Class MfaExceptionHandler

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
com.irurueta.authserver.authorization.api.web.ProblemJsonExceptionHandler
com.irurueta.authserver.authorization.api.web.mfa.MfaExceptionHandler
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.MessageSourceAware

@RestControllerAdvice(assignableTypes={TotpApi.class,RecoveryCodesApi.class,TrustedDevicesApi.class}) public class MfaExceptionHandler extends ProblemJsonExceptionHandler
Translates the failures of the authenticator app, recovery code and trusted device endpoints to RFC 9457 problem details, answered as application/problem+json. It is scoped to the generated interfaces of those endpoints, so it covers their controllers without depending on the packages they live in. Request validation failures are handled by the parent class. A missing step-up (StepUpGuard) is answered as RFC 9470 describes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    Base of the problem type URNs.

    Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler

    logger, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    Answers an enrolment of an authenticator app that is already enabled.
    org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    Answers a device the account does not have.
    org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    Answers a token whose sign-in is not recent or strong enough: 401 with the RFC 9470 challenge, which tells the client which acr_values and max_age to ask for when it signs the user in again.
    org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    Answers a wrong code.
    org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    Answers a confirmation without an enrolment in progress, or a request for recovery codes from an account without a confirmed authenticator app.
    private static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    respond(org.springframework.http.HttpStatus status, String type, String title, String detail)
    Builds a problem response.

    Methods inherited from class com.irurueta.authserver.authorization.api.web.ProblemJsonExceptionHandler

    createResponseEntity, problemResponse, problemResponse

    Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler

    createProblemDetail, getMessageSource, handleAsyncRequestNotUsableException, handleAsyncRequestTimeoutException, handleConversionNotSupported, handleErrorResponseException, handleException, handleExceptionInternal, handleHandlerMethodValidationException, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMaxUploadSizeExceededException, handleMethodArgumentNotValid, handleMethodValidationException, handleMissingPathVariable, handleMissingServletRequestParameter, handleMissingServletRequestPart, handleNoHandlerFoundException, handleNoResourceFoundException, handleServletRequestBindingException, handleTypeMismatch, setMessageSource

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • MfaExceptionHandler

      public MfaExceptionHandler()
  • Method Details

    • handleAlreadyEnabled

      @ExceptionHandler(TotpAlreadyEnabledException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleAlreadyEnabled(TotpAlreadyEnabledException exception)
      Answers an enrolment of an authenticator app that is already enabled.
      Parameters:
      exception - the failure.
      Returns:
      the 409 problem detail.
    • handleNotEnrolled

      @ExceptionHandler(TotpNotEnrolledException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleNotEnrolled(TotpNotEnrolledException exception)
      Answers a confirmation without an enrolment in progress, or a request for recovery codes from an account without a confirmed authenticator app.
      Parameters:
      exception - the failure.
      Returns:
      the 400 problem detail.
    • handleInvalidCode

      @ExceptionHandler(InvalidTotpCodeException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleInvalidCode(InvalidTotpCodeException exception)
      Answers a wrong code.
      Parameters:
      exception - the failure.
      Returns:
      the 400 problem detail.
    • handleDeviceNotFound

      @ExceptionHandler(TrustedDeviceNotFoundException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleDeviceNotFound(TrustedDeviceNotFoundException exception)
      Answers a device the account does not have.
      Parameters:
      exception - the failure.
      Returns:
      the 404 problem detail.
    • handleInsufficientUserAuthentication

      @ExceptionHandler(InsufficientUserAuthenticationException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleInsufficientUserAuthentication(InsufficientUserAuthenticationException exception)
      Answers a token whose sign-in is not recent or strong enough: 401 with the RFC 9470 challenge, which tells the client which acr_values and max_age to ask for when it signs the user in again.
      Parameters:
      exception - the failure.
      Returns:
      the 401 problem detail with the WWW-Authenticate challenge.
    • respond

      private static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> respond(org.springframework.http.HttpStatus status, String type, String title, String detail)
      Builds a problem response.
      Parameters:
      status - HTTP status.
      type - last segment of the problem type.
      title - short summary.
      detail - explanation.
      Returns:
      the response.