Class WebSecurityConfigurerAdapter
- All Implemented Interfaces:
SecurityConfigurer<javax.servlet.Filter,,WebSecurity> WebSecurityConfigurer<WebSecurity>
WebSecurityConfigurer instance.
The implementation allows customization by overriding methods.
Will automatically apply the result of looking up AbstractHttpConfigurer from
SpringFactoriesLoader to allow developers to extend the defaults. To do this,
you must create a class that extends AbstractHttpConfigurer and then create a file in
the classpath at "META-INF/spring.factories" that looks something like:
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer = sample.MyClassThatExtendsAbstractHttpConfigurerIf you have multiple classes that should be added you can use "," to separate the values. For example:
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer = sample.MyClassThatExtendsAbstractHttpConfigurer, sample.OtherThatExtendsAbstractHttpConfigurer
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDeprecated.Creates an instance with the default configuration enabled.protectedWebSecurityConfigurerAdapter(boolean disableDefaults) Deprecated.Creates an instance which allows specifying if the default configuration should be enabled. -
Method Summary
Modifier and TypeMethodDescriptionprotected AuthenticationManagerDeprecated.Gets theAuthenticationManagerto use.Deprecated.Override this method to expose theAuthenticationManagerfromconfigure(AuthenticationManagerBuilder)to be exposed as a Bean.protected voidDeprecated.Used by the default implementation ofauthenticationManager()to attempt to obtain anAuthenticationManager.protected voidconfigure(HttpSecurity http) Deprecated.Override this method to configure theHttpSecurity.voidconfigure(WebSecurity web) Deprecated.Override this method to configureWebSecurity.protected final org.springframework.context.ApplicationContextDeprecated.Gets the ApplicationContextprotected final HttpSecuritygetHttp()Deprecated.Creates theHttpSecurityor returns the current instancevoidinit(WebSecurity web) Deprecated.Initialize theSecurityBuilder.voidsetApplicationContext(org.springframework.context.ApplicationContext context) Deprecated.voidsetAuthenticationConfiguration(AuthenticationConfiguration authenticationConfiguration) Deprecated.voidsetContentNegotationStrategy(org.springframework.web.accept.ContentNegotiationStrategy contentNegotiationStrategy) Deprecated.voidsetObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) Deprecated.voidsetTrustResolver(AuthenticationTrustResolver trustResolver) Deprecated.protected UserDetailsServiceDeprecated.Allows modifying and accessing theUserDetailsServicefromuserDetailsServiceBean()without interacting with theApplicationContext.Deprecated.Override this method to expose aUserDetailsServicecreated fromconfigure(AuthenticationManagerBuilder)as a bean.
-
Constructor Details
-
WebSecurityConfigurerAdapter
protected WebSecurityConfigurerAdapter()Deprecated.Creates an instance with the default configuration enabled. -
WebSecurityConfigurerAdapter
protected WebSecurityConfigurerAdapter(boolean disableDefaults) Deprecated.Creates an instance which allows specifying if the default configuration should be enabled. Disabling the default configuration should be considered more advanced usage as it requires more understanding of how the framework is implemented.- Parameters:
disableDefaults- true if the default configuration should be disabled, else false
-
-
Method Details
-
configure
Deprecated.Used by the default implementation ofauthenticationManager()to attempt to obtain anAuthenticationManager. If overridden, theAuthenticationManagerBuildershould be used to specify theAuthenticationManager.The
authenticationManagerBean()method can be used to expose the resultingAuthenticationManageras a Bean. TheuserDetailsServiceBean()can be used to expose the last populatedUserDetailsServicethat is created with theAuthenticationManagerBuilderas a Bean. TheUserDetailsServicewill also automatically be populated onAbstractConfiguredSecurityBuilder.getSharedObject(Class)for use with otherSecurityContextConfigurer(i.e. RememberMeConfigurer )For example, the following configuration could be used to register in memory authentication that exposes an in memory
UserDetailsService:@Override protected void configure(AuthenticationManagerBuilder auth) { auth // enable in memory based authentication with a user named // "user" and "admin" .inMemoryAuthentication().withUser("user").password("password").roles("USER").and() .withUser("admin").password("password").roles("USER", "ADMIN"); } // Expose the UserDetailsService as a Bean @Bean @Override public UserDetailsService userDetailsServiceBean() throws Exception { return super.userDetailsServiceBean(); }- Parameters:
auth- theAuthenticationManagerBuilderto use- Throws:
Exception
-
getHttp
Deprecated.Creates theHttpSecurityor returns the current instance- Returns:
- the
HttpSecurity - Throws:
Exception
-
authenticationManagerBean
Deprecated.Override this method to expose theAuthenticationManagerfromconfigure(AuthenticationManagerBuilder)to be exposed as a Bean. For example:@Bean(name name="myAuthenticationManager") @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); }- Returns:
- the
AuthenticationManager - Throws:
Exception
-
authenticationManager
Deprecated.Gets theAuthenticationManagerto use. The default strategy is ifconfigure(AuthenticationManagerBuilder)method is overridden to use theAuthenticationManagerBuilderthat was passed in. Otherwise, autowire theAuthenticationManagerby type.- Returns:
- the
AuthenticationManagerto use - Throws:
Exception
-
userDetailsServiceBean
Deprecated.Override this method to expose aUserDetailsServicecreated fromconfigure(AuthenticationManagerBuilder)as a bean. In general only the following override should be done of this method:@Bean(name = "myUserDetailsService") // any or no name specified is allowed @Override public UserDetailsService userDetailsServiceBean() throws Exception { return super.userDetailsServiceBean(); }To change the instance returned, developers should changeuserDetailsService()instead- Returns:
- the
UserDetailsService - Throws:
Exception- See Also:
-
userDetailsService
Deprecated.Allows modifying and accessing theUserDetailsServicefromuserDetailsServiceBean()without interacting with theApplicationContext. Developers should override this method when changing the instance ofuserDetailsServiceBean().- Returns:
- the
UserDetailsServiceto use
-
init
Deprecated.Description copied from interface:SecurityConfigurerInitialize theSecurityBuilder. Here only shared state should be created and modified, but not properties on theSecurityBuilderused for building the object. This ensures that theSecurityConfigurer.configure(SecurityBuilder)method uses the correct shared objects when building. Configurers should be applied here.- Specified by:
initin interfaceSecurityConfigurer<javax.servlet.Filter,WebSecurity> - Throws:
Exception
-
configure
Deprecated.Override this method to configureWebSecurity. For example, if you wish to ignore certain requests. Endpoints specified in this method will be ignored by Spring Security, meaning it will not protect them from CSRF, XSS, Clickjacking, and so on. Instead, if you want to protect endpoints against common vulnerabilities, then seeconfigure(HttpSecurity)and theHttpSecurity.authorizeRequests()configuration method.- Specified by:
configurein interfaceSecurityConfigurer<javax.servlet.Filter,WebSecurity> - Throws:
Exception
-
configure
Deprecated.Override this method to configure theHttpSecurity. Typically subclasses should not invoke this method by calling super as it may override their configuration. The default configuration is:http.authorizeRequests().anyRequest().authenticated().and().formLogin().and().httpBasic();
Any endpoint that requires defense against common vulnerabilities can be specified here, including public ones. SeeHttpSecurity.authorizeRequests()and the `permitAll()` authorization rule for more details on public endpoints.- Parameters:
http- theHttpSecurityto modify- Throws:
Exception- if an error occurs
-
getApplicationContext
protected final org.springframework.context.ApplicationContext getApplicationContext()Deprecated.Gets the ApplicationContext- Returns:
- the context
-
setApplicationContext
@Autowired public void setApplicationContext(org.springframework.context.ApplicationContext context) Deprecated. -
setTrustResolver
Deprecated. -
setContentNegotationStrategy
@Autowired(required=false) public void setContentNegotationStrategy(org.springframework.web.accept.ContentNegotiationStrategy contentNegotiationStrategy) Deprecated. -
setObjectPostProcessor
Deprecated. -
setAuthenticationConfiguration
@Autowired public void setAuthenticationConfiguration(AuthenticationConfiguration authenticationConfiguration) Deprecated.
-
SecurityFilterChainBean to configureHttpSecurityor aWebSecurityCustomizerBean to configureWebSecurity.@Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http .authorizeHttpRequests((authz) -> authz.anyRequest().authenticated() ); // ... return http.build(); } @Bean public WebSecurityCustomizer webSecurityCustomizer() { return (web) -> web.ignoring().antMatchers("/resources/**"); }See the Spring Security without WebSecurityConfigurerAdapter for more details.