Search in sources :

Example 1 with PasswordResetRequestDTO

use of com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO in project AuthGuard by AuthGuard.

the class PasswordResetRequestValidatorTest method validateValidByPassword.

@Test
void validateValidByPassword() {
    final PasswordResetRequestDTO request = PasswordResetRequestDTO.builder().byToken(false).identifier("identifier").oldPassword("oldPassword").newPassword("newPassword").domain("main").build();
    final Validator<PasswordResetRequestDTO> validator = Validators.getForClass(PasswordResetRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).isEmpty();
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) PasswordResetRequestDTO(com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO) Test(org.junit.jupiter.api.Test)

Example 2 with PasswordResetRequestDTO

use of com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO in project AuthGuard by AuthGuard.

the class PasswordResetRequestValidatorTest method validateMissingTokenAndNewPassword.

@Test
void validateMissingTokenAndNewPassword() {
    final PasswordResetRequestDTO request = PasswordResetRequestDTO.builder().byToken(true).build();
    final Validator<PasswordResetRequestDTO> validator = Validators.getForClass(PasswordResetRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).contains(new Violation("resetToken", ViolationType.MISSING_REQUIRED_VALUE));
    assertThat(violations).contains(new Violation("newPassword", ViolationType.MISSING_REQUIRED_VALUE));
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) PasswordResetRequestDTO(com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO) Test(org.junit.jupiter.api.Test)

Example 3 with PasswordResetRequestDTO

use of com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO in project AuthGuard by AuthGuard.

the class PasswordResetRequestValidatorTest method validateValidByToken.

@Test
void validateValidByToken() {
    final PasswordResetRequestDTO request = PasswordResetRequestDTO.builder().byToken(true).resetToken("token").newPassword("newPassword").build();
    final Validator<PasswordResetRequestDTO> validator = Validators.getForClass(PasswordResetRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).isEmpty();
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) PasswordResetRequestDTO(com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO) Test(org.junit.jupiter.api.Test)

Example 4 with PasswordResetRequestDTO

use of com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO in project AuthGuard by AuthGuard.

the class PasswordResetRequestValidatorTest method validateMissingIdentifierAndOldPassword.

@Test
void validateMissingIdentifierAndOldPassword() {
    final PasswordResetRequestDTO request = PasswordResetRequestDTO.builder().byToken(false).build();
    final Validator<PasswordResetRequestDTO> validator = Validators.getForClass(PasswordResetRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).contains(new Violation("identifier", ViolationType.MISSING_REQUIRED_VALUE));
    assertThat(violations).contains(new Violation("oldPassword", ViolationType.MISSING_REQUIRED_VALUE));
    assertThat(violations).contains(new Violation("newPassword", ViolationType.MISSING_REQUIRED_VALUE));
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) PasswordResetRequestDTO(com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO) Test(org.junit.jupiter.api.Test)

Example 5 with PasswordResetRequestDTO

use of com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO in project AuthGuard by AuthGuard.

the class CredentialsRoute method resetPassword.

@Override
public void resetPassword(final Context context) {
    final PasswordResetRequestDTO request = passwordResetRequestBodyHandler.getValidated(context);
    if (request.getIdentifier() != null && !ActorDomainVerifier.verifyActorDomain(context, request.getDomain())) {
        return;
    }
    final Optional<CredentialsBO> updated;
    if (request.isByToken()) {
        updated = credentialsService.resetPasswordByToken(request.getResetToken(), request.getNewPassword());
    } else {
        updated = credentialsService.replacePassword(request.getIdentifier(), request.getOldPassword(), request.getNewPassword(), request.getDomain());
    }
    if (updated.isPresent()) {
        context.status(200).json(updated.get());
    } else {
        context.status(404);
    }
}
Also used : PasswordResetRequestDTO(com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO)

Aggregations

PasswordResetRequestDTO (com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO)6 Violation (com.nexblocks.authguard.api.dto.validation.violations.Violation)5 Test (org.junit.jupiter.api.Test)5