Spring Security 7 introduces native multi-factor authentication (MFA) support using a factor-based authority model. Each successful authentication step grants a FactorGrantedAuthority to the user's security context. The new @EnableMultiFactorAuthentication annotation enables MFA globally, while AuthorizationManagerFactory allows applying MFA rules to specific endpoints. The post covers global MFA setup, endpoint-specific rules, time-based re-authentication requirements, user-based conditional MFA, and unit testing MFA flows with Spring Security test utilities.
Table of contents
1. Overview2. Understanding MFA in Spring Security 73. Project Setup4. Enabling Multi-Factor Authentication Globally5. Applying MFA to Specific Endpoints6. Implementing Time-Based Authentication Rules7. Implementing User-Based MFA Rules8. Writing Unit Tests for MFA9. Conclusion1 Comment
Sort: