use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.
the class AuthorizationHandler method populateBasicActor.
private void populateBasicActor(final Context context, final String base64Credentials) {
final Either<Exception, AccountBO> actorAccount = basicAuth.authenticateAndGetAccount(base64Credentials);
if (actorAccount.isRight()) {
LOG.info("Authenticated actor {} with basic credentials", actorAccount.get().getId());
context.attribute("actor", actorAccount.get());
} else {
LOG.info("Failed to authenticate actor with basic credentials");
context.status(401).json(new Error("401", "Failed to authenticate with basic scheme"));
}
}
use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.
the class ExceptionHandlers method serviceAuthorizationException.
public static void serviceAuthorizationException(final ServiceAuthorizationException e, final Context context) {
LOG.info("Service authorization exception was thrown");
final Error error = new Error(e.getErrorCode(), e.getMessage());
/*
* We leave 401 to signal an unauthorized access.
* TODO: don't rely on exceptions to highlight something like that and instead
* make the service return the error using an Either.
*/
context.status(400).json(error);
}
use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.
the class ExceptionHandlers method serviceException.
public static void serviceException(final ServiceException e, final Context context) {
LOG.info("Service exception was thrown");
final Error error = new Error(e.getErrorCode(), e.getMessage());
context.status(400).json(error);
}
use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.
the class ExceptionHandlers method jsonMappingException.
public static void jsonMappingException(final RuntimeJsonException e, final Context context) {
final Error error = new Error("", "Failed to parse JSON at " + e.getCause().getLocation());
context.status(422).json(error);
}
use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.
the class ExceptionHandlers method completionException.
// NOTE: this will go away when we move to async services
public static void completionException(final CompletionException e, final Context context) {
final Throwable cause = e.getCause();
if (cause == null) {
LOG.error("A CompletionException was thrown without a cause", e);
context.status(500).json(new Error("UNKNOWN", "An unknown error occurred"));
} else if (cause instanceof ServiceAuthorizationException) {
serviceAuthorizationException((ServiceAuthorizationException) cause, context);
} else if (cause instanceof ServiceConflictException) {
serviceConflictException((ServiceConflictException) cause, context);
} else if (cause instanceof ServiceException) {
serviceException((ServiceException) cause, context);
} else if (cause instanceof RuntimeJsonException) {
jsonMappingException((RuntimeJsonException) cause, context);
} else if (cause instanceof RequestValidationException) {
requestValidationException((RequestValidationException) cause, context);
} else if (cause instanceof IdempotencyException) {
idempotencyException((IdempotencyException) cause, context);
} else if (cause instanceof TimeoutException) {
timeoutException((TimeoutException) cause, context);
} else {
LOG.error("An unexpected exception was thrown", cause);
context.status(500).json(new Error("UNKNOWN", "An unknown error occurred"));
}
}
Aggregations