Class AnonymousConfigurer<H extends HttpSecurityBuilder<H>>
java.lang.Object
org.springframework.security.config.annotation.SecurityConfigurerAdapter<DefaultSecurityFilterChain,B>
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer<AnonymousConfigurer<H>,H>
org.springframework.security.config.annotation.web.configurers.AnonymousConfigurer<H>
- All Implemented Interfaces:
SecurityConfigurer<DefaultSecurityFilterChain,
H>
public final class AnonymousConfigurer<H extends HttpSecurityBuilder<H>>
extends AbstractHttpConfigurer<AnonymousConfigurer<H>,H>
Configures Anonymous authentication (i.e. populate an
Authentication
that
represents an anonymous user instead of having a null value) for an
HttpSecurity
. Specifically this will configure an
AnonymousAuthenticationFilter
and an AnonymousAuthenticationProvider
.
All properties have reasonable defaults, so no additional configuration is required
other than applying this SecurityConfigurer
.- Since:
- 3.2
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionauthenticationFilter
(AnonymousAuthenticationFilter authenticationFilter) Sets theAnonymousAuthenticationFilter
used to populate an anonymous user.authenticationProvider
(AuthenticationProvider authenticationProvider) Sets theAuthenticationProvider
used to validate an anonymous user.authorities
(String... authorities) Sets theAuthentication.getAuthorities()
for anonymous usersauthorities
(List<GrantedAuthority> authorities) Sets theAuthentication.getAuthorities()
for anonymous usersvoid
Configure theSecurityBuilder
by setting the necessary properties on theSecurityBuilder
.void
Initialize theSecurityBuilder
.Sets the key to identify tokens created for anonymous authentication.Sets the principal forAuthentication
objects of anonymous usersMethods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer
disable, getSecurityContextHolderStrategy, withObjectPostProcessor, withObjectPostProcessor
Methods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, addObjectPostProcessor, and, getBuilder, postProcess, setBuilder
-
Constructor Details
-
AnonymousConfigurer
public AnonymousConfigurer()Creates a new instance- See Also:
-
-
Method Details
-
key
Sets the key to identify tokens created for anonymous authentication. Default is a secure randomly generated key.- Parameters:
key
- the key to identify tokens created for anonymous authentication. Default is a secure randomly generated key.- Returns:
- the
AnonymousConfigurer
for further customization of anonymous authentication
-
principal
Sets the principal forAuthentication
objects of anonymous users- Parameters:
principal
- used for theAuthentication
object of anonymous users- Returns:
- the
AnonymousConfigurer
for further customization of anonymous authentication
-
authorities
Sets theAuthentication.getAuthorities()
for anonymous users- Parameters:
authorities
- Sets theAuthentication.getAuthorities()
for anonymous users- Returns:
- the
AnonymousConfigurer
for further customization of anonymous authentication
-
authorities
Sets theAuthentication.getAuthorities()
for anonymous users- Parameters:
authorities
- Sets theAuthentication.getAuthorities()
for anonymous users (i.e. "ROLE_ANONYMOUS")- Returns:
- the
AnonymousConfigurer
for further customization of anonymous authentication
-
authenticationProvider
Sets theAuthenticationProvider
used to validate an anonymous user. If this is set, no attributes on theAnonymousConfigurer
will be set on theAuthenticationProvider
.- Parameters:
authenticationProvider
- theAuthenticationProvider
used to validate an anonymous user. Default isAnonymousAuthenticationProvider
- Returns:
- the
AnonymousConfigurer
for further customization of anonymous authentication
-
authenticationFilter
public AnonymousConfigurer<H> authenticationFilter(AnonymousAuthenticationFilter authenticationFilter) Sets theAnonymousAuthenticationFilter
used to populate an anonymous user. If this is set, no attributes on theAnonymousConfigurer
will be set on theAnonymousAuthenticationFilter
.- Parameters:
authenticationFilter
- theAnonymousAuthenticationFilter
used to populate an anonymous user.- Returns:
- the
AnonymousConfigurer
for further customization of anonymous authentication
-
init
Description copied from interface:SecurityConfigurer
Initialize theSecurityBuilder
. Here only shared state should be created and modified, but not properties on theSecurityBuilder
used 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:
init
in interfaceSecurityConfigurer<DefaultSecurityFilterChain,
H extends HttpSecurityBuilder<H>> - Overrides:
init
in classSecurityConfigurerAdapter<DefaultSecurityFilterChain,
H extends HttpSecurityBuilder<H>>
-
configure
Description copied from interface:SecurityConfigurer
Configure theSecurityBuilder
by setting the necessary properties on theSecurityBuilder
.- Specified by:
configure
in interfaceSecurityConfigurer<DefaultSecurityFilterChain,
H extends HttpSecurityBuilder<H>> - Overrides:
configure
in classSecurityConfigurerAdapter<DefaultSecurityFilterChain,
H extends HttpSecurityBuilder<H>>
-