Quick revision
The short answer
With spring-boot-starter-security and no configuration, Boot applies a default SecurityFilterChain that requires authentication for every request and enables both form login and HTTP Basic, and it creates one in-memory user named user with a random password printed at startup, unless we set spring.security.user.* or provide our own UserDetailsService. Form login shows a login page and, after success, remembers the user in a session cookie; HTTP Basic sends the username and password in the Authorization header on every request, so it must only be used over TLS. Defining our own SecurityFilterChain bean replaces the default chain.
What to remember
In this answer, we saw that Spring Boot's default chain requires authentication for every request and enables both form login and HTTP Basic, with an in-memory user named user and a random password logged at startup unless we configure spring.security.user.* or our own user source. Form login suits browsers, sending the password once and then using a session cookie, while HTTP Basic sends Base64-encoded credentials on every request and must only be used over TLS. Declaring our own SecurityFilterChain bean replaces the default chain entirely.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
With spring-boot-starter-security and no configuration, Boot applies a default SecurityFilterChain that requires authentication for every request and enables both form login and HTTP Basic, and it creates one in-memory user named user with a random password printed at startup, unless we set spring.security.user.* or provide our own UserDetailsService. Form login shows a login page and, after success, remembers the user in a session cookie; HTTP Basic sends the username and password in the Authorization header on every request, so it must only be used over TLS. Defining our own SecurityFilterChain bean replaces the default chain.
Why this question is asked
Adding one dependency and suddenly seeing a login page on every URL surprises almost everyone the first time. It is Spring Boot's secure-by-default behaviour, and understanding it explains a lot of later questions: where the password comes from, why curl gets a 401 while the browser gets a page, and why our own configuration makes the defaults disappear. Interviewers ask this because it tests whether we know what auto-configuration does for us. In this answer, we will see what Boot configures, where the user and password come from, how form login and HTTP Basic work and differ, and how to replace the defaults.
1What Boot Configures for Us
When Spring Security is on the classpath, Spring Boot's security auto-configuration adds a default SecurityFilterChain, the ordered list of security filters that every request passes through. It is equivalent to this configuration.
Notice the three parts. Every request needs authentication. Form login is enabled, which also gives us a generated login page at /login and a logout endpoint at /logout. And HTTP Basic is enabled, so non-browser clients can authenticate without a page. The usual protections, such as CSRF protection, security headers and session fixation protection, come with the chain as well.
2Where the User and Password Come From
Authentication needs users, so Boot also creates a UserDetailsService, the component that loads a user by name, backed by memory. It holds one user named user with a random UUID password, which Boot prints in the log when the application starts.
The password changes on every restart, which is a deliberate nudge: it is for trying things out, not for real use. Boot stops creating this user as soon as we define our own UserDetailsService, AuthenticationProvider or AuthenticationManager bean, or configure an OAuth2 login or resource server, because then it assumes we have our own source of users.
3How Form Login Works
Form login is designed for browsers. When an unauthenticated browser asks for a protected page, the form login entry point redirects it to /login. The user fills in the form, the browser posts the username, the password and a CSRF token to /login, and UsernamePasswordAuthenticationFilter checks them. On success, Spring Security changes the session id (to prevent session fixation), stores the security context in the HTTP session, and redirects the browser back to the page it originally wanted.
From then on, the browser sends only the session cookie, JSESSIONID, with each request. The password travels once.
8 messages in order. Play them, or step through them one at a time.
After login, only the session cookie travels.
4How HTTP Basic Works
HTTP Basic is designed for programs. The client sends the username and password with every request, in the Authorization header, as Base64 of username:password. Base64 is an encoding, not encryption: anyone who sees the header can decode it instantly. That is why HTTP Basic must only be used over TLS (HTTPS).
| Form login | HTTP Basic | |
|---|---|---|
| Designed for | People in a browser | Programs and scripts |
| Credentials sent | Once, in a POST to /login | On every request, in a header |
| Remembered by | Session cookie (JSESSIONID) | Nothing; resent each time |
| Unauthenticated response | 302 redirect to /login | 401 with WWW-Authenticate: Basic |
| Logout | POST /logout ends the session | No real logout; client stops sending |
Notice the first call. Without credentials, curl gets a 401 with a WWW-Authenticate: Basic challenge, not a redirect, because Spring Security looks at the request headers to decide which entry point to use: a browser asking for HTML gets the login page, other clients get the Basic challenge. BasicAuthenticationFilter checks the header on each request; there is no login step and, for a pure API, no need for a session.
5Replacing the Defaults
The default chain is only created when the application defines no SecurityFilterChain bean of its own. As soon as we declare one, Boot's default chain disappears completely, so we must state everything we want, not just the parts we wish to change.
Notice the second result. Developers often add a chain to open a few public paths and are then surprised that their scripts stop working, because HTTP Basic was part of the default and is not part of their chain. The in-memory user, by contrast, is separate auto-configuration and stays until we define our own user source.
6Follow-up questions
Is it safe to keep the generated user in production?
No. The password is printed in the log, so anyone with log access has it, and there is one shared account with no roles or audit trail. Boot's own log message says the password is for development only. Production applications should have a real user source or an identity provider.
Why does form login need a CSRF token but HTTP Basic calls do not seem to?
CSRF protection is on for both. Browsers send cookies automatically, so a hostile site could make a logged-in browser submit a form, and the CSRF token blocks that. For POST requests from a Basic client, CSRF also applies by default, which is why stateless APIs that use only header credentials usually disable CSRF in their own chain.
How do we log out of HTTP Basic?
There is no server-side session to end, and browsers cache Basic credentials until they are closed. That is one reason Basic is a poor choice for people in browsers and a reasonable one for scripts.
7Conclusion
In this answer, we saw that Spring Boot's default chain requires authentication for every request and enables both form login and HTTP Basic, with an in-memory user named user and a random password logged at startup unless we configure spring.security.user.* or our own user source. Form login suits browsers, sending the password once and then using a session cookie, while HTTP Basic sends Base64-encoded credentials on every request and must only be used over TLS. Declaring our own SecurityFilterChain bean replaces the default chain entirely.
Open with
With just the starter on the classpath, Boot's security auto-configuration adds a default SecurityFilterChain: any request must be authenticated, and both form login and HTTP Basic are enabled, along with CSRF protection and the security headers.
Then, if they want more
For users, it creates an in-memory UserDetailsService with one user called user and a random UUID password that's printed in the startup log, marked as for development only. I can fix it with spring.security.user.name and password, and Boot stops creating it once I define my own UserDetailsService, AuthenticationProvider or AuthenticationManager, or configure OAuth2.
The difference between the two login methods is how credentials travel. Form login is for browsers: an unauthenticated browser is redirected to the generated /login page, posts the username, password and CSRF token once, Spring Security stores the context in the session and changes the session id, and from then on only the JSESSIONID cookie is sent.
HTTP Basic is for programs: the username and password go in the Authorization header on every request as Base64, which is just an encoding, so it must only be used over TLS. Spring Security chooses the response based on the request: a browser asking for HTML gets a redirect, curl gets a 401 with a Basic challenge.
And if I declare my own SecurityFilterChain bean, Boot's default chain goes away completely, so if I only enable form login, Basic is gone too.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Security reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A new Spring Boot application with spring-boot-starter-security and no configuration...": https://scrivio-interview-library.netlify.app/spring-boot/authentication/70476e920a/