Class EmailLinkAuthenticationProvider

java.lang.Object
org.jwcarman.who.emaillink.EmailLinkAuthenticationProvider
All Implemented Interfaces:
org.springframework.security.authentication.AuthenticationProvider

public class EmailLinkAuthenticationProvider extends Object implements org.springframework.security.authentication.AuthenticationProvider
Authenticates an email sign-in, by the token from the link or by the address and the code typed by hand, then resolves its email credential to an active identity. Every failure is the same InvalidOneTimeTokenException, whatever the cause.

A code attempt is counted before the code is compared, so a token allows at most EmailLinkSettings.codeMaxAttempts() guesses. When no attempt is available, a dummy hash is still computed, so the work done does not reveal whether the address has a live token.

Each failure publishes SignInFailed with its server-side reason, and logs one DEBUG line; the address appears in no log line above DEBUG. A success is returned as a WhoAuthenticationToken that carries its SignInMethod, and is published by who's success handler once the session is saved, not here.

  • Constructor Details

    • EmailLinkAuthenticationProvider

      public EmailLinkAuthenticationProvider(EmailLinkTokenRepository repository, EmailLinkSettings settings, WhoService whoService, Clock clock)
      Creates a new provider that publishes no events.
      Parameters:
      repository - the token repository
      settings - the email-link settings
      whoService - resolves credentials to principals
      clock - the clock
    • EmailLinkAuthenticationProvider

      public EmailLinkAuthenticationProvider(EmailLinkTokenRepository repository, EmailLinkSettings settings, WhoService whoService, Clock clock, WhoEventPublisher eventPublisher)
      Creates a new provider.
      Parameters:
      repository - the token repository
      settings - the email-link settings
      whoService - resolves credentials to principals
      clock - the clock
      eventPublisher - where SignInFailed is published
  • Method Details

    • authenticate

      public org.springframework.security.core.Authentication authenticate(org.springframework.security.core.Authentication authentication)
      Specified by:
      authenticate in interface org.springframework.security.authentication.AuthenticationProvider
    • supports

      public boolean supports(Class<?> authentication)
      Specified by:
      supports in interface org.springframework.security.authentication.AuthenticationProvider