【问题标题】:Getting error org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined出现错误 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为“springSecurityFilterChain”的 bean
【发布时间】:2011-07-02 17:32:27
【问题描述】:

我正在使用 Spring Security 运行 NTLM,我收到以下错误

org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为“springSecurityFilterChain”的bean

我该如何解决这个错误?

我在 web.xml 中定义了以下内容

<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>

更新 1

我解决了这个错误,现在我得到了

org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为“filterSecurityInterceptor”的bean

我有以下

<bean id="springSecurityFilterChain" class="org.acegisecurity.util.FilterChainProxy">
    <property name="filterInvocationDefinitionSource">
    <value>
    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
    PATTERN_TYPE_APACHE_ANT
    /**=httpSessionContextIntegrationFilter, exceptionTranslationFilter, ntlmFilter, filterSecurityInterceptor
    </value>
    </property>
    </bean>`

我更改了我的 applicationContext.xml 如下,因为像@Sean Patrick Floyd 提到的一些元素是旧的、死的和被掩埋的。但是我现在还有其他错误需要修复:-)

谢谢

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd   http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.2.xsd">
  <!--<authentication-manager alias="_authenticationManager"></authentication-manager>-->
  <security:authentication-provider>
    <security:user-service>
      <security:user name="testuser" password="PASSWORD" authorities="ROLE_USER, ROLE_ADMIN"/>
      <security:user name="administrator" password="PASSWORD" authorities="ROLE_USER,ROLE_ADMIN"/>
    </security:user-service>
  </security:authentication-provider>
  <bean id="userDetailsAuthenticationProvider"
        class="com.icesoft.icefaces.security.UserDetailsAuthenticationProvider">
    <security:custom-authentication-provider/>
  </bean>
  <bean id="ntlmEntryPoint"
        class="org.springframework.security.ui.ntlm.NtlmProcessingFilterEntryPoint">
    <property name="authenticationFailureUrl" value="/accessDenied.jspx"/>
  </bean>
  <bean id="ntlmFilter" class="org.springframework.security.ui.ntlm.NtlmProcessingFilter">
    <security:custom-filter position="NTLM_FILTER"/>
    <property name="stripDomain" value="true"/>
    <property name="defaultDomain" value="domain"/>
    <property name="netbiosWINS" value="domain"/>
    <property name="authenticationManager" ref="_authenticationManager"/>
  </bean>
  <bean id="exceptionTranslationFilter"
        class="org.springframework.security.ui.ExceptionTranslationFilter">
    <property name="authenticationEntryPoint" ref="ntlmEntryPoint"/>
  </bean>
  <security:http access-decision-manager-ref="accessDecisionManager"
                 entry-point-ref="ntlmEntryPoint">
    <security:intercept-url pattern="/accessDenied.jspx" filters="none"/>
    <security:intercept-url pattern="/**" access="ROLE_USER"/>
  </security:http>
  <bean id="accessDecisionManager" class="org.springframework.security.vote.UnanimousBased">
    <property name="allowIfAllAbstainDecisions" value="false"/>
    <property name="decisionVoters">
      <list>
        <bean id="roleVoter" class="org.springframework.security.vote.RoleVoter"/>
      </list>
    </property>
  </bean>
</beans>

【问题讨论】:

  • 你从哪里得到这个古老的配置元素?合格的类名是org.springframework.security.web.FilterChainProxyorg.acegisecurity 已死多年。

标签: java spring login spring-security


【解决方案1】:

请提供最少配置的spring安全文件

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/securityhttp://www.springframework.org/schema/security/spring-security-3.0.3.xsd">

<http auto-config='true'>
    <intercept-url pattern="/**" access="ROLE_USER" />
</http>

【讨论】:

    【解决方案2】:

    在Java配置中,可以使用如下注解:

    @Configuration
    @EnableWebSecurity
    @EnableGlobalMethodSecurity
    public class MySecurityConfig extends WebSecurityConfigurerAdapter {
    
    }
    

    这将导入定义springSecurityFilterChain bean 的org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration 配置类。

    【讨论】:

      【解决方案3】:

      肖恩·帕特里克·弗洛伊德 (Sean Patrick Floyd) 绝对正确,但我认为值得一提的解决方案是,这对我来说花了很多时间。

      您只需添加@ImportResource 注释。

      @Configuration
      @EnableWebMvc
      @ComponentScan(basePackages = {"org.company"})
      @ImportResource({"classpath:security.xml"})
      public class CompanyWebMvcConfiguration extends WebMvcConfigurerAdapter {
      }
      

      security.xml:

      <?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.2.xsd
          http://www.springframework.org/schema/security
          http://www.springframework.org/schema/security/spring-security-3.1.xsd">
      
      
          <http use-expressions="true">
              <access-denied-handler error-page="/error"/>
          </http>
      

      【讨论】:

        【解决方案4】:

        来自DelegatingFilterProxy 文档:

        请注意,过滤器实际上是 DelegatingFilterProxy,而不是 将实际实现的类 过滤器的逻辑什么 DelegatingFilterProxy 所做的是 delegate 过滤器的方法通过一个bean 这是从春天获得的 应用上下文。这使 bean 从 Spring web 中受益 应用程序上下文生命周期支持 和配置灵活性。 该 bean必须实现 javax.servlet.Filter 并且它必须有 同名 过滤器名称元素。阅读 Javadoc 对于 DelegatingFilterProxy 了解更多 信息

        您需要定义一个名为 springSecurityFilterChain 的 bean,它在您的应用程序上下文中实现 javax.servlet.Filter

        来自Getting Started with Security Namespace Configuration

        如果您熟悉前命名空间 框架的版本,您可以 大概已经猜到大概是什么了 在这里进行。 &lt;http&gt; 元素是 负责创建一个 FilterChainProxy 和过滤器 bean 它使用的。常见问题如 不正确的过滤器排序是没有 不再是过滤器的问题 位置是预定义的。

        所以你至少需要A Minimal &lt;http&gt; Configuration

        【讨论】:

        • 见这里。 static.springsource.org/spring-security/site/docs/3.0.x/…。 springSecurityFilterChain 是一个由 Spring Security 自动提供的内部基础设施 bean。
        • @Ritesh 您误读了文档。仅当您使用 mvc 命名空间中的 &lt;http&gt; 标记时,它才会自动创建
        • @Polappan 您能否更新您的问题以显示您为解决问题以使用 Spring Security 运行 NTLM 所做的工作?
        • 有没有办法在纯 Java 配置中做到这一点?
        猜你喜欢
        • 1970-01-01
        • 2013-01-25
        • 2015-08-30
        • 2014-04-24
        • 2016-12-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多