use of org.summerb.approaches.validation.ValidationContext in project summerb by skarpushin.
the class UsersServiceFacadeImpl method getUserStatusByEmail.
@Override
public UserStatus getUserStatusByEmail(String email) throws FieldValidationException {
ValidationContext ctx = new ValidationContext();
ctx.validateNotEmpty(email, LoginParams.FN_EMAIL);
ctx.throwIfHasErrors();
// Check if user have record
User user = null;
try {
user = userService.getUserByEmail(email);
} catch (UserNotFoundException nfe) {
return UserStatus.NotExists;
}
// Check if user has ROLE_USER
List<String> permissions = permissionService.findUserPermissionsForSubject(SecurityConstants.DOMAIN, user.getUuid(), null);
if (permissions.contains(SecurityConstants.ROLE_USER)) {
return UserStatus.NormalUser;
}
if (permissions.contains(SecurityConstants.MARKER_AWAITING_ACTIVATION)) {
return UserStatus.AwaitingActivation;
}
return UserStatus.Provisioned;
}
use of org.summerb.approaches.validation.ValidationContext in project summerb by skarpushin.
the class UsersServiceFacadeImpl method validateUserIsEligableForPasswordReset.
protected void validateUserIsEligableForPasswordReset(String email) throws FieldValidationException {
ValidationContext ctx = new ValidationContext();
if (!ctx.validateEmailFormat(email, User.FN_EMAIL)) {
throw new FieldValidationException(ctx.getErrors());
}
// now see if this user exists
UserStatus userStatus = getUserStatusByEmail(email);
if (userStatus == UserStatus.NotExists || userStatus == UserStatus.Provisioned) {
throw new FieldValidationException(new RegistrationRequiredValidationError());
}
// Sanity check
if (userStatus != UserStatus.NormalUser && userStatus != UserStatus.AwaitingActivation) {
throw new RuntimeException("Password Reset scenario is not supported for user whose status is: " + userStatus);
}
}
use of org.summerb.approaches.validation.ValidationContext in project summerb by skarpushin.
the class UsersServiceFacadeImpl method validateRegistration.
protected void validateRegistration(Registration registration) throws FieldValidationException {
ValidationContext ctx = new ValidationContext();
validateDisplayName(registration.getDisplayName(), ctx);
validatePassword(registration.getPassword(), ctx);
ctx.validateEmailFormat(registration.getEmail(), User.FN_EMAIL);
ctx.throwIfHasErrors();
}
use of org.summerb.approaches.validation.ValidationContext in project summerb by skarpushin.
the class UsersServiceFacadeImpl method validatePasswordChangeRequestValid.
protected User validatePasswordChangeRequestValid(String email, PasswordChange passwordChange) throws UserNotFoundException, FieldValidationException {
ValidationContext ctx = new ValidationContext();
ctx.lengthEqOrGreater(passwordChange.getPassword(), 4, LoginParams.FN_PASSWORD);
ctx.equals(passwordChange.getPassword(), SecurityMessageCodes.NEW_PASSWORD, passwordChange.getNewPasswordAgain(), SecurityMessageCodes.NEW_PASSWORD_AGAIN, PasswordChange.FN_NEW_PASSWORD_AGAIN);
User user = null;
if (ctx.hasText(passwordChange.getCurrentPassword(), PasswordChange.FN_CURRENT_PASSWORD)) {
user = userService.getUserByEmail(email);
ctx.isTrue(passwordService.isUserPasswordValid(user.getUuid(), passwordChange.getCurrentPassword()), InvalidPasswordException.ERROR_LOGIN_INVALID_PASSWORD, PasswordChange.FN_CURRENT_PASSWORD);
}
ctx.throwIfHasErrors();
return user;
}
use of org.summerb.approaches.validation.ValidationContext in project summerb by skarpushin.
the class StringTemplateValidationUtilsTest method testValidateStringTemplate_blackbox_expectValidationErrorForWrongExpression.
@Test
public void testValidateStringTemplate_blackbox_expectValidationErrorForWrongExpression() throws Exception {
StringTemplateCompiler stringTemplateCompiler = new StringTemplateCompilerlImpl();
String stringTemplate = "Constant text plus ${vars['4444";
ValidationContext ctx = new ValidationContext();
String fieldToken = "fieldToken";
StringTemplateValidationUtils.validateStringTemplate(stringTemplateCompiler, stringTemplate, ctx, fieldToken);
assertEquals(true, ctx.getHasErrors());
}
Aggregations