Class StepUpChallengeMapper

java.lang.Object
com.irurueta.authserver.bff.infrastructure.resourceserver.StepUpChallengeMapper

@Component public class StepUpChallengeMapper extends Object
Maps the WWW-Authenticate challenge of a 401 answer of the resource server onto the domain: a bearer challenge with error="insufficient_user_authentication" (RFC 9470) becomes a DocumentsStepUpRequiredException carrying its acr_values and max_age. Any other challenge, or none, is not a step-up request.
  • Field Details

    • INSUFFICIENT_USER_AUTHENTICATION

      static final String INSUFFICIENT_USER_AUTHENTICATION
      Error code of a step-up challenge (RFC 9470, section 3).
      See Also:
    • BEARER

      private static final String BEARER
      Authentication scheme of the challenge.
      See Also:
    • ERROR

      private static final String ERROR
      Name of the error parameter of the challenge.
      See Also:
    • ACR_VALUES

      private static final String ACR_VALUES
      Name of the parameter carrying the authentication context classes asked for.
      See Also:
    • MAX_AGE

      private static final String MAX_AGE
      Name of the parameter carrying the maximum age of the authentication, in seconds.
      See Also:
    • PARAMETER

      private static final Pattern PARAMETER
      One auth-param of the challenge: a name and a quoted string (with escapes) or a bare token.
    • NAME_GROUP

      private static final int NAME_GROUP
      Group of PARAMETER holding the parameter name.
      See Also:
    • QUOTED_VALUE_GROUP

      private static final int QUOTED_VALUE_GROUP
      Group of PARAMETER holding a quoted value, without its quotes.
      See Also:
    • TOKEN_VALUE_GROUP

      private static final int TOKEN_VALUE_GROUP
      Group of PARAMETER holding a bare token value.
      See Also:
    • QUOTED_PAIR

      private static final Pattern QUOTED_PAIR
      Escape sequence of a quoted string: a backslash and the character it protects.
  • Constructor Details

    • StepUpChallengeMapper

      public StepUpChallengeMapper()
  • Method Details

    • toException

      public Optional<DocumentsStepUpRequiredException> toException(org.springframework.http.HttpHeaders headers, Throwable cause)
      Reads the step-up request of a 401 answer, if it is one.
      Parameters:
      headers - headers of the answer; null when it had none.
      cause - the failure to keep as the cause of the domain exception.
      Returns:
      the step-up request, or empty when the answer carries no step-up challenge.
    • isBearer

      private static boolean isBearer(String challenge)
      Tells whether a challenge is of the bearer scheme.
      Parameters:
      challenge - value of a WWW-Authenticate header.
      Returns:
      true when its scheme is Bearer, in any case.
    • parameters

      private static Map<String,String> parameters(String challenge)
      Reads the auth-params of a bearer challenge.
      Parameters:
      challenge - value of a WWW-Authenticate header of the bearer scheme.
      Returns:
      the parameters by lower-case name; a repeated parameter keeps its first value.
    • maxAgeOf

      private static Duration maxAgeOf(String value)
      Reads the max_age parameter.
      Parameters:
      value - the parameter, in seconds; null when absent.
      Returns:
      the maximum age, or null when absent, not a number or negative.