Performance: Form-based login configuration
This affects the initial page load speed and interaction responsiveness during user login.
Jump into concepts and practice - no test required
http
.authorizeHttpRequests(auth -> auth.anyRequest().authenticated())
.formLogin(form -> form
.loginPage("/custom-login")
.permitAll()
.defaultSuccessUrl("/home", true))
.csrf(csrf -> csrf.enable());http
.authorizeHttpRequests(auth -> auth.anyRequest().authenticated())
.formLogin(form -> form.loginPage("/custom-login"))
.csrf(csrf -> csrf.disable());| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Simple form with minimal fields | Low (few nodes) | 1 reflow on load | Low paint cost | [OK] Good |
| Complex form with many inputs and scripts | High (many nodes) | Multiple reflows on input | High paint cost | [X] Bad |
formLogin() in Spring Security?formLogin() method in Spring Security enables users to log in using a web form.formLogin().loginPage() used after formLogin().loginPage("/custom-login")./login?
http
.authorizeHttpRequests(auth -> auth.anyRequest().authenticated())
.formLogin(form -> form.loginPage("/login").permitAll());anyRequest().authenticated()./login and permitAll() allows everyone to access it without login.http
.formLogin()
.loginPage("/my-login")
.permitAll();permitAll() is used on authorization rules, not directly on formLogin().permitAll() should be called on the authorization configuration for the login page URL./user-login
- The login page is accessible without authentication
- All other pages require login
Which configuration snippet correctly achieves this?requestMatchers("/user-login").permitAll() to allow unauthenticated access to the login page.anyRequest().authenticated() to protect all other endpoints.formLogin(form -> form.loginPage("/user-login")) sets the custom login page.