How to disable CSRF in Spring Security 4 only for a specific URL pattern through XML configuration?
Spring -security.xml
<security:http auto-config="true" use-expressions="true" pattern="/ext/**"> <csrf disabled="true" /> </security:http> <security:http auto-config="true" use-expressions="true" authentication-manager-ref="authenticationManager"> <security:intercept-url pattern="/auth/**" access="hasAnyRole('ROLE_USER')" /> <security:form-login login-page="/login" authentication-success-handler-ref="loginSuccessHandler" authentication-failure-url="/login" login-processing-url="/j_spring_security_check" /> <security:logout invalidate-session="true" logout-url="/logout" success-handler-ref="logoutSuccessHandler" /> </security:http>
My code works fine if I use only one security block: http, but after adding another block, it throws an error, as shown below:
Error
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter gov.in.controller.filter.LoginAdtAuthFailHdlr.usernamePasswordAuthenticationFilter; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter] is defined: expected single matching bean but found 2: org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
source share