What is the username and password when starting Spring Boot with Tomcat?
In a Spring Boot application with Tomcat, no default username/password is set for server access. For protected routes, Spring Security might require authentication; the username/password is either provided in application.properties or auto-generated on startup. Look for:
Or check the startup logs for an auto-generated password if not set:
Default username is user if not customized.
Confirming Spring Security configuration
To begin with, ensure you have the spring-boot-starter-security in your pom.xml file:
With this dependency, Spring Boot auto-configures a user with the username user and a random password, logged during startup.
Customizing security - Two approaches
Customizing your application security can be done in two ways - through properties files and security configurations.
Using properties files
Bypass auto-generation by setting username and password in your application.properties or application.yml:
Implementing security configurations
For a strong grip, use @EnableWebSecurity and extend the WebSecurityConfigurerAdapter class:
You can also define an in-memory authentication with custom details:
Preventing common pitfalls in security setup
Property encoding issues
Ensure property encoding is correct. Usernames in properties files should not be quoted to avoid login issues:
Encrypted storage of passwords
Use {bcrypt} or {scrypt} password encoder prefixes for secure storage in properties:
Enhancing your mansion's guard
The SecurityAutoConfiguration class auto-secures the mansion, but adding a-custom InMemoryUserDetailsManager opts for a well-trained guard. Enable CSRF protection and use BCryptPasswordEncoder for encoding.
Consider enabling command-line inputs for dynamic guard switch and watch your logs for traces of intrusion.
Was this article helpful?