Search in sources :

Example 21 with Error

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

the class AuthRoute method logout.

@Override
public void logout(final Context context) {
    final AuthRequestDTO authenticationRequest = authRequestBodyHandler.getValidated(context);
    final RequestContextBO requestContext = RequestContextExtractor.extractWithoutIdempotentKey(context);
    authenticationService.logout(restMapper.toBO(authenticationRequest), requestContext).ifPresentOrElse(tokens -> context.json(restMapper.toDTO(tokens)), () -> context.status(400).json(new Error("400", "Failed to log user out")));
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 22 with Error

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

the class AuthRoute method clearToken.

@Override
public void clearToken(final Context context) {
    final AuthRequestDTO authenticationRequest = authRequestBodyHandler.getValidated(context);
    final String tokenType = context.queryParam("tokenType");
    if (tokenType == null) {
        context.status(400).json(new Error("400", "Missing 'tokenType' query parameter"));
    } else {
        final AuthResponseBO tokens = exchangeService.delete(restMapper.toBO(authenticationRequest), tokenType);
        context.json(restMapper.toDTO(tokens));
    }
}
Also used : AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 23 with Error

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

the class CredentialsRoute method update.

public void update(final Context context) {
    final CredentialsDTO credentials = RestJsonMapper.asClass(context.body(), CredentialsDTO.class);
    if (credentials.getPlainPassword() != null) {
        context.status(400).json(new Error("400", "Password cannot be updated using regular update"));
        return;
    }
    final String credentialsId = context.pathParam("id");
    final Optional<CredentialsDTO> updated = Optional.of(credentials.withId(credentialsId)).map(restMapper::toBO).flatMap(credentialsService::update).map(restMapper::toDTO);
    if (updated.isPresent()) {
        context.status(200).json(updated.get());
    } else {
        context.status(404);
    }
}
Also used : CredentialsDTO(com.nexblocks.authguard.api.dto.entities.CredentialsDTO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 24 with Error

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

the class CredentialsRoute method create.

public void create(final Context context) {
    final String idempotentKey = IdempotencyHeader.getKeyOrFail(context);
    final CreateCredentialsRequestDTO request = credentialsRequestBodyHandler.getValidated(context);
    if (!ActorDomainVerifier.verifyActorDomain(context, request.getDomain())) {
        return;
    }
    final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(idempotentKey).source(context.ip()).build();
    final CredentialsBO credentials = restMapper.toBO(request);
    final List<UserIdentifierBO> identifiers = credentials.getIdentifiers().stream().map(identifier -> identifier.withDomain(request.getDomain())).collect(Collectors.toList());
    final Optional<CredentialsDTO> created = Optional.of(credentials.withIdentifiers(identifiers)).map(credentialsBO -> credentialsService.create(credentialsBO, requestContext)).map(restMapper::toDTO);
    if (created.isPresent()) {
        context.status(201).json(created.get());
    } else {
        context.status(400).json(new Error("400", "Failed to create credentials"));
    }
}
Also used : CredentialsDTO(com.nexblocks.authguard.api.dto.entities.CredentialsDTO) Inject(com.google.inject.Inject) UserIdentifiersRequestDTO(com.nexblocks.authguard.api.dto.requests.UserIdentifiersRequestDTO) Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) CredentialsService(com.nexblocks.authguard.service.CredentialsService) CredentialsApi(com.nexblocks.authguard.api.routes.CredentialsApi) UserIdentifierDTO(com.nexblocks.authguard.api.dto.entities.UserIdentifierDTO) RestMapper(com.nexblocks.authguard.rest.mappers.RestMapper) Context(io.javalin.http.Context) ActorDomainVerifier(com.nexblocks.authguard.rest.access.ActorDomainVerifier) CreateCredentialsRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO) IdempotencyHeader(com.nexblocks.authguard.rest.util.IdempotencyHeader) PasswordResetRequestDTO(com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO) RequestValidationException(com.nexblocks.authguard.rest.exceptions.RequestValidationException) com.nexblocks.authguard.service.model(com.nexblocks.authguard.service.model) AuthGuardRoles(com.nexblocks.authguard.api.access.AuthGuardRoles) PasswordResetTokenRequestDTO(com.nexblocks.authguard.api.dto.requests.PasswordResetTokenRequestDTO) Collectors(java.util.stream.Collectors) List(java.util.List) BodyHandler(com.nexblocks.authguard.rest.util.BodyHandler) Error(com.nexblocks.authguard.api.dto.entities.Error) RestJsonMapper(com.nexblocks.authguard.rest.mappers.RestJsonMapper) Optional(java.util.Optional) Collections(java.util.Collections) ViolationType(com.nexblocks.authguard.api.dto.validation.violations.ViolationType) CredentialsDTO(com.nexblocks.authguard.api.dto.entities.CredentialsDTO) Error(com.nexblocks.authguard.api.dto.entities.Error) CreateCredentialsRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO)

Example 25 with Error

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

the class AuthorizationHandler method populateBearerActor.

private void populateBearerActor(final Context context, final String apiKey) {
    final Optional<AppBO> actorApp = apiKeysService.validateApiKey(apiKey);
    if (actorApp.isPresent()) {
        LOG.info("Authenticated actor {} with bearer token", actorApp.get().getId());
        context.attribute("actor", actorApp.get());
    } else {
        LOG.info("Failed to authenticate actor with bearer token");
        context.status(401).json(new Error("401", "Failed to authenticate with bearer scheme"));
    }
}
Also used : AppBO(com.nexblocks.authguard.service.model.AppBO) Error(com.nexblocks.authguard.api.dto.entities.Error)

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