0 Replies Latest reply: Feb 2, 2014 6:10 AM by 84a27ad4-5d2c-4527-a3f2-fe659644336e RSS

ManagedBean is not accessible, using JSF2.2, Spring 4.0 and SpringSecurity 3.2

84a27ad4-5d2c-4527-a3f2-fe659644336e Newbie
Currently Being Moderated

Dear All,

 

 

I am developing a Dynamic Web Application, using JSF 2.2, Spring Framework 4.0 and Spring Security 3.2. I, first, integrated JSF and Spring framework (JSF Page => ManagedBean => Service => DAO). It was working fine. But when I introduced Spring Security, I am unable to access ManagedBean in JSF page and getting no error at all. ManagedBean is not even invoked (even constructor is not called). I have been surfing for this issue for 2 days now, but couldn’t find any resolution.

 

 

My config files are as following:

 

 

faces-config.xml

 

 

    [code=java]<?xml version="1.0" encoding="UTF-8"?>

    <faces-config

        xmlns="http://xmlns.jcp.org/xml/ns/javaee"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"

    version="2.2">

 

 

        <application>

     <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>

        </application>

 

 

    </faces-config>[/code]

 

 

 

 

Web.xml

 

 

   [code=java] <?xml version="1.0" encoding="UTF-8"?>

  <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xmlns="http://java.sun.com/xml/ns/javaee"

  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

  id="WebApp_ID" version="3.0">

 

 

  <display-name>my-app-ui</display-name>

 

 

  <welcome-file-list>

  <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

 

 

  <!-- Spring Framework -->

  <listener>

  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

  </listener>

  <listener>

  <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

  </listener>

 

  <!-- Spring context config locations -->

  <context-param>

  <param-name>contextConfigLocation</param-name>

  <param-value>classpath*:/applicationContext.xml</param-value>

  <param-value>classpath*:/securityConfig.xml</param-value>

  </context-param>

 

  <!-- PROJECT STAGE START FOR DEVELOPEMENT MARK IT AS DEVELOPMENT. FOR TESTING / PRODUCTION REMOVE THIS -->

  <context-param>

  <param-name>javax.faces.PROJECT_STAGE</param-name>

  <param-value>Development</param-value>

  </context-param>

 

  <!-- Spring Security -->

  <filter>

  <filter-name>springSecurityFilterChain</filter-name>

  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

  </filter>

  <filter-mapping>

  <filter-name>springSecurityFilterChain</filter-name>

  <url-pattern>/*</url-pattern>

  <dispatcher>FORWARD</dispatcher>

  <dispatcher>REQUEST</dispatcher>

  </filter-mapping>

 

 

 

 

  <!-- JSF -->

  <servlet>

  <servlet-name>Faces Servlet</servlet-name>

  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

  <load-on-startup>1</load-on-startup>

  </servlet>

  <servlet-mapping>

  <servlet-name>Faces Servlet</servlet-name>

  <url-pattern>*.html</url-pattern>

  </servlet-mapping>

  </web-app>

[/code]

 

 

applicationconContext.xml

 

 

  [code=java]<beans xmlns="http://www.springframework.org/schema/beans

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"

   xmlns:tx="http://www.springframework.org/schema/tx"  

   xsi:schemaLocation="http://www.springframework.org/schema/beans  

  http://www.springframework.org/schema/beans/spring-beans.xsd 

  http://www.springframework.org/schema/context  

  http://www.springframework.org/schema/context/spring-context.xsd"> 

  

  <context:annotation-config />

  <context:component-scan base-package="com.myapp.managedbean"/>

  <context:component-scan base-package="com.myapp.service"/>

  <context:component-scan base-package="com.myapp.domain"/>

  <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

  <property name="jndiName" value="java:comp/env/jdbc/myDS" />

  </bean>

 

 

  <bean id="txManager"

  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

  <property name="dataSource" ref="dataSource" />

  </bean>

  </beans> 

[/code]

 

 

securityConfig.xml

 

 

  [code=java]<b:beans xmlns="http://www.springframework.org/schema/security

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xmlns:b="http://www.springframework.org/schema/beans"

   xsi:schemaLocation="http://www.springframework.org/schema/beans  

  http://www.springframework.org/schema/beans/spring-beans.xsd 

  http://www.springframework.org/schema/security

  http://www.springframework.org/schema/security/spring-security.xsd "> 

  

  <debug />

   

 

  <http pattern="/resources/**" security="none" />

  <http pattern="/login*" security="none" />

 

 

  <http auto-config="true" use-expressions="true" disable-url-rewriting="true" >

  <intercept-url pattern="/**" access="authenticated" />

  <form-login authentication-failure-url="/loginfailed.html"

  default-target-url="/" always-use-default-target="true"/>

 

  <access-denied-handler error-page="/denied.html"/>

 

 

  <session-management invalid-session-url="/session-expire.html" session-fixation-protection="none" />

 

  <logout delete-cookies="JSESSIONID" invalidate-session="true" />

 

 

  <http-basic />

  </http>

 

  <authentication-manager>

   <authentication-provider>

  <user-service>

   <user name="user_admin" password="password" authorities="ROLE_USER,ROLE_ADMIN" />

   <user name="user" password="password" authorities="ROLE_USER" />

  </user-service>

   </authentication-provider>

  </authentication-manager>

  </b:beans>

[/code]

 

 

first-jsf-page.xhtml

 

  [code=java]<!DOCTYPE html >

  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets">

  <head>

 

 

  </head>

  <body>

 

 

  Managed bean data: #{myMB.fetchDataFromService()}

 

 

 

 

  </body>

  </html>[/code]

 

 

 

ManagedBean

 

 

   [code=java] @Component("myMB")

    @Scope("session")

    public class MyMB implements Serializable {

        public MyMB () {

  System.out.println("Constructor called");

  }

 

  @Autowired 

  @Qualifier("myService") 

  public MyService myService;

 

 

  Public String fetchDataFromService() {

  System.out.println("Invoking Service"); 

  return myService.getMessage(); 

  }

    }

[/code]

 

MyService

 

  [code=java]public interface MyService {

  public String getMessage(); 

  }[/code]

 

MyServiceImpl

 

  [code=java]@Service("myService") 

  public class MyServiceImpl implements MyService { 

 

  @Override 

  public String getMessage() { 

   return "JSF and Spring Integrtion - Done"; 

  } 

  }  [/code]

 

 

 

If I remove "DelegatingFilterProxy" from Web.xml, everything works fine. Kindly help me out here.

 

 

I am using Eclipse and tomcat server.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points