Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disabled spring-security by application.properties?

I'd trying to activate basic authentication with password hash encryption.

@Configuration //gets picked up automatically by spring-boot
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(details).passwordEncoder(new BCryptPasswordEncoder());
    }
}

I want the authentication only being active in production. So I'm trying to deactivate it in general at first, use:

security.basic.enabled=false

Result: the application is still secured. I'm presented with the username/password screen.

But how could I then disable the need for authentication?

like image 429
membersound Avatar asked Oct 30 '25 01:10

membersound


1 Answers

Solved with ConditionalOnProperty:

@Configuration
@ConditionalOnProperty("security.basic.enabled")
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

}
like image 119
membersound Avatar answered Nov 01 '25 16:11

membersound



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!