Class AuthenticationFactorRegistry

java.lang.Object
com.irurueta.authserver.authorization.api.web.mfa.AuthenticationFactorRegistry

public final class AuthenticationFactorRegistry extends Object
Registry of the authentication factors this server knows. Every AuthenticationFactor bean is registered, so a new login method adds its factor by declaring a bean, without editing shared files. The class is final because its constructor validates (and may throw), which would otherwise leave a partially built subclass instance observable.
  • Field Details

    • byAuthority

      private final Map<String,AuthenticationFactor> byAuthority
      Registered factors by the authority that proves them, in registration order.
  • Constructor Details

    • AuthenticationFactorRegistry

      public AuthenticationFactorRegistry(List<AuthenticationFactor> factors)
      Creates the registry.
      Parameters:
      factors - the factors to register.
      Throws:
      IllegalArgumentException - if two factors share an authority.
  • Method Details

    • all

      public List<AuthenticationFactor> all()
      Lists every registered factor.
      Returns:
      the factors, in registration order.
    • findByAuthority

      public Optional<AuthenticationFactor> findByAuthority(String authority)
      Finds the factor proved by an authority.
      Parameters:
      authority - the authority, for example FACTOR_PASSWORD.
      Returns:
      the factor, or an empty optional when none is registered for it.
    • withStrength

      public List<AuthenticationFactor> withStrength(FactorStrength strength)
      Lists the registered factors that have a strength.
      Parameters:
      strength - the strength to look for.
      Returns:
      the factors, in registration order.
    • factorsOf

      public Set<AuthenticationFactor> factorsOf(org.springframework.security.core.Authentication authentication)
      Tells which registered factors an authentication has presented.
      Parameters:
      authentication - the authentication; its authorities that match a registered factor count.
      Returns:
      the factors used, empty when none.