Class OneTimeTokenLoginConfigurer<H extends HttpSecurityBuilder<H>>
java.lang.Object
org.springframework.security.config.annotation.SecurityConfigurerAdapter<DefaultSecurityFilterChain,B>
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer<T,B>
org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer<H,OneTimeTokenLoginConfigurer<H>,OneTimeTokenAuthenticationFilter>
org.springframework.security.config.annotation.web.configurers.ott.OneTimeTokenLoginConfigurer<H>
- All Implemented Interfaces:
SecurityConfigurer<DefaultSecurityFilterChain,
H>
public final class OneTimeTokenLoginConfigurer<H extends HttpSecurityBuilder<H>>
extends AbstractAuthenticationFilterConfigurer<H,OneTimeTokenLoginConfigurer<H>,OneTimeTokenAuthenticationFilter>
An
AbstractHttpConfigurer
for One-Time Token Login.
One-Time Token Login provides an application with the capability to have users log in by obtaining a single-use token out of band, for example through email.
Defaults are provided for all configuration options, with the only required
configuration being
tokenGenerationSuccessHandler(OneTimeTokenGenerationSuccessHandler)
.
Alternatively, a OneTimeTokenGenerationSuccessHandler
@Bean
may be
registered instead.
Security Filters
The followingFilter
s are populated:
DefaultOneTimeTokenSubmitPageGeneratingFilter
GenerateOneTimeTokenFilter
OneTimeTokenAuthenticationFilter
Shared Objects Used
The following shared objects are used:DefaultLoginPageGeneratingFilter
- ifloginPage(String)
is not configured andDefaultLoginPageGeneratingFilter
is available, then a default login page will be made available
-
Constructor Summary
ConstructorsConstructorDescriptionOneTimeTokenLoginConfigurer
(org.springframework.context.ApplicationContext context) -
Method Summary
Modifier and TypeMethodDescriptionauthenticationConverter
(AuthenticationConverter authenticationConverter) Use thisAuthenticationConverter
when converting incoming requests to anAuthentication
.authenticationFailureHandler
(AuthenticationFailureHandler authenticationFailureHandler) Deprecated.authenticationProvider
(AuthenticationProvider authenticationProvider) Specifies theAuthenticationProvider
to use when authenticating the user.authenticationSuccessHandler
(AuthenticationSuccessHandler authenticationSuccessHandler) Deprecated.void
Configure theSecurityBuilder
by setting the necessary properties on theSecurityBuilder
.protected RequestMatcher
createLoginProcessingUrlMatcher
(String loginProcessingUrl) Create theRequestMatcher
given a loginProcessingUrldefaultSubmitPageUrl
(String submitPageUrl) Sets the URL that the default submit page will be generated.generateRequestResolver
(GenerateOneTimeTokenRequestResolver requestResolver) Use thisGenerateOneTimeTokenRequestResolver
when resolvingGenerateOneTimeTokenRequest
fromHttpServletRequest
.org.springframework.context.ApplicationContext
Deprecated.Use this.context insteadvoid
Initialize theSecurityBuilder
.Specifies the URL to send users to if login is required.loginProcessingUrl
(String loginProcessingUrl) Specifies the URL to process the login request, defaults to/login/ott
.showDefaultSubmitPage
(boolean show) Configures whether the default one-time token submit page should be shown.tokenGeneratingUrl
(String tokenGeneratingUrl) Specifies the URL that a One-Time Token generate request will be processed.tokenGenerationSuccessHandler
(OneTimeTokenGenerationSuccessHandler oneTimeTokenGenerationSuccessHandler) Specifies strategy to be used to handle generated one-time tokens.tokenService
(OneTimeTokenService oneTimeTokenService) Configures theOneTimeTokenService
used to generate and consumeOneTimeToken
Methods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer
authenticationDetailsSource, defaultSuccessUrl, defaultSuccessUrl, failureHandler, failureUrl, getAuthenticationEntryPoint, getAuthenticationEntryPointMatcher, getAuthenticationFilter, getFailureUrl, getLoginPage, getLoginProcessingUrl, isCustomLoginPage, permitAll, permitAll, registerAuthenticationEntryPoint, registerDefaultAuthenticationEntryPoint, securityContextRepository, setAuthenticationFilter, successHandler, updateAccessDefaults, updateAuthenticationDefaults
Methods 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
-
OneTimeTokenLoginConfigurer
public OneTimeTokenLoginConfigurer(org.springframework.context.ApplicationContext context)
-
-
Method Details
-
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 classAbstractAuthenticationFilterConfigurer<H extends HttpSecurityBuilder<H>,
OneTimeTokenLoginConfigurer<H extends HttpSecurityBuilder<H>>, OneTimeTokenAuthenticationFilter> - Throws:
Exception
-
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 classAbstractAuthenticationFilterConfigurer<H extends HttpSecurityBuilder<H>,
OneTimeTokenLoginConfigurer<H extends HttpSecurityBuilder<H>>, OneTimeTokenAuthenticationFilter> - Throws:
Exception
-
createLoginProcessingUrlMatcher
Description copied from class:AbstractAuthenticationFilterConfigurer
Create theRequestMatcher
given a loginProcessingUrl- Specified by:
createLoginProcessingUrlMatcher
in classAbstractAuthenticationFilterConfigurer<H extends HttpSecurityBuilder<H>,
OneTimeTokenLoginConfigurer<H extends HttpSecurityBuilder<H>>, OneTimeTokenAuthenticationFilter> - Parameters:
loginProcessingUrl
- creates theRequestMatcher
based upon the loginProcessingUrl- Returns:
- the
RequestMatcher
to use based upon the loginProcessingUrl
-
authenticationProvider
public OneTimeTokenLoginConfigurer<H> authenticationProvider(AuthenticationProvider authenticationProvider) Specifies theAuthenticationProvider
to use when authenticating the user.- Parameters:
authenticationProvider
-
-
tokenGeneratingUrl
Specifies the URL that a One-Time Token generate request will be processed. Defaults to/ott/generate
.- Parameters:
tokenGeneratingUrl
-
-
tokenGenerationSuccessHandler
public OneTimeTokenLoginConfigurer<H> tokenGenerationSuccessHandler(OneTimeTokenGenerationSuccessHandler oneTimeTokenGenerationSuccessHandler) Specifies strategy to be used to handle generated one-time tokens.- Parameters:
oneTimeTokenGenerationSuccessHandler
-
-
loginProcessingUrl
Specifies the URL to process the login request, defaults to/login/ott
. Only POST requests are processed, for that reason make sure that you pass a valid CSRF token if CSRF protection is enabled.- Overrides:
loginProcessingUrl
in classAbstractAuthenticationFilterConfigurer<H extends HttpSecurityBuilder<H>,
OneTimeTokenLoginConfigurer<H extends HttpSecurityBuilder<H>>, OneTimeTokenAuthenticationFilter> - Parameters:
loginProcessingUrl
-- Returns:
- the
FormLoginConfigurer
for additional customization - See Also:
-
loginPage
Specifies the URL to send users to if login is required. If used withEnableWebSecurity
a default login page will be generated when this attribute is not specified.- Overrides:
loginPage
in classAbstractAuthenticationFilterConfigurer<H extends HttpSecurityBuilder<H>,
OneTimeTokenLoginConfigurer<H extends HttpSecurityBuilder<H>>, OneTimeTokenAuthenticationFilter> - Parameters:
loginPage
-
-
showDefaultSubmitPage
Configures whether the default one-time token submit page should be shown. This will prevent theDefaultOneTimeTokenSubmitPageGeneratingFilter
to be configured.- Parameters:
show
-
-
defaultSubmitPageUrl
Sets the URL that the default submit page will be generated. Defaults to/login/ott
. If you don't want to generate the default submit page you should useshowDefaultSubmitPage(boolean)
. Note that this method always invokeshowDefaultSubmitPage(boolean)
passingtrue
.- Parameters:
submitPageUrl
-
-
tokenService
Configures theOneTimeTokenService
used to generate and consumeOneTimeToken
- Parameters:
oneTimeTokenService
-
-
authenticationConverter
public OneTimeTokenLoginConfigurer<H> authenticationConverter(AuthenticationConverter authenticationConverter) Use thisAuthenticationConverter
when converting incoming requests to anAuthentication
. By default, theOneTimeTokenAuthenticationConverter
is used.- Parameters:
authenticationConverter
- theAuthenticationConverter
to use
-
authenticationFailureHandler
@Deprecated(since="6.5") public OneTimeTokenLoginConfigurer<H> authenticationFailureHandler(AuthenticationFailureHandler authenticationFailureHandler) Deprecated.Specifies theAuthenticationFailureHandler
to use when authentication fails. The default is redirecting to "/login?error" usingSimpleUrlAuthenticationFailureHandler
- Parameters:
authenticationFailureHandler
- theAuthenticationFailureHandler
to use when authentication fails.
-
authenticationSuccessHandler
@Deprecated(since="6.5") public OneTimeTokenLoginConfigurer<H> authenticationSuccessHandler(AuthenticationSuccessHandler authenticationSuccessHandler) Deprecated.Specifies theAuthenticationSuccessHandler
to be used. The default isSavedRequestAwareAuthenticationSuccessHandler
with no additional properties set.- Parameters:
authenticationSuccessHandler
- theAuthenticationSuccessHandler
.
-
generateRequestResolver
public OneTimeTokenLoginConfigurer<H> generateRequestResolver(GenerateOneTimeTokenRequestResolver requestResolver) Use thisGenerateOneTimeTokenRequestResolver
when resolvingGenerateOneTimeTokenRequest
fromHttpServletRequest
. By default, theDefaultGenerateOneTimeTokenRequestResolver
is used.- Parameters:
requestResolver
- theGenerateOneTimeTokenRequestResolver
- Since:
- 6.5
-
getContext
Deprecated.Use this.context instead
-
AbstractAuthenticationFilterConfigurer.failureHandler(AuthenticationFailureHandler)
instead