Search in sources :

Example 1 with AccessTokenExpiredException

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);
    }
}
Also used : InvalidTokenException(org.springframework.security.oauth2.common.exceptions.InvalidTokenException) AccessTokenExpiredException(org.cloudfoundry.credhub.exceptions.AccessTokenExpiredException) InvalidSignatureException(org.springframework.security.jwt.crypto.sign.InvalidSignatureException) InvalidSignatureException(org.springframework.security.jwt.crypto.sign.InvalidSignatureException) SignatureException(java.security.SignatureException) ServletException(javax.servlet.ServletException) InvalidSignatureException(org.springframework.security.jwt.crypto.sign.InvalidSignatureException) AuthenticationException(org.springframework.security.core.AuthenticationException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) AccessTokenExpiredException(org.cloudfoundry.credhub.exceptions.AccessTokenExpiredException) InvalidTokenException(org.springframework.security.oauth2.common.exceptions.InvalidTokenException)

Aggregations

IOException (java.io.IOException)1 SignatureException (java.security.SignatureException)1 ServletException (javax.servlet.ServletException)1 AccessTokenExpiredException (org.cloudfoundry.credhub.exceptions.AccessTokenExpiredException)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 InvalidSignatureException (org.springframework.security.jwt.crypto.sign.InvalidSignatureException)1 InvalidTokenException (org.springframework.security.oauth2.common.exceptions.InvalidTokenException)1