Video in progress
What happens if you add Spring Security to a project and configure nothing?
Every endpoint is locked and asks for a login. Boot creates a single user named "user" and prints its password to the log, randomly generated on each startup.
📖 Answer
As soon as spring-boot-starter-security is added, Boot turns on a default configuration:
- every URL is open only to logged-in users;
- a login form for browsers (
/login) and/logout; - HTTP Basic for API clients;
- CSRF protection is on, so POST requests suddenly start returning
403; - the user is
user, and the password is in the log:
Using generated security password: 4f1c9e2a-...
This generated password is for development use only.
Many new developers trip over this: "when I send a POST from Postman I get 401 or 403". The reason is that security is now active.
Then you write your own SecurityFilterChain bean: which URLs are open and which are locked, and you plug in a real UserDetailsService or token verification.
Locally you can set the password yourself with spring.security.user.name and spring.security.user.password. You don't do that in prod.
Sign up to mark studied questions and save your progress.