Search in sources :

Example 1 with RequestContextBO

use of com.nexblocks.authguard.service.model.RequestContextBO 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"));
    }
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthResponseDTO(com.nexblocks.authguard.api.dto.entities.AuthResponseDTO) AuthRequestDTO(com.nexblocks.authguard.api.dto.requests.AuthRequestDTO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 2 with RequestContextBO

use of com.nexblocks.authguard.service.model.RequestContextBO in project AuthGuard by AuthGuard.

the class OtpRoute method verify.

public void verify(final Context context) {
    final OtpRequestDTO body = otpRequestBodyHandler.getValidated(context);
    final RequestContextBO requestContext = RequestContextExtractor.extractWithoutIdempotentKey(context);
    final AuthResponseDTO tokens = restMapper.toDTO(otpService.authenticate(body.getPasswordId(), body.getPassword(), requestContext));
    context.json(tokens);
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthResponseDTO(com.nexblocks.authguard.api.dto.entities.AuthResponseDTO) OtpRequestDTO(com.nexblocks.authguard.api.dto.requests.OtpRequestDTO)

Example 3 with RequestContextBO

use of com.nexblocks.authguard.service.model.RequestContextBO in project AuthGuard by AuthGuard.

the class PasswordlessRoute method verify.

public void verify(final Context context) {
    final PasswordlessRequestDTO request = passwordlessRequestBodyHandler.getValidated(context);
    final RequestContextBO requestContext = RequestContextExtractor.extractWithoutIdempotentKey(context);
    final AuthResponseBO generatedTokens = passwordlessService.authenticate(request.getToken(), requestContext);
    context.json(generatedTokens);
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) PasswordlessRequestDTO(com.nexblocks.authguard.api.dto.requests.PasswordlessRequestDTO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO)

Example 4 with RequestContextBO

use of com.nexblocks.authguard.service.model.RequestContextBO in project AuthGuard by AuthGuard.

the class OtpServiceImplTest method authenticate.

@Test
void authenticate() {
    final OtpConfig otpConfig = OtpConfig.builder().generateToken("accessToken").build();
    setup(otpConfig);
    final OneTimePasswordDO otp = random.nextObject(OneTimePasswordDO.class);
    final AuthResponseBO tokens = random.nextObject(AuthResponseBO.class);
    final String otpToken = otp.getId() + ":" + otp.getPassword();
    final AuthRequestBO authRequest = AuthRequestBO.builder().token(otpToken).build();
    final RequestContextBO requestContext = RequestContextBO.builder().build();
    Mockito.when(mockExchangeService.exchange(authRequest, "otp", otpConfig.getGenerateToken(), requestContext)).thenReturn(tokens);
    final AuthResponseBO generated = otpService.authenticate(otp.getId(), otp.getPassword(), requestContext);
    assertThat(generated).isEqualTo(tokens);
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) OtpConfig(com.nexblocks.authguard.basic.config.OtpConfig) OneTimePasswordDO(com.nexblocks.authguard.dal.model.OneTimePasswordDO) AuthRequestBO(com.nexblocks.authguard.service.model.AuthRequestBO) Test(org.junit.jupiter.api.Test)

Example 5 with RequestContextBO

use of com.nexblocks.authguard.service.model.RequestContextBO in project AuthGuard by AuthGuard.

the class AccountsApiTest method create.

@Test
void create() {
    final CreateAccountRequestDTO requestDTO = CreateAccountRequestDTO.builder().externalId("external").email(AccountEmailDTO.builder().email("email@server.com").build()).domain("main").build();
    final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(UUID.randomUUID().toString()).build();
    final AccountBO accountBO = mapper().toBO(requestDTO);
    final AccountBO serviceResponse = accountBO.withId(UUID.randomUUID().toString());
    Mockito.when(accountsService.create(Mockito.eq(accountBO), Mockito.any())).thenReturn(serviceResponse);
    LOG.info("Request {}", requestDTO);
    final ValidatableResponse httpResponse = given().body(requestDTO).contentType(ContentType.JSON).header(IdempotencyHeader.HEADER_NAME, requestContext.getIdempotentKey()).post(url()).then().statusCode(201).contentType(ContentType.JSON);
    final AccountDTO response = httpResponse.extract().response().getBody().as(AccountDTO.class);
    assertThat(response).isEqualToIgnoringGivenFields(requestDTO, "id", "deleted", "createdAt", "lastModified", "social", "identityProvider");
    assertThat(response.getId()).isEqualTo(serviceResponse.getId());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) ValidatableResponse(io.restassured.response.ValidatableResponse) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) CreateAccountRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO) AccountDTO(com.nexblocks.authguard.api.dto.entities.AccountDTO) Test(org.junit.jupiter.api.Test)

Aggregations

RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)17 Test (org.junit.jupiter.api.Test)9 AccountBO (com.nexblocks.authguard.service.model.AccountBO)6 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)5 AuthRequestDTO (com.nexblocks.authguard.api.dto.requests.AuthRequestDTO)4 CreateAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO)4 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)4 Error (com.nexblocks.authguard.api.dto.entities.Error)3 CreateCompleteAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountRequestDTO)3 CreateCompleteAccountResponseDTO (com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountResponseDTO)3 CreateCredentialsRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO)3 CredentialsBO (com.nexblocks.authguard.service.model.CredentialsBO)3 ValidatableResponse (io.restassured.response.ValidatableResponse)3 AuthResponseDTO (com.nexblocks.authguard.api.dto.entities.AuthResponseDTO)2 ApplicationsService (com.nexblocks.authguard.service.ApplicationsService)2 IdempotencyException (com.nexblocks.authguard.service.exceptions.IdempotencyException)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Claim (com.auth0.jwt.interfaces.Claim)1