Class AccountExceptionHandler
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
com.irurueta.authserver.authorization.api.web.ProblemJsonExceptionHandler
com.irurueta.authserver.authorization.api.web.account.AccountExceptionHandler
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.MessageSourceAware
@RestControllerAdvice(assignableTypes=AccountController.class)
public class AccountExceptionHandler
extends ProblemJsonExceptionHandler
Translates the failures of
AccountController to RFC 9457 problem details, answered as
application/problem+json. Request validation failures are handled by the parent class, which already
answers problem details. The messages never say whether an e-mail address exists.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringBase of the problem type URNs.(package private) static final StringName of the property that lists the broken password rules.Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
logger, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> Answers a password known to be compromised.org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> Answers a wrong current password.org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleInvalidPassword(InvalidPasswordException exception) Answers a password that breaks the password policy.org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleInvalidToken(InvalidAccountTokenException exception) Answers an invalid, expired or already used token.org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleMailFailure(AccountMailException exception) Answers an account e-mail that could not be delivered: the use case stored nothing, so the user can retry.org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> Answers a client or an e-mail address that made too many account requests, telling when to retry.private static org.springframework.http.ProblemDetailBuilds a bad request problem.private static org.springframework.http.ProblemDetailBuilds a problem.private static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> respond(org.springframework.http.ProblemDetail problem) Wraps a problem into its response.Methods inherited from class com.irurueta.authserver.authorization.api.web.ProblemJsonExceptionHandler
createResponseEntity, problemResponse, problemResponseMethods 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
-
Field Details
-
TYPE_BASE
Base of the problem type URNs.- See Also:
-
VIOLATIONS_PROPERTY
Name of the property that lists the broken password rules.- See Also:
-
-
Constructor Details
-
AccountExceptionHandler
public AccountExceptionHandler()
-
-
Method Details
-
handleInvalidPassword
@ExceptionHandler(InvalidPasswordException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleInvalidPassword(InvalidPasswordException exception) Answers a password that breaks the password policy.- Parameters:
exception- the failure.- Returns:
- the problem detail, listing the broken rules.
-
handleCompromisedPassword
@ExceptionHandler(CompromisedPasswordException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleCompromisedPassword(CompromisedPasswordException exception) Answers a password known to be compromised.- Parameters:
exception- the failure.- Returns:
- the problem detail.
-
handleInvalidCredentials
@ExceptionHandler(InvalidCredentialsException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleInvalidCredentials(InvalidCredentialsException exception) Answers a wrong current password.- Parameters:
exception- the failure.- Returns:
- the problem detail.
-
handleInvalidToken
@ExceptionHandler(InvalidAccountTokenException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleInvalidToken(InvalidAccountTokenException exception) Answers an invalid, expired or already used token.- Parameters:
exception- the failure.- Returns:
- the problem detail.
-
handleRateLimited
@ExceptionHandler(AccountRateLimitExceededException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleRateLimited(AccountRateLimitExceededException exception) Answers a client or an e-mail address that made too many account requests, telling when to retry.- Parameters:
exception- the failure.- Returns:
- the
429problem detail, with aRetry-Afterheader in seconds.
-
handleMailFailure
@ExceptionHandler(AccountMailException.class) public org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> handleMailFailure(AccountMailException exception) Answers an account e-mail that could not be delivered: the use case stored nothing, so the user can retry.- Parameters:
exception- the failure.- Returns:
- the
503problem detail.
-
problem
private static org.springframework.http.ProblemDetail problem(String type, String title, String detail) Builds a bad request problem.- Parameters:
type- last segment of the problem type.title- short summary.detail- explanation.- Returns:
- the problem detail.
-
problem
private static org.springframework.http.ProblemDetail problem(org.springframework.http.HttpStatus status, String type, String title, String detail) Builds a problem.- Parameters:
status- HTTP status of the answer.type- last segment of the problem type.title- short summary.detail- explanation.- Returns:
- the problem detail.
-
respond
private static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> respond(org.springframework.http.ProblemDetail problem) Wraps a problem into its response.- Parameters:
problem- the problem.- Returns:
- the response carrying the problem's status.
-