use of org.summerb.validation.FieldValidationException in project summerb by skarpushin.
the class AuthTokenServiceImpl method updateToken.
@Override
@Transactional(rollbackFor = Throwable.class)
public void updateToken(String authTokenUuid, long lastVerifiedAt, String newTokenValue) throws AuthTokenNotFoundException, FieldValidationException {
Preconditions.checkArgument(authTokenUuid != null);
Preconditions.checkArgument(StringUtils.hasText(newTokenValue), "TokenValue is mandatory");
try {
// First - check token itself
AuthToken authToken = getAuthTokenByUuid(authTokenUuid);
if (newTokenValue.equals(authToken.getTokenValue())) {
throw new FieldValidationException(new ValidationError("validation.newValueExpected", "newTokenValue"));
}
// Now we need to update time when token was checked
authTokenDao.updateToken(authTokenUuid, lastVerifiedAt, newTokenValue);
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
Throwables.throwIfInstanceOf(t, AuthTokenNotFoundException.class);
String msg = String.format("Failed to update token '%s'", authTokenUuid);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.validation.FieldValidationException in project summerb by skarpushin.
the class UserDetailsServiceDefaultImpl method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String userEmail) throws UsernameNotFoundException {
try {
User user = userService.getUserByEmail(userEmail);
List<String> permissions = permissionService.findUserPermissionsForSubject(SecurityConstants.DOMAIN, user.getUuid(), null);
AuthToken authToken = null;
UserDetailsImpl ret = new UserDetailsImpl(user, null, permissions, authToken);
return ret;
} catch (UserNotFoundException e) {
throw new UsernameNotFoundException("User not found", e);
} catch (FieldValidationException e) {
throw new UsernameNotFoundException("Email provided in invalid format", e);
} catch (Throwable t) {
throw new UsernameNotFoundException("Failed to get user by email", t);
}
}
use of org.summerb.validation.FieldValidationException in project summerb by skarpushin.
the class LoginController method processRegisterForm.
@RequestMapping(method = RequestMethod.POST, value = SecurityActionsUrlsProviderDefaultImpl.REGISTER)
public String processRegisterForm(@ModelAttribute(ATTR_REGISTRATION) Registration registration, Model model, HttpServletRequest request) {
if (!isAutoTestMode) {
CaptchaController.assertCaptchaTokenValid("register", registration.getCaptcha(), request);
}
try {
// Create user
User user = usersServiceFacade.registerUser(registration);
model.addAttribute(ATTR_REGISTERED, true);
if (isDevMode) {
String activationAbsoluteLink = absoluteUrlBuilder.buildExternalUrl(securityActionsUrlsProvider.buildRegistrationActivationPath(user, null));
model.addAttribute(UserAccountChangeHadlersDefaultImpl.ATTR_ACTIVATION_LINK, activationAbsoluteLink);
}
} catch (FieldValidationException fve) {
model.addAttribute(ControllerBase.ATTR_VALIDATION_ERRORS, new ValidationErrorsVm(fve.getErrors()));
}
return views.registerForm();
}
use of org.summerb.validation.FieldValidationException in project summerb by skarpushin.
the class LoginController method processPasswordChangeForm.
@Secured({ "ROLE_USER" })
@RequestMapping(method = RequestMethod.POST, value = SecurityActionsUrlsProviderDefaultImpl.CHANGE_PASSWORD)
public String processPasswordChangeForm(@ModelAttribute(ATTR_PASSWORD_CHANGE) PasswordChange passwordChange, Model model, HttpServletRequest request) throws UserNotFoundException {
try {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
usersServiceFacade.changePassword(auth.getName(), passwordChange);
model.addAttribute(ATTR_PASSWORD_CHANGED, true);
} catch (FieldValidationException fve) {
model.addAttribute(ControllerBase.ATTR_VALIDATION_ERRORS, new ValidationErrorsVm(fve.getErrors()));
}
return views.changePassword();
}
use of org.summerb.validation.FieldValidationException in project summerb by skarpushin.
the class ExceptionTranslatorFveImpl method buildUserMessage.
@Override
public String buildUserMessage(Throwable t, Locale locale) {
if (!FieldValidationException.class.equals(t.getClass())) {
return null;
}
FieldValidationException fve = (FieldValidationException) t;
StringBuilder ret = new StringBuilder();
ret.append(I18nUtils.buildMessage(fve, messageSource, locale));
ret.append(": ");
boolean first = true;
for (ValidationError ve : fve.getErrors()) {
if (!first) {
ret.append(", ");
}
ret.append(translateFieldName(ve.getFieldToken(), messageSource, locale));
ret.append(" - ");
ret.append(I18nUtils.buildMessage(ve, messageSource, locale));
first = false;
}
return ret.toString();
}
Aggregations