use of com.nexblocks.authguard.api.dto.requests.AuthRequestDTO in project AuthGuard by AuthGuard.
the class ApiKeysRoute method verify.
@Override
public void verify(final Context context) {
final AuthRequestDTO authenticationRequest = authRequestBodyHandler.getValidated(context);
final Optional<AppBO> app = apiKeysService.validateApiKey(authenticationRequest.getToken());
if (app.isPresent()) {
context.status(200).json(app.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.requests.AuthRequestDTO 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.requests.AuthRequestDTO in project AuthGuard by AuthGuard.
the class AuthRequestValidatorTest method validateNoViolationsNoRestrictions.
@Test
void validateNoViolationsNoRestrictions() {
final AuthRequestDTO valid = AuthRequestDTO.builder().build();
final Validator<AuthRequestDTO> validator = Validators.getForClass(AuthRequestDTO.class);
final List<Violation> violations = validator.validate(valid);
assertThat(violations).isEmpty();
}
use of com.nexblocks.authguard.api.dto.requests.AuthRequestDTO in project AuthGuard by AuthGuard.
the class AuthRouteTest method authenticateUnsuccessful.
@Test
void authenticateUnsuccessful() {
final AuthRequestDTO requestDTO = randomObject(AuthRequestDTO.class);
final AuthRequestBO requestBO = restMapper.toBO(requestDTO);
final RequestContextBO requestContext = RequestContextBO.builder().build();
Mockito.when(authenticationService.authenticate(requestBO, requestContext)).thenReturn(Optional.empty());
given().body(requestDTO).post(url("authenticate")).then().statusCode(400);
}
use of com.nexblocks.authguard.api.dto.requests.AuthRequestDTO 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")));
}
Aggregations