1 | initial version |
To obtain the login and password for basic authorization in Spring Boot, you can follow the below steps:
Define a username and password in the application.properties file. For example:
spring.security.user.name=username spring.security.user.password=password
Add the @EnableWebSecurity annotation to your configuration file and create a class that extends WebSecurityConfigurerAdapter. For example:
@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
}
}
The configure(HttpSecurity http) method configures the HttpSecurity object to require basic authentication for all requests.
Now, when you access a secured resource you will be prompted for a username and password.
Use the defined username and password to access your resource.