public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
try {
User user = LogonControllerFactory.getInstance().getUser(request);
UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(user.getRealm());
if (getOldPassword().length() == 0) {
throw new FieldValidationException("noOldPassword");
}
if (getOldPassword().equals(getNewPassword())) {
throw new FieldValidationException("newAndOldPasswordMatch");
}
if (!getNewPassword().equals(getConfirmPassword())) {
throw new FieldValidationException("newAndConfirmPasswordsDontMatch");
}
if (getNewPassword().length() == 0) {
throw new FieldValidationException("noNewPassword");
}
if (!udb.checkPassword(user.getPrincipalName(), getOldPassword())) {
throw new FieldValidationException("oldPasswordIncorrect");
} else {
// Check that the password matches the current policy, if not
// then request a new one
try {
String pattern = Property.getProperty(new RealmKey("security.password.pattern", user.getRealm().getResourceId()));
Pattern p = Pattern.compile(pattern);
if (!p.matcher(newPassword).matches()) {
throw new FieldValidationException("doesNotMatchPolicy");
}
} catch(FieldValidationException fve) {