formLogin enables authentication through an HTML form. In a SecurityFilterChain, it replaces httpBasic() for browser-oriented applications and redirects unauthenticated requests to a login page. section 6.3 section 6.3.2
Figure 6.13 Using form-based login. A user who has not yet been authenticated is sent to a form to log in with their credentials. After the application has verified their identity, they are directed to the application’s main page.
The flow sends an unauthenticated user to a login form, verifies credentials, and then directs the user to the application page. section 6.3.2
A minimal configuration provides several defaults:
- Calling http.formLogin(Customizer.withDefaults()) enables a login form and a logout page. section 6.3.2
- Without a registered UserDetailsService, the default user credentials can authenticate; the generated password appears in the startup console. section 6.3.2
- formLogin can be enabled alongside HTTP Basic when browser and command-line clients need different authentication methods. section 6.4
Small browser application
Configure formLogin, require authentication for every request, map /home to home.html through a controller, and redirect successful logins to /home.
