Search in sources :

Example 26 with Error

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"));
    }
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) Error(com.nexblocks.authguard.api.dto.entities.Error) ServiceException(com.nexblocks.authguard.service.exceptions.ServiceException)

Example 27 with Error

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);
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) RequestValidationError(com.nexblocks.authguard.api.dto.entities.RequestValidationError)

Example 28 with 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);
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) RequestValidationError(com.nexblocks.authguard.api.dto.entities.RequestValidationError)

Example 29 with 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);
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) RequestValidationError(com.nexblocks.authguard.api.dto.entities.RequestValidationError)

Example 30 with 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"));
    }
}
Also used : ServiceConflictException(com.nexblocks.authguard.service.exceptions.ServiceConflictException) ServiceException(com.nexblocks.authguard.service.exceptions.ServiceException) IdempotencyException(com.nexblocks.authguard.service.exceptions.IdempotencyException) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) Error(com.nexblocks.authguard.api.dto.entities.Error) RequestValidationError(com.nexblocks.authguard.api.dto.entities.RequestValidationError) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Error (com.nexblocks.authguard.api.dto.entities.Error)31 AccountDTO (com.nexblocks.authguard.api.dto.entities.AccountDTO)9 RequestValidationError (com.nexblocks.authguard.api.dto.entities.RequestValidationError)7 Inject (com.google.inject.Inject)4 AuthRequestDTO (com.nexblocks.authguard.api.dto.requests.AuthRequestDTO)4 RestMapper (com.nexblocks.authguard.rest.mappers.RestMapper)4 BodyHandler (com.nexblocks.authguard.rest.util.BodyHandler)4 IdempotencyHeader (com.nexblocks.authguard.rest.util.IdempotencyHeader)4 Context (io.javalin.http.Context)4 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 AuthGuardRoles (com.nexblocks.authguard.api.access.AuthGuardRoles)3 ApiKeyDTO (com.nexblocks.authguard.api.dto.entities.ApiKeyDTO)3 AppDTO (com.nexblocks.authguard.api.dto.entities.AppDTO)3 ActorDomainVerifier (com.nexblocks.authguard.rest.access.ActorDomainVerifier)3 ApplicationsService (com.nexblocks.authguard.service.ApplicationsService)3 CredentialsService (com.nexblocks.authguard.service.CredentialsService)3 IdempotencyException (com.nexblocks.authguard.service.exceptions.IdempotencyException)3 com.nexblocks.authguard.service.model (com.nexblocks.authguard.service.model)3