Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined

I am running NTLM using Spring Security, I am getting the following error

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined

How can I resolve this error?

I have the following defined in 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> 

Update 1

I resolved that error, now I am getting

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'filterSecurityInterceptor' is defined

and I have the following

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

I changed my applicationContext.xml as follows because like @Sean Patrick Floyd mentioned some elements were old and dead and buried. However I have other errors now which needs to be fixed :-)

Thanks

<?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> 
like image 859
Jacob Avatar asked Feb 23 '11 12:02

Jacob


People also ask

How do I fix Nosuchbeandefinitionexception?

This Issue occurs when the main class and repository class are in different packages and the repository class and interfaces are not automatically scanned. The solution is to annotate the main class with EnableJpaRepositories and explicitly mention the repository package that needs to be scanned.

What is the use of DelegatingFilterProxy in spring?

DelegatingFilterProxy is a class in Spring's Web module. It provides features for making HTTP calls pass through filters before reaching the actual destination. With the help of DelegatingFilterProxy, a class implementing the javax. Servlet.

What is SecurityWebFilterChain?

Interface SecurityWebFilterChainDefines a filter chain which is capable of being matched against a ServerWebExchange in order to decide whether it applies to that request.


2 Answers

From the DelegatingFilterProxy docs:

Notice that the filter is actually a DelegatingFilterProxy, and not the class that will actually implement the logic of the filter. What DelegatingFilterProxy does is delegate the Filter's methods through to a bean which is obtained from the Spring application context. This enables the bean to benefit from the Spring web application context lifecycle support and configuration flexibility. The bean must implement javax.servlet.Filter and it must have the same name as that in the filter-name element. Read the Javadoc for DelegatingFilterProxy for more information

You need to define a bean named springSecurityFilterChain that implements javax.servlet.Filter in your application context.

From Getting Started with Security Namespace Configuration:

If you are familiar with pre-namespace versions of the framework, you can probably already guess roughly what's going on here. The <http> element is responsible for creating a FilterChainProxy and the filter beans which it uses. Common problems like incorrect filter ordering are no longer an issue as the filter positions are predefined.

So you need at least A Minimal <http> Configuration

like image 86
Sean Patrick Floyd Avatar answered Oct 13 '22 20:10

Sean Patrick Floyd


Sean Patrick Floyd is absolutely right but I think it is worth mention one solution, which took to much time for me.

You simply add @ImportResource annotation.

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

like image 27
Christian Nilsson Avatar answered Oct 13 '22 21:10

Christian Nilsson