Search in sources :

Example 1 with KeyValuePair

use of com.liferay.portal.kernel.util.KeyValuePair in project liferay-ide by liferay.

the class UserLocalServiceImpl method decryptUserId.

/**
 * Decrypts the user's primary key and password from their encrypted forms.
 * Used for decrypting a user's credentials from the values stored in an
 * automatic login cookie.
 *
 * @param  companyId the primary key of the user's company
 * @param  name the encrypted primary key of the user
 * @param  password the encrypted password of the user
 * @return the user's primary key and password
 * @throws PortalException if a user with the primary key could not be found
 *         or if the user's password was incorrect
 * @throws SystemException if a system exception occurred
 */
@Override
public KeyValuePair decryptUserId(long companyId, String name, String password) throws PortalException, SystemException {
    Company company = companyPersistence.findByPrimaryKey(companyId);
    try {
        name = Encryptor.decrypt(company.getKeyObj(), name);
    } catch (EncryptorException ee) {
        throw new SystemException(ee);
    }
    long userId = GetterUtil.getLong(name);
    User user = userPersistence.findByPrimaryKey(userId);
    try {
        password = Encryptor.decrypt(company.getKeyObj(), password);
    } catch (EncryptorException ee) {
        throw new SystemException(ee);
    }
    String userPassword = user.getPassword();
    String encPassword = PasswordEncryptorUtil.encrypt(password, userPassword);
    if (userPassword.equals(encPassword)) {
        if (isPasswordExpired(user)) {
            user.setPasswordReset(true);
            userPersistence.update(user);
        }
        return new KeyValuePair(name, password);
    } else {
        throw new PrincipalException();
    }
}
Also used : Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User) EncryptorException(com.liferay.util.EncryptorException) SystemException(com.liferay.portal.kernel.exception.SystemException) KeyValuePair(com.liferay.portal.kernel.util.KeyValuePair) PrincipalException(com.liferay.portal.security.auth.PrincipalException)

Aggregations

SystemException (com.liferay.portal.kernel.exception.SystemException)1 KeyValuePair (com.liferay.portal.kernel.util.KeyValuePair)1 Company (com.liferay.portal.model.Company)1 User (com.liferay.portal.model.User)1 PrincipalException (com.liferay.portal.security.auth.PrincipalException)1 EncryptorException (com.liferay.util.EncryptorException)1