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();
}
}
Aggregations