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 anAuthentication
that represents an anonymous user instead of having a null value) for anHttpSecurity
. Specifically this will configure anAnonymousAuthenticationFilter
and anAnonymousAuthenticationProvider
. All properties have reasonable defaults, so no additional configuration is required other than applying thisSecurityConfigurer
.- Since:
- 3.2
-
-
Constructor Summary
Constructors Constructor Description AnonymousConfigurer()
Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AnonymousConfigurer<H>
authenticationFilter(AnonymousAuthenticationFilter authenticationFilter)
Sets theAnonymousAuthenticationFilter
used to populate an anonymous user.AnonymousConfigurer<H>
authenticationProvider(AuthenticationProvider authenticationProvider)
Sets theAuthenticationProvider
used to validate an anonymous user.AnonymousConfigurer<H>
authorities(java.lang.String... authorities)
Sets theAuthentication.getAuthorities()
for anonymous usersAnonymousConfigurer<H>
authorities(java.util.List<GrantedAuthority> authorities)
Sets theAuthentication.getAuthorities()
for anonymous usersvoid
configure(H http)
Configure theSecurityBuilder
by setting the necessary properties on theSecurityBuilder
.void
init(H http)
Initialize theSecurityBuilder
.AnonymousConfigurer<H>
key(java.lang.String key)
Sets the key to identify tokens created for anonymous authentication.AnonymousConfigurer<H>
principal(java.lang.Object principal)
Sets the principal forAuthentication
objects of anonymous users-
Methods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer
disable, withObjectPostProcessor
-
Methods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, and, getBuilder, postProcess, setBuilder
-
-
-
-
Constructor Detail
-
AnonymousConfigurer
public AnonymousConfigurer()
Creates a new instance- See Also:
HttpSecurity.anonymous()
-
-
Method Detail
-
key
public AnonymousConfigurer<H> key(java.lang.String 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
public AnonymousConfigurer<H> principal(java.lang.Object 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
public AnonymousConfigurer<H> authorities(java.util.List<GrantedAuthority> 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
public AnonymousConfigurer<H> authorities(java.lang.String... 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
public AnonymousConfigurer<H> authenticationProvider(AuthenticationProvider 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
public void init(H http)
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
public void configure(H http)
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>>
-
-