Class AnonymousConfigurer<H extends HttpSecurityBuilder<H>>
- java.lang.Object
-
- org.springframework.security.config.annotation.SecurityConfigurerAdapter<org.springframework.security.web.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<org.springframework.security.web.DefaultSecurityFilterChain,H>
public final class AnonymousConfigurer<H extends HttpSecurityBuilder<H>> extends AbstractHttpConfigurer<AnonymousConfigurer<H>,H>
Configures Anonymous authentication (i.e. populate anAuthenticationthat represents an anonymous user instead of having a null value) for anHttpSecurity. Specifically this will configure anAnonymousAuthenticationFilterand 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(org.springframework.security.web.authentication.AnonymousAuthenticationFilter authenticationFilter)Sets theAnonymousAuthenticationFilterused to populate an anonymous user.AnonymousConfigurer<H>authenticationProvider(org.springframework.security.authentication.AuthenticationProvider authenticationProvider)Sets theAuthenticationProviderused to validate an anonymous user.AnonymousConfigurer<H>authorities(java.lang.String... authorities)Sets theAuthentication.getAuthorities()for anonymous usersAnonymousConfigurer<H>authorities(java.util.List<org.springframework.security.core.GrantedAuthority> authorities)Sets theAuthentication.getAuthorities()for anonymous usersvoidconfigure(H http)Configure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.voidinit(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 forAuthenticationobjects of anonymous users-
Methods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer
disable, getSecurityContextHolderStrategy, 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
AnonymousConfigurerfor further customization of anonymous authentication
-
principal
public AnonymousConfigurer<H> principal(java.lang.Object principal)
Sets the principal forAuthenticationobjects of anonymous users- Parameters:
principal- used for theAuthenticationobject of anonymous users- Returns:
- the
AnonymousConfigurerfor further customization of anonymous authentication
-
authorities
public AnonymousConfigurer<H> authorities(java.util.List<org.springframework.security.core.GrantedAuthority> authorities)
Sets theAuthentication.getAuthorities()for anonymous users- Parameters:
authorities- Sets theAuthentication.getAuthorities()for anonymous users- Returns:
- the
AnonymousConfigurerfor 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
AnonymousConfigurerfor further customization of anonymous authentication
-
authenticationProvider
public AnonymousConfigurer<H> authenticationProvider(org.springframework.security.authentication.AuthenticationProvider authenticationProvider)
Sets theAuthenticationProviderused to validate an anonymous user. If this is set, no attributes on theAnonymousConfigurerwill be set on theAuthenticationProvider.- Parameters:
authenticationProvider- theAuthenticationProviderused to validate an anonymous user. Default isAnonymousAuthenticationProvider- Returns:
- the
AnonymousConfigurerfor further customization of anonymous authentication
-
authenticationFilter
public AnonymousConfigurer<H> authenticationFilter(org.springframework.security.web.authentication.AnonymousAuthenticationFilter authenticationFilter)
Sets theAnonymousAuthenticationFilterused to populate an anonymous user. If this is set, no attributes on theAnonymousConfigurerwill be set on theAnonymousAuthenticationFilter.- Parameters:
authenticationFilter- theAnonymousAuthenticationFilterused to populate an anonymous user.- Returns:
- the
AnonymousConfigurerfor further customization of anonymous authentication
-
init
public void init(H http)
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<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>- Overrides:
initin classSecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>
-
configure
public void configure(H http)
Description copied from interface:SecurityConfigurerConfigure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.- Specified by:
configurein interfaceSecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>- Overrides:
configurein classSecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>
-
-