import ims.framework.interfaces.IAppUser; //导入方法依赖的package包/类
public IAppUser changePassword(IAppUser user, String newPassword) throws Exception
{
if(user == null)
throw new Exception("Invalid user and/or password.");
if(user.useExternalAuthentication())
{
throw new ConfigurationException("Change password functionality not supported.");
}
else
{
DomainFactory factory = getDomainFactory();
AppUser domUser = (AppUser)factory.getDomainObject(AppUser.class, user.getUserId());
String currentEncodedPassord = domUser.getEncodedPassword();
domUser.setPassword(Configuration.getHash(newPassword));
domUser.setEncodedPassword(Configuration.encryptPasswordWithCloak(newPassword));
java.util.Date date = domUser.getPwdExpDate();
if (date != null)
{
Calendar cal = Calendar.getInstance();
cal.setTime(new java.util.Date());
cal.add(Calendar.DATE, ConfigFlag.GEN.PASSWD_EXP_INCREMENT.getValue());
domUser.setPwdExpDate(cal.getTime());
}
// WDEV-8894 fix - the current encoded password might be null
// and in this case we won't store it in the history
if(currentEncodedPassord != null && currentEncodedPassord.trim().length() > 0)
{
List prev = domUser.getPreviousPasswords();
if(prev == null)
prev = new ArrayList();
AppUserPasswordVo previousPassword = new AppUserPasswordVo();
previousPassword.setDateTime(new DateTime());
previousPassword.setEncodedPassword(currentEncodedPassord);
prev.add(AppUserPasswordVoAssembler.extractAppUserPassword(factory, previousPassword));
domUser.setPreviousPasswords(prev);
}
factory.save(domUser);
AppUserVo fulluser = AppUserVoAssembler.create(domUser);
user = fulluser;
user.setClearPassword(newPassword);
return user;
}
}