How to disable spring-security login screen?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
To disable the default Spring Security login screen, call .formLogin(AbstractHttpConfigurer::disable) in your SecurityFilterChain bean. This tells Spring Security to stop auto-generating the /login page. The exact configuration depends on your Spring Boot version: Spring Boot 3.x uses the component-based SecurityFilterChain approach, while older 2.x projects may still extend the now-deprecated WebSecurityConfigurerAdapter.
Why the Login Screen Appears
When you add spring-boot-starter-security to your classpath, Spring Boot auto-configures a security filter chain that includes form-based login. This default chain:
- Protects every endpoint with authentication
- Generates a login page at
/login - Creates a single user with a random password printed to the console at startup
- Enables session-based authentication
This is convenient for prototyping, but most production applications need a different authentication strategy: JWT tokens, OAuth2, API keys, or a custom login UI served by a frontend framework.
Spring Boot 3.x / Spring Security 6.x (Recommended)
The WebSecurityConfigurerAdapter class was removed in Spring Security 6. The modern approach uses a @Bean method that returns a SecurityFilterChain:
This disables the generated login page while keeping all other security features active. Requests to /login will now return a 403 instead of rendering a form.
Spring Boot 2.x / Spring Security 5.x (Legacy)
If you are on an older Spring Boot 2.x project, you may still be using the adapter pattern:
Note that WebSecurityConfigurerAdapter is deprecated since Spring Security 5.7 and removed in 6.0. If you are starting a new project, use the SecurityFilterChain bean approach.
Common Replacement Authentication Strategies
Disabling the login screen is only half the job. You need to replace it with the authentication mechanism your application actually uses.
HTTP Basic Authentication
Suitable for internal services, CLI tools, or APIs behind a gateway:
Stateless JWT Authentication
For REST APIs where clients send a Bearer token with each request:
Stateless APIs disable both form login and session creation. CSRF protection is also typically disabled for stateless APIs because the browser-cookie attack vector does not apply when tokens are sent in headers.
OAuth2 Resource Server
For services that validate tokens issued by an external identity provider:
Permit All (Disable Security Entirely)
For local development or when security is handled entirely by an API gateway:
This is the nuclear option. Never deploy this to production.
Session Management Policies
Once you disable form login, review your session management strategy. The default IF_REQUIRED policy creates sessions when needed, which may not match your new authentication model.
| Policy | Behavior | Use Case |
STATELESS | No session created or used | JWT APIs, microservices |
IF_REQUIRED | Session created only when needed | Traditional web apps with custom login UI |
ALWAYS | Session always created | Legacy apps that depend on session state |
NEVER | Spring Security never creates a session but uses one if it exists | Servlet-managed sessions |
Configure it in your filter chain:
Disabling Security Auto-Configuration Entirely
If you want to remove Spring Security's auto-configuration completely (not just the login page), you can exclude it at the application level:
Or in application.properties:
This removes all security behavior, not just the login page. Use this approach only when you genuinely do not want any security filtering.
Comparison of Approaches
| Goal | Method | Side Effects |
| Remove login page only | .formLogin(AbstractHttpConfigurer::disable) | Endpoints still require authentication; need alternate auth mechanism |
| Replace with HTTP Basic | .httpBasic(Customizer.withDefaults()) | Browser shows native credential dialog |
| Replace with JWT | Custom filter + STATELESS session | Must implement token validation; CSRF disabled |
| Replace with OAuth2 | .oauth2ResourceServer() | Requires external identity provider configuration |
| Remove all security | @SpringBootApplication(exclude = ...) | No authentication, no authorization, no CSRF |
Common Pitfalls
Calling .formLogin().disable() without providing an alternative authentication mechanism locks you out of every endpoint. Requests fail with 401 or 403, and there is no way to authenticate. Always pair the disable with a replacement strategy.
Using the deprecated WebSecurityConfigurerAdapter in a Spring Boot 3.x project will not compile. The class was removed in Spring Security 6.0. Use the SecurityFilterChain bean pattern instead.
Disabling CSRF globally when your application still uses session-based authentication opens a real security vulnerability. Only disable CSRF for truly stateless APIs where authentication comes from headers, not cookies.
Excluding SecurityAutoConfiguration in production is almost always a mistake. It removes all security, not just the login page. Prefer the targeted .formLogin(AbstractHttpConfigurer::disable) approach.
Forgetting that Spring Boot Actuator has its own security auto-configuration (ManagementWebSecurityAutoConfiguration) means actuator endpoints may still show a login prompt even after you configure your main filter chain.
Summary
- Disable the default login page with
.formLogin(AbstractHttpConfigurer::disable)in aSecurityFilterChainbean (Spring Boot 3.x) or.formLogin().disable()in aWebSecurityConfigurerAdapteroverride (Spring Boot 2.x). - Always replace form login with the authentication mechanism your application actually needs: HTTP Basic, JWT, or OAuth2.
- Set the session policy to
STATELESSfor token-based APIs. - Avoid excluding
SecurityAutoConfigurationentirely unless you genuinely want zero security. - Remember that
WebSecurityConfigurerAdapterwas removed in Spring Security 6.0. Use the bean-based configuration for any new project.
Related reading
- How to disable 'X-Frame-Options' response header in Spring Security?
- How to efficiently hash the ip-address
- How to elevate privileges only when required?
- How to enable Bearer authentication on Spring Boot application?
- How to disable spring boot logo in stdout?
- How to display auto-configuration report when running a Spring Boot application
- How to enable Client Certificate Authentication with Traefik Kubernetes?
- How to enable Client Certificate in Google Kubernetes Engine Cluster

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.