Class SpringBootWebSecurityConfiguration


  • @Configuration
    @EnableConfigurationProperties
    @ConditionalOnClass({org.springframework.security.config.annotation.web.configuration.EnableWebSecurity.class,org.springframework.security.web.AuthenticationEntryPoint.class})
    @ConditionalOnMissingBean(org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.class)
    @ConditionalOnWebApplication
    @EnableWebSecurity
    public class SpringBootWebSecurityConfiguration
    extends Object
    Configuration for security of a web application or service. By default everything is secured with HTTP Basic authentication except the explicitly ignored paths (defaults to /css/**, /js/**, /images/**, /**/favicon.ico ). Many aspects of the behavior can be controller with SecurityProperties via externalized application properties (or via an bean definition of that type to set the defaults). The user details for authentication are just placeholders (username=user, password=password) but can easily be customized by providing a an AuthenticationManager. Also provides audit logging of authentication events.

    Some common simple customizations:

    • Switch off security completely and permanently: remove Spring Security from the classpath or excludeSecurityAutoConfiguration.
    • Switch off security temporarily (e.g. for a dev environment): set security.basic.enabled=false
    • Customize the user details: autowire an AuthenticationManagerBuilder into a method in one of your configuration classes or equivalently add a bean of type AuthenticationManager
    • Add form login for user facing resources: add a WebSecurityConfigurerAdapter and use HttpSecurity.formLogin()