private AuthenticationResponse fail(Throwable throwable) { if (optional) { LOGGER.log(Level.FINE, "Failed to authenticate Google token", throwable); return AuthenticationResponse.abstain(); } String description = ((null == throwable) ? null : throwable.getMessage()); if (null == description) { description = ((null == throwable) ? "verification failed" : throwable.getClass().getName()); } return AuthenticationResponse.builder() .statusCode(401) .responseHeader(HEADER_AUTHENTICATION_REQUIRED, buildChallenge(description)) .status(AuthenticationResponse.SecurityStatus.FAILURE) .description(description) .throwable(throwable) .build(); }
private AuthenticationResponse failInvalidRequest(Exception e) { if (optional) { LOGGER.log(Level.FINE, "Failed to authenticate Google token", e); return AuthenticationResponse.abstain(); } return AuthenticationResponse.builder() .statusCode(400) .responseHeader(HEADER_AUTHENTICATION_REQUIRED, buildInvalidRequestChallenge(e)) .status(AuthenticationResponse.SecurityStatus.FAILURE) .description("Invalid authorization header") .throwable(e) .build(); }
/** * Construct a failed response with a throwable as a cause. * * @param message Descriptive message of what happened. This message is propagated to public API! * @param cause Throwable causing the failed authentication. This will be logged. It may reach user only in case of debug. * @return AuthenticationResponse with information filled */ public static AuthenticationResponse failed(String message, Throwable cause) { return builder().description(message).throwable(cause).status(SecurityStatus.FAILURE).build(); }