use of com.nexblocks.authguard.api.dto.requests.AuthRequestDTO in project AuthGuard by AuthGuard.
the class AuthRoute method exchange.
public void exchange(final Context context) {
final AuthRequestDTO authenticationRequest = authRequestBodyHandler.getValidated(context);
if (authenticationRequest.getDomain() != null && !ActorDomainVerifier.verifyActorDomain(context, authenticationRequest.getDomain())) {
return;
}
final String from = context.queryParam("from");
final String to = context.queryParam("to");
final RequestContextBO requestContext = RequestContextExtractor.extractWithoutIdempotentKey(context);
final AuthResponseBO tokens = exchangeService.exchange(restMapper.toBO(authenticationRequest), from, to, requestContext);
context.json(restMapper.toDTO(tokens));
}
use of com.nexblocks.authguard.api.dto.requests.AuthRequestDTO 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));
}
}
use of com.nexblocks.authguard.api.dto.requests.AuthRequestDTO in project AuthGuard by AuthGuard.
the class AuthRouteTest method authenticate.
@Test
void authenticate() {
final AuthRequestDTO requestDTO = randomObject(AuthRequestDTO.class);
final AuthRequestBO requestBO = restMapper.toBO(requestDTO);
final AuthResponseBO tokensBO = AuthResponseBO.builder().token("token").build();
final AuthResponseDTO tokensDTO = mapper().toDTO(tokensBO);
Mockito.when(authenticationService.authenticate(Mockito.eq(requestBO), Mockito.any())).thenReturn(Optional.of(tokensBO));
final ValidatableResponse httpResponse = given().body(requestDTO).post(url("authenticate")).then().statusCode(200).contentType(ContentType.JSON);
final AuthResponseDTO responseBody = httpResponse.extract().response().body().as(AuthResponseDTO.class);
assertThat(responseBody).isEqualTo(tokensDTO);
}
use of com.nexblocks.authguard.api.dto.requests.AuthRequestDTO in project AuthGuard by AuthGuard.
the class AuthRequestValidatorTest method validateWithIdentifierAndDomain.
@Test
void validateWithIdentifierAndDomain() {
final AuthRequestDTO valid = AuthRequestDTO.builder().identifier("identifier").domain("main").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 AuthRequestValidatorTest method validateNoViolations.
@Test
void validateNoViolations() {
final AuthRequestDTO valid = AuthRequestDTO.builder().restrictions(TokenRestrictionsDTO.builder().addScopes("scope").addPermissions("permission").build()).build();
final Validator<AuthRequestDTO> validator = Validators.getForClass(AuthRequestDTO.class);
final List<Violation> violations = validator.validate(valid);
assertThat(violations).isEmpty();
}
Aggregations