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"));
}
}
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"));
}
}
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);
}
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;
}
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);
}
Aggregations