Search in sources :

Example 1 with Company

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

Example 2 with Company

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;
}
Also used : Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User) Contact(com.liferay.portal.model.Contact)

Example 3 with Company

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);
    }
}
Also used : Company(com.liferay.portal.model.Company) PasswordPolicy(com.liferay.portal.model.PasswordPolicy) RegExpToolkit(com.liferay.portal.security.pwd.RegExpToolkit) StringBundler(com.liferay.portal.kernel.util.StringBundler) Date(java.util.Date)

Example 4 with Company

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;
}
Also used : Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 5 with Company

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);
    }
}
Also used : Company(com.liferay.portal.model.Company)

Aggregations

Company (com.liferay.portal.model.Company)15 User (com.liferay.portal.model.User)11 Group (com.liferay.portal.model.Group)4 UserGroup (com.liferay.portal.model.UserGroup)4 EncryptorException (com.liferay.util.EncryptorException)4 Date (java.util.Date)4 SystemException (com.liferay.portal.kernel.exception.SystemException)3 Contact (com.liferay.portal.model.Contact)3 PasswordPolicy (com.liferay.portal.model.PasswordPolicy)3 CompanyMaxUsersException (com.liferay.portal.CompanyMaxUsersException)2 DuplicateUserEmailAddressException (com.liferay.portal.DuplicateUserEmailAddressException)2 ReservedUserEmailAddressException (com.liferay.portal.ReservedUserEmailAddressException)2 UserEmailAddressException (com.liferay.portal.UserEmailAddressException)2 EmailAddressGenerator (com.liferay.portal.security.auth.EmailAddressGenerator)2 IOException (java.io.IOException)2 ContactBirthdayException (com.liferay.portal.ContactBirthdayException)1 ContactFirstNameException (com.liferay.portal.ContactFirstNameException)1 ContactFullNameException (com.liferay.portal.ContactFullNameException)1 ContactLastNameException (com.liferay.portal.ContactLastNameException)1 DuplicateOpenIdException (com.liferay.portal.DuplicateOpenIdException)1