Search in sources :

Example 1 with PasswordChanged

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");
    }
}
Also used : User(org.bimserver.models.store.User) PasswordChanged(org.bimserver.models.log.PasswordChanged) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) Authenticator(org.bimserver.Authenticator) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 Authenticator (org.bimserver.Authenticator)1 PostCommitAction (org.bimserver.database.PostCommitAction)1 SConverter (org.bimserver.interfaces.SConverter)1 PasswordChanged (org.bimserver.models.log.PasswordChanged)1 User (org.bimserver.models.store.User)1 UserException (org.bimserver.shared.exceptions.UserException)1