Class DocumentsExceptionHandler

java.lang.Object
com.irurueta.authserver.bff.api.web.documents.DocumentsExceptionHandler

@RestControllerAdvice(assignableTypes=DocumentsController.class) public class DocumentsExceptionHandler extends Object
Translates the failures of DocumentsController to RFC 9457 problem details. The media type is not forced, so a client that only accepts application/json still gets the status and the problem instead of 406: Spring writes a problem detail as application/problem+json when the client's types do not include it. The detail is a fixed text: the message of the failure, and anything the resource server said, never reach the browser, except the values of a step-up request, which StepUpProblemMapper keeps within what GET /bff/login accepts.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final StepUpProblemMapper
    Builds the extra members of a step-up problem.
    (package private) static final String
    Base of the problem type URNs.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    Answers an operation the user may not perform with 403.
    org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    Answers a missing document, or someone else's, with 404.
    org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    Answers a step-up request of the resource server (RFC 9470) with 401 and the values the SPA passes to GET /bff/login, so the user signs in again with a strong and recent enough authentication.
    org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    Answers a session without a valid token with 401, so the SPA signs the user in again.
    org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    Answers an unreachable or failing resource server with 502.
    private static org.springframework.http.ProblemDetail
    problem(org.springframework.http.HttpStatus status, String type, String detail)
    Builds a problem detail.
    private static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    respond(org.springframework.http.HttpStatus status, String type, String detail)
    Builds a problem response.
    private static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail>
    respond(org.springframework.http.ProblemDetail problem)
    Answers a problem detail with its status; the media type is left to content negotiation.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • DocumentsExceptionHandler

      public DocumentsExceptionHandler()
  • Method Details

    • handleUnauthorized

      @ExceptionHandler(DocumentsUnauthorizedException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleUnauthorized(DocumentsUnauthorizedException exception)
      Answers a session without a valid token with 401, so the SPA signs the user in again.
      Parameters:
      exception - the failure.
      Returns:
      the problem detail.
    • handleStepUpRequired

      @ExceptionHandler(DocumentsStepUpRequiredException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleStepUpRequired(DocumentsStepUpRequiredException exception)
      Answers a step-up request of the resource server (RFC 9470) with 401 and the values the SPA passes to GET /bff/login, so the user signs in again with a strong and recent enough authentication.
      Parameters:
      exception - the failure, with the values the resource server asked for.
      Returns:
      the problem detail.
    • handleForbidden

      @ExceptionHandler(DocumentsForbiddenException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleForbidden(DocumentsForbiddenException exception)
      Answers an operation the user may not perform with 403.
      Parameters:
      exception - the failure.
      Returns:
      the problem detail.
    • handleNotFound

      @ExceptionHandler(DocumentNotFoundException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleNotFound(DocumentNotFoundException exception)
      Answers a missing document, or someone else's, with 404.
      Parameters:
      exception - the failure.
      Returns:
      the problem detail.
    • handleUnavailable

      @ExceptionHandler(DocumentsUnavailableException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleUnavailable(DocumentsUnavailableException exception)
      Answers an unreachable or failing resource server with 502.
      Parameters:
      exception - the failure.
      Returns:
      the problem detail.
    • respond

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

      private static org.springframework.http.ProblemDetail problem(org.springframework.http.HttpStatus status, String type, String detail)
      Builds a problem detail.
      Parameters:
      status - HTTP status.
      type - last segment of the problem type.
      detail - explanation shown to the user.
      Returns:
      the problem detail.
    • respond

      private static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> respond(org.springframework.http.ProblemDetail problem)
      Answers a problem detail with its status; the media type is left to content negotiation.
      Parameters:
      problem - the problem detail.
      Returns:
      the response.