java.lang.Object
com.irurueta.authserver.authorization.domain.mfa.MfaPolicy

public class MfaPolicy extends Object
The rule that decides when the factors of an authentication are enough, and when they are required. It is pure: it knows nothing about sessions, requests or storage.
  • Field Details

    • MIN_MULTI_FACTORS

      public static final int MIN_MULTI_FACTORS
      Minimum number of distinct reported factors of a multi-factor authentication.
      See Also:
  • Constructor Details

    • MfaPolicy

      public MfaPolicy()
  • Method Details

    • isSatisfied

      public boolean isSatisfied(Set<AuthenticationFactor> factors)
      Tells whether a set of factors satisfies the sign-in policy: a FactorStrength.PRIMARY_STRONG factor alone, or a FactorStrength.PRIMARY factor together with a FactorStrength.SECOND or a FactorStrength.REMEMBERED one (a trusted device skips the second factor of a sign-in).
      Parameters:
      factors - the factors used by the authentication; must not be null.
      Returns:
      true when the factors are enough.
    • isReported

      public boolean isReported(AuthenticationFactor factor)
      Tells whether a factor proves something about the authentication it was presented in, and is therefore reported (amr, acr, auth_time) and counted by a step-up request. A FactorStrength.REMEMBERED factor is not: it only recalls a second factor presented earlier.
      Parameters:
      factor - the factor.
      Returns:
      true unless the factor is FactorStrength.REMEMBERED.
    • isMultiFactor

      public boolean isMultiFactor(Set<AuthenticationFactor> factors)
      Tells whether the factors of an authentication make it multi-factor, the one rule behind the amr mfa value, the multi-factor acr and every step-up check: at least MIN_MULTI_FACTORS distinct reported factors, or one reported factor that proves a multi-factor authentication alone (AuthenticationFactor.multiFactor()). A FactorStrength.PRIMARY_STRONG factor alone satisfies the sign-in policy (isSatisfied(java.util.Set<com.irurueta.authserver.authorization.domain.mfa.AuthenticationFactor>)) but is multi-factor only when it says so: a passkey or a certificate proves one thing, however strongly.
      Parameters:
      factors - the factors used by the authentication; must not be null.
      Returns:
      true for a multi-factor authentication.
    • isPrimary

      public boolean isPrimary(AuthenticationFactor factor)
      Tells whether a factor is the primary one of an authentication, the one auth_time and max_age are measured from.
      Parameters:
      factor - the factor.
      Returns:
      true for a FactorStrength.PRIMARY or FactorStrength.PRIMARY_STRONG factor.
    • isRequired

      public boolean isRequired(boolean clientRequires, boolean userRequires)
      Tells whether multi-factor authentication is required, which is when either the client or the user demands it.
      Parameters:
      clientRequires - whether the client being served requires it.
      userRequires - whether the user's account requires it.
      Returns:
      true when a second factor is required.
    • hasStrength

      private static boolean hasStrength(Set<AuthenticationFactor> factors, FactorStrength strength)
      Tells whether any factor has a strength.
      Parameters:
      factors - the factors to inspect.
      strength - the strength to look for.
      Returns:
      true when at least one factor has that strength.