Java - Spring - Security (@EnableWebSecurity)

Java - Spring - Security (@EnableWebSecurity)

@Configuration
@EnableWebSecurity
public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(WebSecurity web) throws Exception {} 

    @Override
    protected void configure(HttpSecurity http) throws Exception {}
    
    @Override
    protected void configure(AuthenticationManagerBuilder amb) {}
}

What is the Use of @EnableWebSecurity

To switch off the default web application security configuration completely you can add a bean with @EnableWebSecurity (this does not disable the authentication manager configuration or Actuator’s security). To customize it you normally use external properties and beans of type WebSecurityConfigurerAdapter (e.g. to add form-based login).

If you add @EnableWebSecurity and also disable Actuator security, you will get the default form-based login for the entire application unless you add a custom WebSecurityConfigurerAdapter.

If you define a @Configuration with @EnableWebSecurity anywhere in your application, it will switch off the default webapp security settings in Spring Boot (but leave the Actuator’s security enabled). To tweak the defaults try setting properties in security.* (see SecurityProperties for details of available settings) and SECURITY section of Common application properties.