use of com.liferay.portal.model.Company 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.portal.model.Company in project liferay-ide by liferay.
the class UserLocalServiceImpl method updateEmailAddress.
/**
* Updates the user's email address or sends verification email.
*
* @param userId the primary key of the user
* @param password the user's password
* @param emailAddress1 the user's new email address
* @param emailAddress2 the user's new email address confirmation
* @param serviceContext the service context to be applied. Must set the
* portal URL, main path, primary key of the layout, remote address,
* remote host, and agent for the user.
* @return the user
* @throws PortalException if a user with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public User updateEmailAddress(long userId, String password, String emailAddress1, String emailAddress2, ServiceContext serviceContext) throws PortalException, SystemException {
emailAddress1 = StringUtil.toLowerCase(emailAddress1.trim());
emailAddress2 = StringUtil.toLowerCase(emailAddress2.trim());
User user = userPersistence.findByPrimaryKey(userId);
validateEmailAddress(user, emailAddress1, emailAddress2);
Company company = companyPersistence.findByPrimaryKey(user.getCompanyId());
if (!company.isStrangersVerify()) {
setEmailAddress(user, password, user.getFirstName(), user.getMiddleName(), user.getLastName(), emailAddress1);
userPersistence.update(user);
Contact contact = user.getContact();
contact.setEmailAddress(user.getEmailAddress());
contactPersistence.update(contact);
} else {
sendEmailAddressVerification(user, emailAddress1, serviceContext);
}
return user;
}
use of com.liferay.portal.model.Company in project liferay-ide by liferay.
the class UserLocalServiceImpl method completeUserRegistration.
/**
* Completes the user's registration by generating a password and sending
* the confirmation email.
*
* @param user the user
* @param serviceContext the service context to be applied. You can specify
* an unencrypted custom password for the user via attribute
* <code>passwordUnencrypted</code>. You automatically generate a
* password for the user by setting attribute
* <code>autoPassword</code> to <code>true</code>. You can send a
* confirmation email to the user by setting attribute
* <code>sendEmail</code> to <code>true</code>.
* @throws PortalException if a portal exception occurred
* @throws SystemException if a system exception occurred
*/
@Override
public void completeUserRegistration(User user, ServiceContext serviceContext) throws PortalException, SystemException {
boolean autoPassword = ParamUtil.getBoolean(serviceContext, "autoPassword");
String password = (String) serviceContext.getAttribute("passwordUnencrypted");
if (autoPassword) {
if (LDAPSettingsUtil.isPasswordPolicyEnabled(user.getCompanyId())) {
if (_log.isWarnEnabled()) {
StringBundler sb = new StringBundler(4);
sb.append("When LDAP password policy is enabled, it is ");
sb.append("possible that portal generated passwords will ");
sb.append("not match the LDAP policy. Using ");
sb.append("RegExpToolkit to generate new password.");
_log.warn(sb.toString());
}
RegExpToolkit regExpToolkit = new RegExpToolkit();
password = regExpToolkit.generate(null);
} else {
PasswordPolicy passwordPolicy = passwordPolicyLocalService.getPasswordPolicy(user.getCompanyId(), user.getOrganizationIds());
password = PwdToolkitUtil.generate(passwordPolicy);
}
serviceContext.setAttribute("passwordUnencrypted", password);
user.setPassword(PasswordEncryptorUtil.encrypt(password));
user.setPasswordUnencrypted(password);
user.setPasswordEncrypted(true);
user.setPasswordModified(true);
user.setPasswordModifiedDate(new Date());
userPersistence.update(user);
user.setPasswordModified(false);
}
if (user.hasCompanyMx()) {
mailService.addUser(user.getCompanyId(), user.getUserId(), password, user.getFirstName(), user.getMiddleName(), user.getLastName(), user.getEmailAddress());
}
boolean sendEmail = ParamUtil.getBoolean(serviceContext, "sendEmail");
if (sendEmail) {
sendEmail(user, password, serviceContext);
}
Company company = companyPersistence.findByPrimaryKey(user.getCompanyId());
if (company.isStrangersVerify()) {
sendEmailAddressVerification(user, user.getEmailAddress(), serviceContext);
}
}
use of com.liferay.portal.model.Company in project liferay-ide by liferay.
the class LiferayActivityService method getThemeDisplay.
protected ThemeDisplay getThemeDisplay(SecurityToken securityToken) throws Exception {
long userIdLong = GetterUtil.getLong(securityToken.getViewerId());
User user = UserLocalServiceUtil.getUserById(userIdLong);
Company company = CompanyLocalServiceUtil.getCompanyById(user.getCompanyId());
ThemeDisplay themeDisplay = new ThemeDisplay();
themeDisplay.setCompany(company);
themeDisplay.setLocale(user.getLocale());
themeDisplay.setUser(user);
return themeDisplay;
}
use of com.liferay.portal.model.Company in project liferay-ide by liferay.
the class OpenSocialHotDeployMessageListener method onDeploy.
@Override
protected void onDeploy(Message message) throws Exception {
verifyGadgets();
List<Company> companies = CompanyLocalServiceUtil.getCompanies();
for (Company company : companies) {
PortletLocalServiceUtil.addPortletCategory(company.getCompanyId(), _GADGETS_CATEGORY);
}
GadgetLocalServiceUtil.initGadgets();
checkExpando();
Thread currentThread = Thread.currentThread();
ClassLoader classLoader = currentThread.getContextClassLoader();
try {
currentThread.setContextClassLoader(PortletClassLoaderUtil.getClassLoader(ClpSerializer.getServletContextName()));
_guiceServletContextListener.contextInitialized(GuiceServletContextListener.getInitializedServletContextEvent());
} finally {
currentThread.setContextClassLoader(classLoader);
}
}
Aggregations