Search in sources :

Example 91 with User

use of com.liferay.portal.model.User 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 92 with User

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

the class UserLocalServiceImpl method addDefaultRoles.

/**
 * Adds the user to the default roles, unless the user already has these
 * roles. The default roles can be specified in
 * <code>portal.properties</code> with the key
 * <code>admin.default.role.names</code>.
 *
 * @param  userId the primary key of the user
 * @throws PortalException if a user with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public void addDefaultRoles(long userId) throws PortalException, SystemException {
    User user = userPersistence.findByPrimaryKey(userId);
    Set<Long> roleIdSet = new HashSet<Long>();
    String[] defaultRoleNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_ROLE_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_ROLE_NAMES);
    for (String defaultRoleName : defaultRoleNames) {
        try {
            Role role = rolePersistence.findByC_N(user.getCompanyId(), defaultRoleName);
            if (!userPersistence.containsRole(userId, role.getRoleId())) {
                roleIdSet.add(role.getRoleId());
            }
        } catch (NoSuchRoleException nsre) {
        }
    }
    long[] roleIds = ArrayUtil.toArray(roleIdSet.toArray(new Long[roleIdSet.size()]));
    roleIds = UsersAdminUtil.addRequiredRoles(user, roleIds);
    userPersistence.addRoles(userId, roleIds);
}
Also used : Role(com.liferay.portal.model.Role) UserGroupRole(com.liferay.portal.model.UserGroupRole) NoSuchRoleException(com.liferay.portal.NoSuchRoleException) User(com.liferay.portal.model.User) HashSet(java.util.HashSet)

Example 93 with User

use of com.liferay.portal.model.User 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 94 with User

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

the class LiferayAppDataService method getCompanyId.

protected long getCompanyId(SecurityToken securityToken) throws Exception {
    long userIdLong = GetterUtil.getLong(securityToken.getViewerId());
    User user = UserLocalServiceUtil.getUser(userIdLong);
    return user.getCompanyId();
}
Also used : User(com.liferay.portal.model.User)

Example 95 with User

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

the class LiferayMediaItemService method doUpdateMediaItem.

protected void doUpdateMediaItem(UserId userId, String appId, String albumId, String mediaItemId, MediaItem mediaItem, SecurityToken securityToken) throws Exception {
    long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
    User user = UserLocalServiceUtil.getUserById(userIdLong);
    if (!ShindigUtil.isValidUser(user)) {
        return;
    }
    Group group = user.getGroup();
    long groupIdLong = group.getGroupId();
    Http.Options options = new Http.Options();
    options.setLocation(mediaItem.getUrl());
    byte[] byteArray = HttpUtil.URLtoByteArray(options);
    String fileName = getFileName(mediaItem, options);
    String contentType = MimeTypesUtil.getContentType(fileName);
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setAttribute("sourceFileName", fileName);
    serviceContext.setExpandoBridgeAttributes(SerializerUtil.toExpandoAttributes(mediaItem, _MEDIA_ITEM_FIELDS, user.getCompanyId(), DLFileEntry.class.getName()));
    serviceContext.setScopeGroupId(groupIdLong);
    if (mediaItemId == null) {
        long albumIdLong = GetterUtil.getLong(albumId);
        DLAppServiceUtil.addFileEntry(groupIdLong, albumIdLong, fileName, contentType, mediaItem.getTitle(), mediaItem.getDescription(), StringPool.BLANK, byteArray, serviceContext);
    } else {
        long mediaItemIdLong = GetterUtil.getLong(mediaItemId);
        FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(mediaItemIdLong);
        serviceContext.setCreateDate(fileEntry.getCreateDate());
        serviceContext.setModifiedDate(fileEntry.getModifiedDate());
        DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), fileName, contentType, mediaItem.getTitle(), mediaItem.getDescription(), StringPool.BLANK, false, byteArray, serviceContext);
    }
}
Also used : Group(com.liferay.portal.model.Group) CollectionOptions(org.apache.shindig.social.opensocial.spi.CollectionOptions) User(com.liferay.portal.model.User) ServiceContext(com.liferay.portal.service.ServiceContext) Http(com.liferay.portal.kernel.util.Http) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Aggregations

User (com.liferay.portal.model.User)97 Date (java.util.Date)22 SystemException (com.liferay.portal.kernel.exception.SystemException)17 Group (com.liferay.portal.model.Group)15 PortalException (com.liferay.portal.kernel.exception.PortalException)13 Company (com.liferay.portal.model.Company)11 ServiceContext (com.liferay.portal.service.ServiceContext)11 Indexable (com.liferay.portal.kernel.search.Indexable)10 UserGroup (com.liferay.portal.model.UserGroup)10 IOException (java.io.IOException)9 DuplicateUserEmailAddressException (com.liferay.portal.DuplicateUserEmailAddressException)8 EncryptorException (com.liferay.util.EncryptorException)7 Song (org.liferay.jukebox.model.Song)7 Contact (com.liferay.portal.model.Contact)6 PrincipalException (com.liferay.portal.security.auth.PrincipalException)6 Album (org.liferay.jukebox.model.Album)6 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)5 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)5 NoSuchImageException (com.liferay.portal.NoSuchImageException)5 NoSuchOrganizationException (com.liferay.portal.NoSuchOrganizationException)5