public class OttLinkAuthenticationProviderextends Object
implements org.springframework.security.authentication.AuthenticationProvider
Confirms a magic link: consumes the token Spring's JdbcOneTimeTokenService stored and signs the user in with
it. It does what Spring's own provider does, except that it also reads the purpose the link was requested for
(LinkTokenUsername), which Spring's provider cannot because it would look the marked user name up as it is:
a link requested for a sign-in answers with the user's authentication plus FACTOR_OTT;
a link requested as a second factor is refused unless the session that confirms it is the signed-in session of
the same user, with a primary factor, and OttSecondFactorChannels allows the e-mail channel for that session
(it did not sign the user in, and the user has no other confirmed second factor); it then answers with the
second-factor authority of the e-mail channel, and Spring Security's authentication filter merges it with the
factors the session holds.
Links are delivered by e-mail only. The account is loaded through the user service of the chain, which refuses a
disabled, locked or expired account.
authenticate in interface org.springframework.security.authentication.AuthenticationProvider
Parameters:
authentication - the OneTimeTokenAuthenticationToken to confirm.
Returns:
the authentication of the user, with the factor of the purpose of the link.
Throws:
org.springframework.security.core.AuthenticationException - if the token is not valid, the account cannot sign in or a second-factor link
is confirmed outside the session of the user it was requested for.
Requires the current session to be the signed-in session of a user who still has to present a second factor.
Parameters:
username - the user the link was requested for.
Throws:
org.springframework.security.authentication.BadCredentialsException - if the session is another user's, holds no primary factor, or may not use the
e-mail channel the link was delivered by as its second factor.