liveBook · Manning

formLogin

As explained in Spring Security in Action, Second Edition

formLogin is a Spring Security configuration method that enables authentication through an HTML form-based login flow.

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.

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains defaults, redirects, handlers, and combined authentication, but defers larger scalability concerns to later OAuth 2 treatment.
Examples
Uses a home.html page, /home controller, default redirects, custom success and failure handlers, and curl HTTP Basic access.
What it assumes
Assumes basic Spring and Java knowledge while demonstrating SecurityFilterChain configuration and default authentication behavior.
What you can do after
Build it from scratch by configuring formLogin, protecting requests, serving an HTML page, and customizing authentication outcomes.
How it connects
Connects formLogin with HTTP Basic, server-side sessions, Spring MVC, SecurityContext, and OAuth 2.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.