收到错误org.springframework.beans.factory.NoSuchBeanDefinitionException:未定义名为“ springSecurityFilterChain”的bean
问题内容:
我正在使用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>
问题答案:
请注意,过滤器实际上是DelegatingFilterProxy,而不是实际上将实现过滤器逻辑的类。DelegatingFilterProxy的作用是
将Filter的方法委托给从Spring应用程序上下文获得的bean 。这使Bean可以从Spring
Web应用程序上下文生命周期支持和配置灵活性中受益。 Bean必须实现javax.servlet.Filter,并且必须与filter-
name元素中的名称相同 。阅读Javadoc for DelegatingFilterProxy了解更多信息
您需要定义一个在应用程序上下文springSecurityFilterChain
中实现的名为bean javax.servlet.Filter
。
从“ 安全命名空间配置入门”中:
如果您熟悉框架的命名空间前版本,则可能已经大概猜到这里发生了什么。 该
<http>
元素是负责创建
FilterChainProxy
和它使用的过滤器bean。由于预定义了过滤器位置,不再像过滤器订购不正确这样的常见问题。
因此,您至少需要最小<http>
配置