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
FieldsModifier and TypeFieldDescriptionprivate final StepUpProblemMapperBuilds the extra members of a step-up problem.(package private) static final StringBase of the problem type URNs. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleForbidden(DocumentsForbiddenException exception) Answers an operation the user may not perform with 403.org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleNotFound(DocumentNotFoundException exception) 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 toGET /bff/login, so the user signs in again with a strong and recent enough authentication.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.org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleUnavailable(DocumentsUnavailableException exception) Answers an unreachable or failing resource server with 502.private static org.springframework.http.ProblemDetailBuilds a problem detail.private static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> 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.
-
Field Details
-
TYPE_BASE
Base of the problem type URNs.- See Also:
-
stepUpProblemMapper
Builds the extra members of a step-up problem.
-
-
Constructor Details
-
DocumentsExceptionHandler
public DocumentsExceptionHandler()
-
-
Method Details
-
handleUnauthorized
@ExceptionHandler(com.irurueta.authserver.bff.domain.documents.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(com.irurueta.authserver.bff.domain.documents.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 toGET /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(com.irurueta.authserver.bff.domain.documents.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(com.irurueta.authserver.bff.domain.documents.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.
-
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.
-