Search in sources :

Example 11 with Company

use of com.liferay.portal.model.Company in project liferay-ide by liferay.

the class WebServerServlet method _getUser.

private static User _getUser(HttpServletRequest request) throws Exception {
    HttpSession session = request.getSession();
    if (PortalSessionThreadLocal.getHttpSession() == null) {
        PortalSessionThreadLocal.setHttpSession(session);
    }
    User user = PortalUtil.getUser(request);
    if (user != null) {
        return user;
    }
    String userIdString = (String) session.getAttribute("j_username");
    String password = (String) session.getAttribute("j_password");
    if ((userIdString != null) && (password != null)) {
        long userId = GetterUtil.getLong(userIdString);
        user = UserLocalServiceUtil.getUser(userId);
    } else {
        long companyId = PortalUtil.getCompanyId(request);
        Company company = CompanyLocalServiceUtil.getCompany(companyId);
        user = company.getDefaultUser();
    }
    return user;
}
Also used : Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User) HttpSession(javax.servlet.http.HttpSession)

Example 12 with Company

use of com.liferay.portal.model.Company 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);
    }
}
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) Transactional(com.liferay.portal.kernel.transaction.Transactional)

Example 13 with Company

use of com.liferay.portal.model.Company in project liferay-ide by liferay.

the class UserLocalServiceImpl method updateAsset.

/**
 * Updates the user's asset with the new asset categories and tag names,
 * removing and adding asset categories and tag names as necessary.
 *
 * @param  userId the primary key of the user
 * @param  user ID the primary key of the user
 * @param  assetCategoryIds the primary key's of the new asset categories
 * @param  assetTagNames the new asset tag names
 * @throws PortalException if a user with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public void updateAsset(long userId, User user, long[] assetCategoryIds, String[] assetTagNames) throws PortalException, SystemException {
    User owner = userPersistence.findByPrimaryKey(userId);
    Company company = companyPersistence.findByPrimaryKey(owner.getCompanyId());
    Group companyGroup = company.getGroup();
    assetEntryLocalService.updateEntry(userId, companyGroup.getGroupId(), user.getCreateDate(), user.getModifiedDate(), User.class.getName(), user.getUserId(), user.getUuid(), 0, assetCategoryIds, assetTagNames, false, null, null, null, null, user.getFullName(), null, null, null, null, 0, 0, null, false);
}
Also used : Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User)

Example 14 with Company

use of com.liferay.portal.model.Company 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;
}
Also used : Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User) EncryptorException(com.liferay.util.EncryptorException) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) ServletException(javax.servlet.ServletException) EncryptorException(com.liferay.util.EncryptorException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 15 with Company

use of com.liferay.portal.model.Company in project liferay-ide by liferay.

the class AddGoogleDocsFileEntryTypeAction method doRun.

protected void doRun(long companyId) throws PortalException, SystemException {
    Company company = CompanyLocalServiceUtil.getCompanyById(companyId);
    if (!hasGoogleDocsFileEntryType(company.getGroupId())) {
        long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
        addGoogleDocsFileEntryType(defaultUserId, company.getGroupId());
    }
}
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