I created following API endpoint secured by Spring Security 6.
@Controller
public class HelloController {
@GetMapping("/")
public String hello() {
return "index";
}
}
Dependencies are shown below.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
I haven’t defined a SecurityConfig
class or UserDetails
object. I just want to use the default username user
and default password generated by Spring Security. However, when I started the application, there is no default password generated. Is there any configuration needed?
1
Since Spring Boot 3.2.2 you have to configure name and password in your application.yaml
, see Spring Boot 3.2 Release Notes:
Auto-configured User Details Service
The auto-configured
InMemoryUserDetailsManager
now backs off when one or more ofspring-security-oauth2-client
,spring-security-oauth2-resource-server
, andspring-security-saml2-service-provider
is on the classpath and, since 3.2.2, neitherspring.security.user.name
norspring.security.user.password
has been configured. Similarly, in reactive applications, the auto-configuredMapReactiveUserDetailsService
now backs off when one or more ofspring-security-oauth2-client
andspring-security-oauth2-resource-server
is one the classpath and, since 3.2.2, neitherspring.security.user.name
norspring.security.user.password
has been configured.If you are using one of the above dependencies yet still require an
InMemoryUserDetailsManager
orMapReactiveUserDetailsService
in your application, define the required bean in your application, or with Spring Boot 3.2.2 and later, configure one or both ofspring.security.user.name
andspring.security.user.password
.
1