How to disable the Spring Security login screen
Codemia Knowledge Hub ·
Call .formLogin(AbstractHttpConfigurer::disable) in your SecurityFilterChain bean. Spring Security then stops generating the /login page. Spring Boot 3.x uses this component-based SecurityFilterChain approach; older 2.x projects may still extend the now-deprecated WebSecurityConfigurerAdapter.
Where the login screen comes from
Adding spring-boot-starter-security to the classpath makes Spring Boot auto-configure a security filter chain with form-based login. That 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
That is handy for prototyping, but most production applications use something else: JWT tokens, OAuth2, API keys, or a custom login UI served by a frontend framework.
Spring Boot 3.x / Spring Security 6.x
WebSecurityConfigurerAdapter was removed in Spring Security 6. Define a @Bean method that returns a SecurityFilterChain:
This disables the generated login page while keeping all other security features active. Requests to /login now return a 403 instead of rendering a form.
Spring Boot 2.x / Spring Security 5.x
Older projects may still use the adapter pattern:
WebSecurityConfigurerAdapter is deprecated since Spring Security 5.7 and removed in 6.0, so it will not compile in a Spring Boot 3.x project. Use the SecurityFilterChain bean for anything new.
Replace form login with another mechanism
Disabling form login alone does not open your endpoints. They still require authentication, and with no alternative mechanism every request fails with 401 or 403. Always pair the disable with the authentication your application actually uses.
HTTP Basic
Suitable for internal services, CLI tools, or APIs behind a gateway:
Stateless JWT
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 here, because the browser-cookie attack vector does not apply when tokens travel in headers. Do not disable CSRF if the application still uses session-based authentication; that opens a real vulnerability.
OAuth2 resource server
For services that validate tokens issued by an external identity provider:
Permit all requests
For local development, or when an API gateway handles security entirely:
This is the nuclear option. Never deploy it to production.
Session management policy
Once form login is gone, review the session policy. The default IF_REQUIRED creates sessions when needed, which may not fit 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 |
Set it in the filter chain:
Turning off security auto-configuration completely
To remove Spring Security's auto-configuration entirely (not just the login page), exclude it at the application level:
Or in application.properties:
This removes all security behavior: no authentication, no authorization, no CSRF. In production it is almost always a mistake; prefer the targeted .formLogin(AbstractHttpConfigurer::disable).
Spring Boot Actuator has its own security auto-configuration (ManagementWebSecurityAutoConfiguration). If you forget it, actuator endpoints may still show a login prompt after you configure your main filter chain.
Comparing the 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 |
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 interview problems on this topic
- Design a Secure Identity Management System: solution and walkthrough
- Design an API Rate Limiter: solution and walkthrough
- Design a Network Security Monitoring Tool: solution and walkthrough
- Design a CAPTCHA System: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.