How Spring Security Filter Chain works

后端 未结 3 1875

I realize that Spring security build on chain of filters, which will intercept the request, detect (absence of) authentication, redirect to authentication entry point or pas

3条回答
  •  再見小時候
    2020-11-27 09:27

    UsernamePasswordAuthenticationFilter is only used for /login, and latter filters are not?

    No, UsernamePasswordAuthenticationFilter extends AbstractAuthenticationProcessingFilter, and this contains a RequestMatcher, that means you can define your own processing url, this filter only handle the RequestMatcher matches the request url, the default processing url is /login.

    Later filters can still handle the request, if the UsernamePasswordAuthenticationFilter executes chain.doFilter(request, response);.

    More details about core fitlers

    Does the form-login namespace element auto-configure these filters?

    UsernamePasswordAuthenticationFilter is created by , these are Standard Filter Aliases and Ordering

    Does every request (authenticated or not) reach FilterSecurityInterceptor for non-login url?

    It depends on whether the before fitlers are successful, but FilterSecurityInterceptor is the last fitler normally.

    Does configuring two http elements create two springSecurityFitlerChains?

    Yes, every fitlerChain has a RequestMatcher, if the RequestMatcher matches the request, the request will be handled by the fitlers in the fitler chain.

    The default RequestMatcher matches all request if you don't config the pattern, or you can config the specific url ().

    If you want to konw more about the fitlers, I think you can check source code in spring security. doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)

提交回复
热议问题