0
votes

Trying to implement into your project springowego Spring Security, but I have a problem. When I try to run a project crashes me the error:

lis 05, 2014 2:54:51 PM org.apache.catalina.core.StandardContext filterStart SEVERE: Exception starting filter springSecurityFilterChain org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1097) at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326) at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:236) at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:194) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262) at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:107) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

lis 05, 2014 2:54:51 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Error filterStart lis 05, 2014 2:54:51 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Context [/ibank] startup failed due to previous errors

My web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>

    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</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>

</web-app>

security-config.xml:

    <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.2.xsd">

    <http auto-config="true">
        <access-denied-handler error-page="/403page" />
        <intercept-url pattern="/client**" access="ROLE_CLIENT" />
        <intercept-url pattern="/admin**" access="ROLE_ADMIN" />
        <form-login login-page='/login' username-parameter="username"
            password-parameter="password" default-target-url="/user"
            authentication-failure-url="/login?authfailed" />
        <logout logout-success-url="/login?logout" />
    </http>

    <!-- <authentication-manager> <authentication-provider> <user-service> <user 
        name="user" password="user@123" authorities="ROLE_ADMIN" /> </user-service> 
        </authentication-provider> </authentication-manager> -->

    <authentication-manager>
        <authentication-provider>
            <jdbc-user-service data-source-ref="dataSource"
                users-by-username-query="select username,password, enabled from users where username=?"
                authorities-by-username-query="select username, role from user_roles where username =?  " />
        </authentication-provider>
    </authentication-manager>

</beans:beans>

I find this topic but i don't now how he solved Spring : Exception starting filter springSecurityFilterChain

I try

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
                 /WEB-INF/spring/root-context.xml
                 /WEB-INF/spring/security-config.xml
    </param-value>
</context-param>

but application still not working and i have this errors:

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security] Offending resource: ServletContext resource [/WEB-INF/spring/security-config.xml]

lis 05, 2014 3:28:37 PM org.apache.catalina.core.StandardContext listenerStart SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security] Offending resource: ServletContext resource [/WEB-INF/spring/security-config.xml]

lis 05, 2014 3:28:37 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Error listenerStart lis 05, 2014 3:28:37 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Context [/ibank] startup failed due to previous errors lis 05, 2014 3:28:37 PM org.apache.catalina.core.ApplicationContext log INFO: Closing Spring root WebApplicationContext lis 05, 2014 3:28:37 PM org.apache.catalina.core.StandardContext listenerStop SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception thrown from ApplicationListener handling ContextClosedEvent java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Wed Nov 05 15:28:35 CET 2014]; root of context hierarchy

WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception thrown from LifecycleProcessor on context close java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Wed Nov 05 15:28:35 CET 2014]; root of context hierarchy

2
please post the dependencies in your POM.XML - EpicPandaForce
You are referencing a property - ${spring.security.version} to provide the version number for spring security dependencies, but I can't see in your pom where this is defined (and there doesn't appear to be a parent pom); I would rectify that first and see if things improve. - Tom Bunting
I do not have parent pom. - The Nightmare
I think you are missing http://mvnrepository.com/artifact/org.springframework.security/spring-security-core - EpicPandaForce
@TheNightmare - indeed, so you need to declare the properties you are using in the pom you have provided. - Tom Bunting

2 Answers

1
votes

Your web.xml says

   <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

Unless your root-context.xml includes security-config.xml you'll have to list it there

   <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                     /WEB-INF/spring/root-context.xml
                     /WEB-INF/spring/security-config.xml
        </param-value>
    </context-param>

With your latest update I believe that your issue is two-folded, one, not including the security configuration, second missing pom property try adding

 <spring.security.version>3.1.0.RELEASE</spring.security.version>

within your properties section. Version might be wrong for you, but the issue should be fixed

1
votes

Add your security-config.xml to your application context, i.e. in your web.xml :

 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml /WEB-INF/spring/security-config.xml</param-value>    
 </context-param>

seperate entries with a whitespace character.

Alternatively import it in your root-context.xml, i.e.

<import resource="security-config.xml" />