Spring安全配置错误

时间:2014-12-24 03:28:45

标签: spring spring-security

我一直在寻找解决问题的解决方案所需的一切。但由于某种原因,我的tomcat没有拿起安全配置我得到springSecurityFilterChain没有定义。所以春天大师请帮帮我。非常感谢

我一直收到以下错误

   org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:979)
        at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:324)


<?xml version="1.0" encoding="UTF-8"?>

<web-app>
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.xml</param-value>
    </context-param>

    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>tenone.com</param-value>
    </context-param>

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>


    <context-param>
        <param-name>springSecurityFilterChain</param-name>
        <param-value>
            classpath*:security.xml
        </param-value>
    </context-param>


    <filter>
        <filter-name>encoding-filter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>encoding-filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <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.web.context.request.RequestContextListener</listener-class>
    </listener>
    <listener>
        <listener-class>
             org.springframework.security.web.session.HttpSessionEventPublisher
        </listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>


    <servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-ws-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>/service/*</url-pattern>
    </servlet-mapping>

    <!-- this requires any path listed to be accessed over https, i dont use it for local dev, will uncomment at some point -->
    <!--

  <security-constraint>
        <web-resource-collection>
            <web-resource-name>secured-resources</web-resource-name>
            <url-pattern>/install/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

-->
</web-app>

        <!----------------------------------------------------------------------------------------------- >
          my dispatcher servlet config file as below -->

<?xml version="1.0" encoding="UTF-8"?>

<context:component-scan base-package="com.tenone"/>
<mvc:annotation-driven/>

<!-- DB connection and TX management -->
<import resource="classpath*:db-config.xml"/>
<!-- Services configuration -->
<import resource="classpath*:core-spring-config.xml"/>
<import resource="classpath:platform-managers.xml"/>
<import resource="classpath:web-config.xml"/>
<import resource="classpath:security.xml"/>
<import resource="classpath:services-config.xml"/>
<import resource="classpath:web-config.xml"/>
<import resource="classpath*:validators.xml"/>


<!-- Any other configurations load them here -->

<bean id="jacksonHttpMessageConverter"
      class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <property name="messageConverters">
        <util:list id="beanList">
            <ref bean="jacksonHttpMessageConverter"/>
        </util:list>
    </property>
</bean>

</beans>

        <!----------------------------------------------------------------------
        my spring security xml file is as below. -->



<context:annotation-config/>

<import resource="classpath*:services-config.xml"/>
<import resource="classpath*:web-config.xml"/>

<s:global-method-security secured-annotations="enabled"/>


<!-- This controls urls without any security -->
<s:http pattern="/service/connect/**" security="none"/>
<s:http pattern="/service/register/**" security="none"/>


<!-- This controls the default spring security info -->
<s:http auto-config="true">
    <!-- protection against cross site request forgery -->
    <s:csrf/>
    <!-- The login page should take this into account -->
    <s:form-login/>
    <s:http-basic/>
    <s:intercept-url pattern="/j_spring_security_check" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
    <s:intercept-url pattern="/service/**"/>
    <s:logout logout-url="/logout" logout-success-url="/" invalidate-session="true" delete-cookies="JSESSIONID"/>

</s:http>

<s:authentication-manager alias="authenticationManager">
    <s:authentication-provider>
        <s:password-encoder ref="passwordEncoder"/>
        <s:jdbc-user-service data-source-ref="dataSource"
                             users-by-username-query=""/>
    </s:authentication-provider>
</s:authentication-manager>


<bean id="passwordEncoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder"/>

<bean id="reCaptcha" class="net.tanesha.recaptcha.ReCaptchaImpl">
    <property name="privateKey" value="${recaptcha.privateKey}"/>
    <property name="publicKey" value="${recaptcha.publicKey}"/>
    <property name="includeNoscript" value="false"/>
    <property name="httpLoader">
        <bean class="com.tenone.api.util.SystemHttpLoader"/>
    </property>
</bean>


</beans>

1 个答案:

答案 0 :(得分:1)

我认为你不需要这些:

<context-param>
    <param-name>springSecurityFilterChain</param-name>
    <param-value>
        classpath*:security.xml
    </param-value>
</context-param>

安全性xml应该由ContextLoaderListener而不是调度程序加载。

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>

应该解决你的问题