Search in sources :

Example 6 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class ApiKeysRoute method deleteById.

@Override
public void deleteById(final Context context) {
    final String apiKeyId = context.pathParam("id");
    final Optional<ApiKeyDTO> apiKey = apiKeysService.delete(apiKeyId).map(restMapper::toDTO);
    if (apiKey.isPresent()) {
        context.status(200).json(apiKey.get());
    } else {
        context.status(404).json(new Error(ErrorCode.API_KEY_DOES_NOT_EXIST.getCode(), "API key does not exist"));
    }
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) ApiKeyDTO(com.nexblocks.authguard.api.dto.entities.ApiKeyDTO)

Example 7 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class AuthRoute method authenticate.

public void authenticate(final Context context) {
    final AuthRequestDTO authenticationRequest = authRequestBodyHandler.getValidated(context);
    if (authenticationRequest.getDomain() != null && !ActorDomainVerifier.verifyActorDomain(context, authenticationRequest.getDomain())) {
        return;
    }
    final RequestContextBO requestContext = RequestContextExtractor.extractWithoutIdempotentKey(context);
    final Optional<AuthResponseDTO> tokens = authenticationService.authenticate(restMapper.toBO(authenticationRequest), requestContext).map(restMapper::toDTO);
    if (tokens.isPresent()) {
        context.json(tokens.get());
    } else {
        context.status(400).json(new Error("400", "Failed to authenticate user"));
    }
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthResponseDTO(com.nexblocks.authguard.api.dto.entities.AuthResponseDTO) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 8 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class AuthRoute method getExchangeAttempts.

@Override
public void getExchangeAttempts(final Context context) {
    final String entityId = context.queryParam("entityId");
    final OffsetDateTime fromTimestamp = parseOffsetDateTime(context.queryParam("fromTimestamp"));
    final String fromExchange = context.queryParam("fromExchange");
    // take care of checking the parameters
    if (entityId == null) {
        context.status(400).json(new Error(ErrorCode.MISSING_REQUEST_QUERY.getCode(), "Query parameter entityId is required"));
        return;
    }
    if (fromExchange != null && fromTimestamp == null) {
        context.status(400).json(new Error(ErrorCode.MISSING_REQUEST_QUERY.getCode(), "Query parameter fromTimestamp is required when fromExchange is set"));
        return;
    }
    // do the real work
    final ExchangeAttemptsQueryBO query = ExchangeAttemptsQueryBO.builder().entityId(entityId).fromTimestamp(fromTimestamp).fromExchange(fromExchange).build();
    final Collection<ExchangeAttemptDTO> attempts = exchangeAttemptsService.find(query).stream().map(restMapper::toDTO).collect(Collectors.toList());
    context.json(attempts);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Error(com.nexblocks.authguard.api.dto.entities.Error) ExchangeAttemptDTO(com.nexblocks.authguard.api.dto.entities.ExchangeAttemptDTO) ExchangeAttemptsQueryBO(com.nexblocks.authguard.service.model.ExchangeAttemptsQueryBO)

Example 9 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class ActorDomainVerifier method verifyActorDomain.

public static boolean verifyActorDomain(final Context context, final String domain) {
    if (context.attribute("actor") instanceof AppBO) {
        final AppBO actor = context.attribute("actor");
        final boolean isAuthClient = actor.getRoles().contains(AuthGuardRoles.AUTH_CLIENT);
        if (isAuthClient && !actor.getDomain().equals(domain)) {
            context.status(403).json(new Error("", "An auth client violated its restrictions in the request"));
            return false;
        }
        return true;
    }
    return true;
}
Also used : AppBO(com.nexblocks.authguard.service.model.AppBO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 10 with Error

use of com.nexblocks.authguard.api.dto.entities.Error in project AuthGuard by AuthGuard.

the class ExceptionHandlers method timeoutException.

public static void timeoutException(final TimeoutException e, final Context context) {
    final Error error = new Error("504", "Timeout");
    LOG.warn("A timeout error occurred", e);
    context.status(504).json(error);
}
Also used : Error(com.nexblocks.authguard.api.dto.entities.Error) RequestValidationError(com.nexblocks.authguard.api.dto.entities.RequestValidationError)

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