Spring Security provides form-based authentication to verify user identity before allowing access to protected resources. Users are redirected to a login page where they provide credentials, and only authenticated users can access secured endpoints.
Consider an Employee Portal application.
User Requests /dashboard
↓
Spring Security Intercepts Request
↓
Redirect to Login Page
↓
User Enters Credentials
↓
Authentication Successful
↓
Access Granted
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(
HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> auth
.requestMatchers(
"/login",
"/about").permitAll()
.requestMatchers(
"/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
)
.formLogin(form -> form
.loginPage("/login")
.defaultSuccessUrl("/dashboard")
.permitAll()
)
.logout(logout -> logout
.logoutSuccessUrl("/login?logout")
);
return http.build();
}
}@Bean
public UserDetailsService userDetailsService() {
UserDetails user = User.builder()
.username("admin")
.password(
passwordEncoder().encode("admin123"))
.roles("ADMIN")
.build();
return new InMemoryUserDetailsManager(user);
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}A concise interview answer is: To configure basic form-based authentication in Spring Boot, I would add the Spring Security dependency, configure a SecurityFilterChain to protect endpoints, enable formLogin() for login handling, and configure users either in-memory or through a database using UserDetailsService. Passwords should always be stored using BCryptPasswordEncoder for security.
Last updated: 1 November 2026
Next question: How do you make a Spring Boot auto-configuration back away when a bean already exists?