Search in sources :

Example 1 with Violation

use of com.nexblocks.authguard.api.dto.validation.violations.Violation in project AuthGuard by AuthGuard.

the class CredentialsRoute method addIdentifiers.

public void addIdentifiers(final Context context) {
    final String credentialsId = context.pathParam("id");
    final UserIdentifiersRequestDTO request = userIdentifiersRequestBodyHandler.getValidated(context);
    if (request.getOldIdentifier() != null && request.getIdentifiers().size() != 1) {
        throw new RequestValidationException(Collections.singletonList(new Violation("identifier", ViolationType.EXCEEDS_LENGTH_BOUNDARIES)));
    }
    final List<UserIdentifierBO> identifiers = request.getIdentifiers().stream().map(restMapper::toBO).collect(Collectors.toList());
    if (request.getOldIdentifier() != null) {
        credentialsService.replaceIdentifier(credentialsId, request.getOldIdentifier(), identifiers.get(0)).map(restMapper::toDTO).ifPresentOrElse(context::json, () -> context.status(404));
    } else {
        credentialsService.addIdentifiers(credentialsId, identifiers).map(restMapper::toDTO).ifPresentOrElse(context::json, () -> context.status(404));
    }
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) UserIdentifiersRequestDTO(com.nexblocks.authguard.api.dto.requests.UserIdentifiersRequestDTO) RequestValidationException(com.nexblocks.authguard.rest.exceptions.RequestValidationException)

Example 2 with Violation

use of com.nexblocks.authguard.api.dto.validation.violations.Violation in project AuthGuard by AuthGuard.

the class VerificationRoute method verifyEmail.

public void verifyEmail(final Context context) {
    final String token = context.queryParam("token");
    if (token == null) {
        context.status(400).json(new RequestValidationError(Collections.singletonList(new Violation("token", ViolationType.MISSING_REQUIRED_VALUE))));
    }
    verificationService.verifyEmail(token);
    context.status(200);
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) RequestValidationError(com.nexblocks.authguard.api.dto.entities.RequestValidationError)

Example 3 with Violation

use of com.nexblocks.authguard.api.dto.validation.violations.Violation in project AuthGuard by AuthGuard.

the class OAuthRoute method authorize.

void authorize(final Context context) {
    final String provider = context.queryParam("provider");
    final String state = context.queryParam("state");
    final String code = context.queryParam("code");
    if (provider == null) {
        context.status(400).json(new RequestValidationError(Collections.singletonList(new Violation("provider", ViolationType.MISSING_REQUIRED_VALUE))));
        return;
    }
    if (state == null) {
        context.status(400).json(new RequestValidationError(Collections.singletonList(new Violation("state", ViolationType.MISSING_REQUIRED_VALUE))));
        return;
    }
    if (code == null) {
        context.status(400).json(new RequestValidationError(Collections.singletonList(new Violation("code", ViolationType.MISSING_REQUIRED_VALUE))));
        return;
    }
    context.json(oAuthService.exchangeAuthorizationCode(provider, state, code));
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) RequestValidationError(com.nexblocks.authguard.api.dto.entities.RequestValidationError)

Example 4 with Violation

use of com.nexblocks.authguard.api.dto.validation.violations.Violation in project AuthGuard by AuthGuard.

the class AccountEmailsRequestValidatorTest method validateInvalidEmail.

@Test
void validateInvalidEmail() {
    final AccountEmailsRequestDTO request = AccountEmailsRequestDTO.builder().email(AccountEmailDTO.builder().email("invalid").build()).build();
    final Validator<AccountEmailsRequestDTO> validator = Validators.getForClass(AccountEmailsRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).containsExactly(new Violation("email", ViolationType.INVALID_VALUE));
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) AccountEmailsRequestDTO(com.nexblocks.authguard.api.dto.requests.AccountEmailsRequestDTO) Test(org.junit.jupiter.api.Test)

Example 5 with Violation

use of com.nexblocks.authguard.api.dto.validation.violations.Violation 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();
}
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

Violation (com.nexblocks.authguard.api.dto.validation.violations.Violation)44 Test (org.junit.jupiter.api.Test)40 CreateAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO)6 PasswordResetRequestDTO (com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO)5 UpdateAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.UpdateAccountRequestDTO)5 AuthRequestDTO (com.nexblocks.authguard.api.dto.requests.AuthRequestDTO)4 RequestValidationError (com.nexblocks.authguard.api.dto.entities.RequestValidationError)3 CreateCredentialsRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO)3 PermissionsRequestDTO (com.nexblocks.authguard.api.dto.requests.PermissionsRequestDTO)3 AccountEmailsRequestDTO (com.nexblocks.authguard.api.dto.requests.AccountEmailsRequestDTO)2 CreateAppRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO)2 CreatePermissionRequestDTO (com.nexblocks.authguard.api.dto.requests.CreatePermissionRequestDTO)2 CreateRoleRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateRoleRequestDTO)2 OtpRequestDTO (com.nexblocks.authguard.api.dto.requests.OtpRequestDTO)2 PasswordlessRequestDTO (com.nexblocks.authguard.api.dto.requests.PasswordlessRequestDTO)2 RolesRequestDTO (com.nexblocks.authguard.api.dto.requests.RolesRequestDTO)2 UserIdentifiersRequestDTO (com.nexblocks.authguard.api.dto.requests.UserIdentifiersRequestDTO)1 RequestValidationException (com.nexblocks.authguard.rest.exceptions.RequestValidationException)1