return User.class.equals(clazz);
}
@Override
public void validate(Object target, Errors errors) {
User user = (User) target;
if (!user.getHasGlobalGroupAccess() || user.getGlobalRole() == null ||
user.getGlobalRole().getId() == null || user.getGlobalRole().getId() == null ||
user.getGlobalRole().getId() == 0 ||
roleService == null ||
roleService.loadRole(user.getGlobalRole().getId()) == null) {
user.setGlobalRole(null);
} else {
user.setGlobalRole(roleService.loadRole(user.getGlobalRole().getId()));
}
if (isEmptyOrWhitespace(user.getName())) {
errors.rejectValue("name", MessageConstants.ERROR_REQUIRED, new String[] { "Name" }, null);
} else if (user.getName() != null && user.getName().length() > 25) {
errors.rejectValue("name", null, "Name has a maximum length of 25.");
}
// Validate password
if (!user.getIsLdapUser()) {
if (user.isNew()) {
if (isEmptyOrWhitespace(user.getUnencryptedPassword())) {
errors.rejectValue("password", MessageConstants.ERROR_REQUIRED, new String[] { "Password" }, "");
}
}
if(errors.getFieldError("password") == null &&
user.getWasLdap() &&
user.getUnencryptedPassword().length() < 12){
errors.rejectValue("password", null, "Password has a minimum length of 12.");
}
if (errors.getFieldError("password") == null && user.getUnencryptedPassword() != null &&
user.getUnencryptedPassword().length() < 12 &&
user.getUnencryptedPassword().length() != 0) {
errors.rejectValue("password", null, "Password has a minimum length of 12.");
}
// Confirm password
if (errors.getFieldError("password") == null) {
if (!isEmptyOrWhitespace(user.getUnencryptedPassword())
|| !isEmptyOrWhitespace(user.getPasswordConfirm())) {
if (isEmptyOrWhitespace(user.getUnencryptedPassword())) {
errors.rejectValue("password", null, "Passwords do not match.");
} else if (isEmptyOrWhitespace(user.getPasswordConfirm())) {
errors.rejectValue("password", null, "Passwords do not match.");
} else if (!user.getUnencryptedPassword().equals(user.getPasswordConfirm())) {
errors.rejectValue("password", null, "Passwords do not match.");
}
}
}
}