I added one custom Security Config in my application on Spring Boot, but the message about \"Using default security password\" is still there in LOG file.
Is there a
Although it works, the current solution is a little overkill as noted in some comments. So here is an alternative that works for me, using the latest Spring Boot (1.4.3).
The default security password is configured inside Spring Boot's AuthenticationManagerConfiguration class. This class has a conditional annotation to prevent from loading if a AuthenticationManager Bean is already defined.
The folllowing code works to prevent execution of the code inside AuthenticationManagerConfiguration because we define our current AuthenticationManager as a bean.
@Configuration
@EnableWebSecurity
public class MyCustomSecurityConfig extends WebSecurityConfigurerAdapter{
[...]
@Override
protected void configure(AuthenticationManagerBuilder authManager) throws Exception {
// This is the code you usually have to configure your authentication manager.
// This configuration will be used by authenticationManagerBean() below.
}
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
// ALTHOUGH THIS SEEMS LIKE USELESS CODE,
// IT'S REQUIRED TO PREVENT SPRING BOOT AUTO-CONFIGURATION
return super.authenticationManagerBean();
}
}
In a Spring Boot 2 application you can either exclude the service configuration from autoconfiguration:
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration
or if you just want to hide the message in the logs you can simply change the log level:
logging.level.org.springframework.boot.autoconfigure.security=WARN
Further information can be found here: https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/boot-features-security.html
If you are using Spring Boot version >= 2.0 try setting this bean in your configuration:
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
http.authorizeExchange().anyExchange().permitAll();
return http.build();
}
Reference: https://stackoverflow.com/a/47292134/1195507
I found out a solution about excluding SecurityAutoConfiguration class.
Example:
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class })
public class ReportApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(MyApplication.class, args);
}
}
If you are declaring your configs in a separate package, make sure you add component scan like this :
@SpringBootApplication
@ComponentScan("com.mycompany.MY_OTHER_PACKAGE.account.config")
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
You may also need to add @component annotation in the config class like so :
@Component
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.....
Using Spring Boot 2.0.4 I came across the same issue.
Excluding SecurityAutoConfiguration.class
did destroy my application.
Now I'm using @SpringBootApplication(exclude= {UserDetailsServiceAutoConfiguration.class})
Works fine with @EnableResourceServer
and JWT :)