}
public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
ChangePasswordForm f = (ChangePasswordForm) form;
UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(getSessionInfo(request).getUser().getRealm());
if (!udb.supportsPasswordChange()) {
throw new Exception("Changing of passwords is not supported by the underlying user database.");
}
User user = LogonControllerFactory.getInstance().getUser(request);
SessionInfo info = this.getSessionInfo(request);
// Read in all of the confidential user attribute values
Properties confidentialAttributes = new Properties();
UserAttributes userAttributes = (UserAttributes) PropertyClassManager.getInstance().getPropertyClass(UserAttributes.NAME);
for (PropertyDefinition def : userAttributes.getDefinitions()) {
AttributeDefinition attrDef = (AttributeDefinition) def;
if (attrDef.getVisibility() == AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
confidentialAttributes.setProperty(def.getName(), attrDef.getPropertyClass()
.retrieveProperty(new UserAttributeKey(info.getUser(), def.getName())));
}
}
try {
// Change the password
udb.changePassword(user.getPrincipalName(), f.getOldPassword(), f.getNewPassword(), false);
PublicKeyStore publicKeyStore = PublicKeyStore.getInstance();
if ("automatic".equals(Property.getProperty(new SystemConfigKey("security.privateKeyMode")))) {
if (publicKeyStore.isPassphraseValid(user.getPrincipalName(), f.getOldPassword())) {
publicKeyStore.changePrivateKeyPassphrase(user.getPrincipalName(), f.getOldPassword(), f.getNewPassword());
publicKeyStore.removeCachedKeys(user.getPrincipalName());
publicKeyStore.verifyPrivateKey(user.getPrincipalName(), f.getNewPassword().toCharArray());
// Write back all of the confidential user attribute values
for (PropertyDefinition def : userAttributes.getDefinitions()) {
AttributeDefinition attrDef = (AttributeDefinition) def;
if (attrDef.getVisibility() == AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {