Results 1 to 4 of 4

Thread: BeanFactory not initialized or already closed - call 'refresh' before accessing beans

  1. #1
    Join Date
    Aug 2012
    Posts
    4

    Default BeanFactory not initialized or already closed - call 'refresh' before accessing beans

    I'm trying to add spring security to a regular JSF application. After repeated tries and I'm failing with the following error on tomcat bring-up.

    Here is the entire stack trace. Any help is appreciated.

    SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
    java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
    at org.springframework.context.support.AbstractRefres hableApplicationContext.getBeanFactory(AbstractRef reshableApplicationContext.java:171)
    at org.springframework.context.support.AbstractApplic ationContext.destroyBeans(AbstractApplicationConte xt.java:1048)
    at org.springframework.context.support.AbstractApplic ationContext.doClose(AbstractApplicationContext.ja va:1022)
    at org.springframework.context.support.AbstractApplic ationContext.close(AbstractApplicationContext.java :970)
    at org.springframework.web.context.ContextLoader.clos eWebApplicationContext(ContextLoader.java:556)
    at org.springframework.web.context.ContextLoaderListe ner.contextDestroyed(ContextLoaderListener.java:14 2)
    at org.apache.catalina.core.StandardContext.listenerS top(StandardContext.java:4245)
    at org.apache.catalina.core.StandardContext.stop(Stan dardContext.java:4886)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4750)
    at org.apache.catalina.manager.ManagerServlet.start(M anagerServlet.java:1276)
    at org.apache.catalina.manager.HTMLManagerServlet.sta rt(HTMLManagerServlet.java:625)
    at org.apache.catalina.manager.HTMLManagerServlet.doG et(HTMLManagerServlet.java:136)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.filters.CsrfPreventionFilter.d oFilter(CsrfPreventionFilter.java:186)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:563)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)


    my web.xml is

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    	
    	<context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/applicationContext.xml
                /WEB-INF/applicationContext-security.xml
            </param-value>
        </context-param>
        <context-param>
            <param-name>javax.faces.PROJECT_STAGE</param-name>
            <param-value>Development</param-value>
        </context-param>
    	<context-param>
    		<param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
    		<param-value>false</param-value>
    	</context-param>
    	<context-param>
    		<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
    		<param-value>true</param-value>
    	</context-param>
    	
    	<context-param>
            <param-name>com.icesoft.faces.debugDOMUpdate</param-name>
            <param-value>false</param-value>
        </context-param>
    	
    	<context-param>
            <param-name>com.icesoft.faces.concurrentDOMViews</param-name>
            <param-value>true</param-value>
        </context-param>
        
        <context-param>
            <param-name>com.icesoft.faces.synchronousUpdate</param-name>
            <param-value>true</param-value>
        </context-param>
    	  
    	<!-- Faces Servlet -->  
    	<servlet>
    		<servlet-name>Faces Servlet</servlet-name>
    		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    		<!-- <load-on-startup>1</load-on-startup> -->
    	</servlet>
    	
    	<servlet>
    	    <servlet-name>Resource Servlet</servlet-name>
    	    <servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
    	    <load-on-startup>1</load-on-startup>
    	</servlet>
    	<!-- Extension Mapping -->
    	<servlet-mapping>
    		<servlet-name>Faces Servlet</servlet-name>
    		<url-pattern>/faces/*</url-pattern>
    		<url-pattern>*.jsf</url-pattern>
    	</servlet-mapping>
    	<servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/icefaces/*</url-pattern>
        </servlet-mapping>
        <session-config>
    		<session-timeout>90</session-timeout>
    	</session-config>
    	
    	
    	<servlet-mapping>
    	  <servlet-name>Resource Servlet</servlet-name>
    	  <url-pattern>/xmlhttp/*</url-pattern>
    	  <url-pattern>/resources/*</url-pattern>
    	</servlet-mapping>
    	
    	 <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>
        </filter-mapping>
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <listener>
            <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
        </listener>
    	
    	
    	<welcome-file-list>
    		<!-- <welcome-file>faces/greeting.xhtml</welcome-file> -->
    		<welcome-file>index.html</welcome-file>
    		<!-- <welcome-file>faces/test.xhtml</welcome-file> -->
    	</welcome-file-list>
    </web-app>

    And my applicationContext-security.xml is

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/security"
                 xmlns:beans="http://www.springframework.org/schema/beans"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/security
               http://www.springframework.org/schema/security/spring-security-3.0.xsd">
    
        <!--  key configuration here is an entry point to be used by security intercepts -->
        <http realm="Sample Realm" entry-point-ref="authenticationEntryPoint" auto-config="false">
    
            <custom-filter ref="sessionManagementFilter" before="SESSION_MANAGEMENT_FILTER" />
            <!-- any role that is used to protect a directory, can be multiples -->
            <intercept-url pattern='/secure/**' access='ROLE_READER' />
    
            <!-- enable form login to use UsernamePasswordAuthenticationFilter [/j_spring_security_check] -->
            <form-login login-page="/general/logins/htmlLogin.faces"  
                        authentication-failure-url="/general/logins/loginFailed.jsf"/>
    
            <!-- logout page uses the default LogoutFilter, no changes are needed as IT accepts a GET call... -->
            <!-- here is an example logout link:
                    <a href="#{request.contextPath}/j_spring_security_logout">Logout</a> -->
            <logout logout-url="/j_spring_security_logout"
                    logout-success-url="/general/main.jsf"
                    invalidate-session="true"/>
        </http>
    
        <beans:bean id="authenticationEntryPoint"
            class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
            <beans:property name="loginFormUrl" value="/general/logins/login.jsf" />
        </beans:bean>
    
        <!-- test with this before you hook up your LDAP or other Authentication Manager -->
        <authentication-manager alias="authenticationManager">
            <authentication-provider>
                <user-service>
                    <user name="joe.blow@gr.am" password="pass1234" authorities="ROLE_READER"/>
                    <user name="tester@gr.com" password="pass5678" authorities="ROLE_READER"/>
                </user-service>
            </authentication-provider>
        </authentication-manager>
    
        <beans:bean id="sessionManagementFilter" class="org.springframework.security.web.session.SessionManagementFilter">
            <beans:constructor-arg name="securityContextRepository" ref="httpSessionSecurityContextRepository" />
            <beans:property name="invalidSessionUrl" value="/general/logins/sessionExpired.jsf" />
            <!-- this permits redirection to session timeout page from javascript/ajax or http -->
            <beans:property name="redirectStrategy" ref="jsfRedirectStrategy" />
        </beans:bean>
    
        <beans:bean id="jsfRedirectStrategy" class="com.palm.safe.spring.security.JsfRedirectStrategy"/>
        <beans:bean id="httpSessionSecurityContextRepository" class="org.springframework.security.web.context.HttpSessionSecurityContextRepository"/>
    
    </beans:beans>

  2. #2
    Join Date
    Jan 2008
    Posts
    1,826

    Default

    This usually means there was another error. Look in the logs for any other errors which will clue you in to why the application is not starting up.
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

  3. #3
    Join Date
    Aug 2012
    Posts
    4

    Default

    Quote Originally Posted by Rob Winch View Post
    This usually means there was another error. Look in the logs for any other errors which will clue you in to why the application is not starting up.
    Thanks, it turns out I only get the error use 3.1.1.RELEASE version of the spring framework jars, and works just fine with 3.0.5.RELEASE and I'm pretty sure it got something with jar conflict probably from other jersey-spring dependency I have in my pom(inspite of excluding spring, spring-core, spring-web, spring-beans, spring-context etc). I can live with 3.0.5.RELEASE for now, I'll first sort out my LDAP issues first before upgrading SPRING jars.

    Anyway, seeing as what you signature is what it is, it brings me to another question I thought i might as well ask. I'm a newbie with using LDAP and spring security and now that I've incorporated basic login authentication using the settings in appContext-security.xml, I'm still struggling the with exact configuration details add the basic LDAP authentication. I have my LDAP server, port, domainName etc that I plan to use. However I'm confused with all the configuration, the BindAuthentication, whether or not to use ActiveDirectory

    With all that, I was wondering if you giving me some pointed changes to make to my appContext-security to add the right kind of tags to support a simple LDAP authentication.

  4. #4
    Join Date
    Jan 2008
    Posts
    1,826

    Default

    Your best bet is to look at the LDAP sample application http://static.springsource.org/sprin...mple-apps.html
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •