use of com.liferay.util.EncryptorException 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();
}
}
use of com.liferay.util.EncryptorException in project liferay-ide by liferay.
the class UserLocalServiceImpl method encryptUserId.
/**
* Encrypts the primary key of the user. Used when encrypting the user's
* credentials for storage in an automatic login cookie.
*
* @param name the primary key of the user
* @return the user's encrypted primary key
* @throws PortalException if a user with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public String encryptUserId(String name) throws PortalException, SystemException {
long userId = GetterUtil.getLong(name);
User user = userPersistence.findByPrimaryKey(userId);
Company company = companyPersistence.findByPrimaryKey(user.getCompanyId());
try {
return Encryptor.encrypt(company.getKeyObj(), name);
} catch (EncryptorException ee) {
throw new SystemException(ee);
}
}
use of com.liferay.util.EncryptorException in project liferay-ide by liferay.
the class ShindigFilter method setPermissionChecker.
protected boolean setPermissionChecker(ServletRequest servletRequest) {
String companyIdString = CookieKeys.getCookie((HttpServletRequest) servletRequest, CookieKeys.COMPANY_ID);
if (Validator.isNull(companyIdString)) {
return false;
}
long companyId = GetterUtil.getLong(companyIdString);
String userUUID = StringPool.BLANK;
try {
Company company = CompanyLocalServiceUtil.fetchCompany(companyId);
if (company == null) {
return false;
}
String userUUIDString = CookieKeys.getCookie((HttpServletRequest) servletRequest, CookieKeys.USER_UUID);
if (Validator.isNull(userUUIDString)) {
return false;
}
userUUID = GetterUtil.getString(Encryptor.decrypt(company.getKeyObj(), userUUIDString));
} catch (EncryptorException ee) {
return false;
} catch (Exception e) {
_log.error(e, e);
return false;
}
if (!AuthenticatedUserUUIDStoreUtil.exists(userUUID)) {
return false;
}
String userIdString = userUUID.substring(0, userUUID.indexOf(StringPool.PERIOD));
long userId = GetterUtil.getLong(userIdString);
try {
User user = UserLocalServiceUtil.getUserById(userId);
PrincipalThreadLocal.setName(userIdString);
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
} catch (Exception e) {
_log.error(e, e);
return false;
}
return true;
}
Aggregations