use of com.nexblocks.authguard.rest.mappers.RestMapper in project AuthGuard by AuthGuard.
the class AccountsRoute method create.
public void create(final Context context) {
final String idempotentKey = IdempotencyHeader.getKeyOrFail(context);
final CreateAccountRequestDTO request = accountRequestBodyHandler.getValidated(context);
if (!canPerform(context, request)) {
context.status(403).json(new Error("", "An auth client violated its restrictions in the request"));
return;
}
final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(idempotentKey).source(context.ip()).build();
final Optional<AccountDTO> createdAccount = Optional.of(restMapper.toBO(request)).map(accountBO -> accountsService.create(accountBO, requestContext)).map(restMapper::toDTO);
if (createdAccount.isPresent()) {
context.status(201).json(createdAccount.get());
} else {
context.status(400).json(new Error("400", "Failed to create account"));
}
}
use of com.nexblocks.authguard.rest.mappers.RestMapper in project AuthGuard by AuthGuard.
the class ApplicationsRoute method create.
public void create(final Context context) {
final String idempotentKey = IdempotencyHeader.getKeyOrFail(context);
final CreateAppRequestDTO request = appRequestRequestBodyHandler.getValidated(context);
final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(idempotentKey).source(context.ip()).build();
final Optional<Object> created = Optional.of(restMapper.toBO(request)).map(appBO -> applicationsService.create(appBO, requestContext)).map(restMapper::toDTO);
if (created.isPresent()) {
context.status(201).json(created.get());
} else {
context.status(400).json(new Error("400", "Failed to create application"));
}
}
use of com.nexblocks.authguard.rest.mappers.RestMapper 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"));
}
}
Aggregations