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));
}
}
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);
}
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));
}
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));
}
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();
}
Aggregations