The Big Picture

Security Lives in Filters

Spring Security does not touch your controllers. It sits in front of them as a chain of servlet filters. A filter sees every request before the DispatcherServlet and can let it through, change it, or stop it with 401/403.

HTTP request
    |
    v
+------------------------- Servlet container (Tomcat) -------------------------+
|  Filter  ->  Filter  ->  DelegatingFilterProxy  ->  Filter  ->  ...          |
|                               |                                              |
|                               v                                              |
|                     FilterChainProxy  (bean "springSecurityFilterChain")    |
|                               |  picks the first matching chain             |
|                               v                                              |
|                     SecurityFilterChain                                      |
|                     [ SecurityContextHolderFilter -> CsrfFilter ->           |
|                       LogoutFilter -> UsernamePasswordAuthenticationFilter ->|
|                       BasicAuthenticationFilter -> AnonymousAuthentication-  |
|                       Filter -> ExceptionTranslationFilter ->               |
|                       AuthorizationFilter ]                                  |
+-------------------------------|----------------------------------------------+
                                v
                       DispatcherServlet -> ProductController

The Main Pieces

ComponentJob
DelegatingFilterProxya normal servlet filter registered with Tomcat that hands the request to a Spring bean
FilterChainProxythe Spring bean that holds all SecurityFilterChains and picks one per request
SecurityFilterChainan ordered list of security filters for matching URLs (you define it as a @Bean)
AuthenticationManagertakes a login attempt and returns an authenticated user or throws
AuthenticationProviderdoes the actual check for one login type (e.g. username + password against the DB)
UserDetailsServiceloads a user by username
PasswordEncoderhashes and verifies passwords
SecurityContextHolderstores the logged-in user for the current request