Search in sources :

Example 1 with Password

use of org.summerb.users.impl.dom.Password in project summerb by skarpushin.

the class PasswordFactory method createExistentUserPassword.

public static Password createExistentUserPassword() {
    Password ret = new Password();
    ret.setUserUuid(UserFactory.EXISTENT_USER);
    ret.setPasswordHash(RIGHT_PASSWORD_FOR_EXISTENT_USER_HASH);
    ret.setRestorationToken(TOKEN_FOR_EXISTENT_USER);
    return ret;
}
Also used : Password(org.summerb.users.impl.dom.Password)

Example 2 with Password

use of org.summerb.users.impl.dom.Password in project summerb by skarpushin.

the class PasswordServiceImpl method isRestorationTokenValid.

@Override
public boolean isRestorationTokenValid(String userUuid, String restorationTokenUuid) throws UserNotFoundException {
    Preconditions.checkArgument(userUuid != null);
    Preconditions.checkArgument(restorationTokenUuid != null);
    assertUserExists(userUuid);
    try {
        Password password = passwordDao.findPasswordByUserUuid(userUuid);
        if (password == null || !restorationTokenUuid.equals(password.getRestorationToken())) {
            return false;
        }
    } catch (Throwable t) {
        String msg = String.format("Failed to check user '%s' restoration token validity", userUuid);
        throw new UserServiceUnexpectedException(msg, t);
    }
    return true;
}
Also used : UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) Password(org.summerb.users.impl.dom.Password)

Example 3 with Password

use of org.summerb.users.impl.dom.Password in project summerb by skarpushin.

the class PasswordDaoImpl method updateUserPassword.

@Override
public int updateUserPassword(String userUuid, String newPasswordHash) {
    Password pwd = new Password();
    pwd.setUserUuid(userUuid);
    pwd.setPasswordHash(newPasswordHash);
    pwd.setRestorationToken(null);
    BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(pwd);
    return jdbc.update(sqlPutPassword, params);
}
Also used : BeanPropertySqlParameterSource(org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource) Password(org.summerb.users.impl.dom.Password)

Example 4 with Password

use of org.summerb.users.impl.dom.Password in project summerb by skarpushin.

the class PasswordServiceImpl method isUserPasswordValid.

@Override
public boolean isUserPasswordValid(String userUuid, String passwordPlain) throws UserNotFoundException {
    Preconditions.checkArgument(userUuid != null);
    Preconditions.checkArgument(passwordPlain != null);
    assertUserExists(userUuid);
    try {
        Password password = passwordDao.findPasswordByUserUuid(userUuid);
        if (password == null) {
            return false;
        }
        if (!isPasswordMatch(passwordPlain, password.getPasswordHash())) {
            return false;
        }
    } catch (Throwable t) {
        String msg = String.format("Failed to validate user '%s' password", userUuid);
        throw new UserServiceUnexpectedException(msg, t);
    }
    return true;
}
Also used : UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) Password(org.summerb.users.impl.dom.Password)

Aggregations

Password (org.summerb.users.impl.dom.Password)4 UserServiceUnexpectedException (org.summerb.users.api.exceptions.UserServiceUnexpectedException)2 BeanPropertySqlParameterSource (org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource)1