use of org.forgerock.openam.core.rest.authn.exceptions.RestAuthException in project OpenAM by OpenRock.
the class AuthenticationServiceV1 method handleErrorResponse.
/**
* Processes the given Exception into a Restlet response representation or wrap it into
* a ResourceException, which will be thrown.
*
* @param status The status to set the response to.
* @param exception The Exception to be handled.
* @return The Restlet Response Representation.
* @throws ResourceException If the given exception is wrapped in a ResourceException.
*/
protected Response handleErrorResponse(Request request, Status status, Exception exception) {
Reject.ifNull(status);
Response response = new Response(status);
final Map<String, Object> rep = new HashMap<>();
if (exception instanceof RestAuthResponseException) {
final RestAuthResponseException authResponseException = (RestAuthResponseException) exception;
for (Map.Entry<String, String> entry : authResponseException.getResponseHeaders().entrySet()) {
response.getHeaders().put(entry.getKey(), entry.getValue());
}
rep.putAll(authResponseException.getJsonResponse().asMap());
} else if (exception instanceof RestAuthException) {
final RestAuthException authException = (RestAuthException) exception;
if (authException.getFailureUrl() != null) {
rep.put("failureUrl", authException.getFailureUrl());
}
rep.put("errorMessage", getLocalizedMessage(request, exception));
} else if (exception == null) {
rep.put("errorMessage", status.getReasonPhrase());
} else {
rep.put("errorMessage", getLocalizedMessage(request, exception));
}
response.setEntity(rep);
return response;
}
use of org.forgerock.openam.core.rest.authn.exceptions.RestAuthException in project OpenAM by OpenRock.
the class AuthenticationServiceV2 method handleErrorResponse.
@Override
protected Response handleErrorResponse(Request request, Status status, Exception exception) {
Reject.ifNull(status);
Response response = new Response(status);
if (exception instanceof RestAuthResponseException) {
final RestAuthResponseException authResponseException = (RestAuthResponseException) exception;
for (Map.Entry<String, String> entry : authResponseException.getResponseHeaders().entrySet()) {
response.getHeaders().add(entry.getKey(), entry.getValue());
}
response.setEntity(authResponseException.getJsonResponse().asMap());
return response;
} else if (exception instanceof RestAuthException) {
final RestAuthException rae = (RestAuthException) exception;
ResourceException cause = ResourceException.getException(rae.getStatusCode(), getLocalizedMessage(request, rae));
if (rae.getFailureUrl() != null) {
cause.setDetail(json(object(field("failureUrl", rae.getFailureUrl()))));
}
return createExceptionResponse(response, cause);
} else if (exception == null) {
return createExceptionResponse(response, ResourceException.getException(status.getCode()));
} else {
return createExceptionResponse(response, ResourceException.getException(status.getCode(), exception.getMessage(), exception));
}
}
Aggregations