Search in sources :

Example 6 with AuthRequestDTO

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));
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO)

Example 7 with AuthRequestDTO

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));
    }
}
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 8 with AuthRequestDTO

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);
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) AuthResponseDTO(com.nexblocks.authguard.api.dto.entities.AuthResponseDTO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO) AuthRequestBO(com.nexblocks.authguard.service.model.AuthRequestBO) Test(org.junit.jupiter.api.Test)

Example 9 with AuthRequestDTO

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();
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO) Test(org.junit.jupiter.api.Test)

Example 10 with AuthRequestDTO

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();
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO) Test(org.junit.jupiter.api.Test)

Aggregations

AuthRequestDTO (com.nexblocks.authguard.api.dto.requests.AuthRequestDTO)11 Test (org.junit.jupiter.api.Test)6 Error (com.nexblocks.authguard.api.dto.entities.Error)4 Violation (com.nexblocks.authguard.api.dto.validation.violations.Violation)4 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)4 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)3 AuthResponseDTO (com.nexblocks.authguard.api.dto.entities.AuthResponseDTO)2 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)2 AppBO (com.nexblocks.authguard.service.model.AppBO)1 ValidatableResponse (io.restassured.response.ValidatableResponse)1