use of org.cloudfoundry.credhub.exceptions.AccessTokenExpiredException in project credhub by cloudfoundry-incubator.
the class AuditOAuth2AuthenticationExceptionHandler method commence.
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
String token = (String) request.getAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_VALUE);
final Map<String, Object> tokenInformation = extractTokenInformation(token);
Throwable cause = extractCause(authException);
Exception exception;
if (tokenIsExpired(tokenInformation)) {
exception = new AccessTokenExpiredException("Access token expired", cause);
} else if (cause instanceof InvalidSignatureException || cause instanceof SignatureException) {
exception = new InvalidTokenException(messageSourceAccessor.getMessage("error.invalid_token_signature"), cause);
} else {
exception = new InvalidTokenException(removeTokenFromMessage(authException.getMessage(), token), cause);
}
exception.setStackTrace(authException.getStackTrace());
try {
doHandle(request, response, exception);
} finally {
final String message = removeTokenFromMessage(exception.getMessage(), token);
logAuthFailureToDb(request, tokenInformation, response.getStatus(), message);
}
}
Aggregations