Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

A new Spring Boot application with spring-boot-starter-security and no configuration asks for a login on every page. What has Boot configured, and what is the difference between form login and HTTP Basic here?

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.

Java
// Roughly what Boot's default chain does (SpringBootWebSecurityConfiguration)
@Bean
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(requests -> requests.anyRequest().authenticated()); // every request
http.formLogin(Customizer.withDefaults()); // login page at /login
http.httpBasic(Customizer.withDefaults()); // Authorization: Basic
return http.build();
}

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.

Text
Using generated security password: 6d1c2c58-4b55-4bf8-9f1e-3a0f5a7f3b21
This generated password is for development use only. Your security configuration must be updated before running your application in production.
# Fixed credentials instead, for local development:
spring.security.user.name=admin
spring.security.user.password=change-me
spring.security.user.roles=ADMIN

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.

Step throughForm login in a browser
BrowserSpring SecurityHttpSession
GET /orders
302 Location: /login
POST /login username, password, _csrf
store context, new session id
302 Location: /orders, Set-Cookie: JSESSIONID
GET /orders with cookie
load context: user
200

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).

Shell
$ curl -i http://localhost:8080/orders
HTTP/1.1 401
WWW-Authenticate: Basic realm="Realm"
$ curl -i -u user:secret http://localhost:8080/orders
GET /orders
Authorization: Basic dXNlcjpzZWNyZXQ= # Base64 of "user:secret", trivially decoded
HTTP/1.1 200
Form login versus HTTP Basic
Form loginHTTP Basic
Designed forPeople in a browserPrograms and scripts
Credentials sentOnce, in a POST to /loginOn every request, in a header
Remembered bySession cookie (JSESSIONID)Nothing; resent each time
Unauthenticated response302 redirect to /login401 with WWW-Authenticate: Basic
LogoutPOST /logout ends the sessionNo real logout; client stops sending
Both need TLS; Basic exposes the password on every request.

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.

Java
@Bean
SecurityFilterChain app(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(a -> a
.requestMatchers("/", "/public/**").permitAll()
.anyRequest().authenticated())
.formLogin(Customizer.withDefaults()); // HTTP Basic is now off: we did not ask for it
return http.build();
}
// GET /public/info -> 200 without login
// curl -u user:secret /orders -> 302 to /login: Basic is no longer enabled

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.

What to say in the interviewAbout 90 seconds aloud

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/