use of org.bimserver.models.log.PasswordChanged in project BIMserver by opensourceBIM.
the class ChangePasswordDatabaseAction method changePassword.
private boolean changePassword(DatabaseSession databaseSession, User actingUser, boolean skipCheck) throws BimserverLockConflictException, BimserverDatabaseException, UserException {
User user = getUserByUoid(uoid);
Authenticator authenticator = new Authenticator();
if (skipCheck || authenticator.validate(oldPassword, user.getPasswordHash(), user.getPasswordSalt())) {
byte[] salt = new byte[32];
new java.security.SecureRandom().nextBytes(salt);
user.setPasswordHash(authenticator.createHash(newPassword, salt));
user.setPasswordSalt(salt);
final PasswordChanged passwordchanged = databaseSession.create(PasswordChanged.class);
passwordchanged.setAccessMethod(getAccessMethod());
passwordchanged.setDate(new Date());
passwordchanged.setExecutor(actingUser);
passwordchanged.setUser(user);
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(passwordchanged));
}
});
databaseSession.store(user);
return true;
} else {
throw new UserException("Old password does not match user's password");
}
}
Aggregations