Custom authenticationFilter Spring Security 3.2

For the project, I am trying to use Spring Security 3.2 as the base security. Since this project is already running, I already have a different (own) level of security. Consequently, I made an authenticationprovider customer to melt security levels. Works well until I need to do basic anonymous authentication ( Spring Security Documentation, Chapter 13 ).

So, I created my own filter and removed the orignal filter:

<http request-matcher="regex" use-expressions="true"> <anonymous enabled="false" /> <custom-filter ref="anonymousAuthFilter" position="ANONYMOUS_FILTER"/> ... </http> 

bean:

 <beans:bean id="anonymousAuthFilter" class="own.package.auth.SecurityAnonymousAuthenticationFilter"> <beans:property name="key" value="anonymousKey "/> <beans:property name="userAttribute" value="anonymous,ROLE_ANONYMOUS"/> </beans:bean> 

and te Java Class:

 public class SecurityAnonymousAuthenticationFilter extends GenericFilterBean implements InitializingBean { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { logger.info("Entering doFilter method"); //implementation code here } //other methods } 

The problem is that the doFilter method is not called when the server requests. However, the init method afterPropertiesSet () is called ... Does anyone understand why my customFilter does not start?

PS I called delegating FilterProxy in the web.xml file, so no problem.

+6
source share
1 answer

Since ANONYMOUS_FILTER is a filter associated with the namespace. You should avoid any namespace tag that references specific filtering:

  <http auto-config='false' request-matcher="regex" use-expressions="true"> <custom-filter ref="anonymousAuthFilter" position="ANONYMOUS_FILTER"/> ... </http> 

For more information, see Spring's security documentation in section 2.3.5: http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ns-config.html

Edit: And be sure to leave the <anonymous-enabled=false/> .

Edit 2: Fixed my answer. This configuration should work. If not, then we need to start looking at the larger picture, and you will have to publish more of your application, starting with the full configuration.

+1
source

Source: https://habr.com/ru/post/945936/


All Articles