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