Spring Security Architecture

 Spring Security is a well made and powerful authentication and authorization framework used for securing Spring-based applications. The underlying value is how quickly and easily it can be configured and extended to meet most business requirements. However, because it’s so configurable it can be daunting to set up and understand how to quickly get it running for your application. This 5 part series will take you through a real-world example from start to finish.

Other Articles

Overview

If you’re new to Spring and you haven’t set up a projet yet then take a look at Getting started with Spring Framework for Web Apps.

Spring Security does a lot of work with a very little configuration. It’s important to have a solid understanding how its architected with regard to web servlet based applications. Spring Security is based on the use of servlet filter chains. It injects itself into the servlet chain to determine if a request needs a user to be authentication, whether the user has authorization, etc.

Servlet filters intercept a request from a client and can inspect or change the request before it gets to the servlet engine. Here’s a high level architecture.

Client => filter0 => filter1 => filter2 => filterN => Servlet

Spring Security injects its own FilterChainProxy into the servlet’s filter chain which then executes a SecurityFilterChain. The security filter chain contains as many Security Filters as needed based on configuration.

Client => filter0 => DelegatingFilterProxy =|                   ---> filter2 => filterN => Servlet
        v-----------------------------------|                   |
        FilterChainProxy => SecurityFilterChain -|              |  
        v----------------------------------------|              |  
        securityFilter0 => securityFilter1 => securityFilterN --^

Spring Security has a specific order it executes its filters in. From a security perspective, the order of filters matters. It typically is not necessary to understand or know the ordering of Spring Security filter instances. However, there are times that it is beneficial to know the ordering.

  • ForceEagerSessionCreationFilter
  • ChannelProcessingFilter
  • WebAsyncManagerIntegrationFilter
  • SecurityContextPersistenceFilter
  • HeaderWriterFilter
  • CorsFilter
  • CsrfFilter
  • LogoutFilter
  • OAuth2AuthorizationRequestRedirectFilter
  • Saml2WebSsoAuthenticationRequestFilter
  • X509AuthenticationFilter
  • AbstractPreAuthenticatedProcessingFilter
  • CasAuthenticationFilter
  • OAuth2LoginAuthenticationFilter
  • Saml2WebSsoAuthenticationFilter
  • UsernamePasswordAuthenticationFilter
  • DefaultLoginPageGeneratingFilter
  • DefaultLogoutPageGeneratingFilter
  • ConcurrentSessionFilter
  • DigestAuthenticationFilter
  • BearerTokenAuthenticationFilter
  • BasicAuthenticationFilter
  • RequestCacheAwareFilter
  • SecurityContextHolderAwareRequestFilter
  • JaasApiIntegrationFilter
  • RememberMeAuthenticationFilter
  • AnonymousAuthenticationFilter
  • OAuth2AuthorizationCodeGrantFilter
  • SessionManagementFilter
  • ExceptionTranslationFilter
  • FilterSecurityInterceptor
  • SwitchUserFilter

In part 1, we’ll be taking advantage of the SecurityFilterChain where we’ll configure and see the filters in action.

That’s an overview of Spring Security filter architecture. For a more comprehensive review refer to the Spring Security documentation.

Comments

Popular posts from this blog

Max Upload File Size in Spring Framework

Use Java Enums with JPA

Spring Security part 3 - OidcUser