Is there a way I can disable the global method security using the boolean securityEnabled from my config.properties? Any other approach?
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled=true)
@PropertySource("classpath:config.properties")
public class SecurityConfig
extends WebSecurityConfigurerAdapter {
@Value("${securityconfig.enabled}")
private boolean securityEnabled;
...
}
The easiest way to do this is:
For example:
I've managed this by defining a Spring "securityDisabled" profile and conditionally applying security config based off that. I'm using Spring Boot 2.0.2. I believe this should work if not using Spring Boot and in previous versions of Spring Boot, but I have not tested. It's possible some tweaks may be required to property and class names because I know in Spring 2.0 some of that changed.
Then my security config looks like this: