List of usage examples for com.liferay.portal.kernel.security.auth PrincipalThreadLocal getUserId
public static long getUserId()
From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java
License:Open Source License
@Override public long getGroupIdFromScopeId(String scopeId, long siteGroupId, boolean privateLayout) throws PortalException { if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_CHILD_GROUP_PREFIX.length()); long childGroupId = GetterUtil.getLong(scopeIdSuffix); Group childGroup = _groupLocalService.getGroup(childGroupId); if (!childGroup.hasAncestor(siteGroupId)) { throw new PrincipalException(); }/*from w ww . j av a 2s . co m*/ return childGroupId; } else if (scopeId.startsWith(SCOPE_ID_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_GROUP_PREFIX.length()); if (scopeIdSuffix.equals(GroupConstants.DEFAULT)) { return siteGroupId; } long scopeGroupId = GetterUtil.getLong(scopeIdSuffix); Group scopeGroup = _groupLocalService.getGroup(scopeGroupId); return scopeGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_UUID_PREFIX)) { String layoutUuid = scopeId.substring(SCOPE_ID_LAYOUT_UUID_PREFIX.length()); Layout scopeIdLayout = _layoutLocalService.getLayoutByUuidAndGroupId(layoutUuid, siteGroupId, privateLayout); Group scopeIdGroup = _groupLocalService.checkScopeGroup(scopeIdLayout, PrincipalThreadLocal.getUserId()); return scopeIdGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_PREFIX)) { // Legacy portlet preferences String scopeIdSuffix = scopeId.substring(SCOPE_ID_LAYOUT_PREFIX.length()); long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix); Layout scopeIdLayout = _layoutLocalService.getLayout(siteGroupId, privateLayout, scopeIdLayoutId); Group scopeIdGroup = scopeIdLayout.getScopeGroup(); return scopeIdGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_PARENT_GROUP_PREFIX.length()); long parentGroupId = GetterUtil.getLong(scopeIdSuffix); Group parentGroup = _groupLocalService.getGroup(parentGroupId); if (!SitesUtil.isContentSharingWithChildrenEnabled(parentGroup)) { throw new PrincipalException(); } Group group = _groupLocalService.getGroup(siteGroupId); if (!group.hasAncestor(parentGroupId)) { throw new PrincipalException(); } return parentGroupId; } else { throw new IllegalArgumentException("Invalid scope ID " + scopeId); } }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
public static long getGroupIdFromScopeId(String scopeId, long siteGroupId, boolean privateLayout) throws PortalException { if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_CHILD_GROUP_PREFIX.length()); long childGroupId = GetterUtil.getLong(scopeIdSuffix); Group childGroup = _groupLocalService.getGroup(childGroupId); if (!childGroup.hasAncestor(siteGroupId)) { throw new PrincipalException(); }/* w w w . j ava 2 s . com*/ return childGroupId; } else if (scopeId.startsWith(SCOPE_ID_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_GROUP_PREFIX.length()); if (scopeIdSuffix.equals(GroupConstants.DEFAULT)) { return siteGroupId; } long scopeGroupId = GetterUtil.getLong(scopeIdSuffix); Group scopeGroup = _groupLocalService.getGroup(scopeGroupId); return scopeGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_UUID_PREFIX)) { String layoutUuid = scopeId.substring(SCOPE_ID_LAYOUT_UUID_PREFIX.length()); Layout scopeIdLayout = _layoutLocalService.getLayoutByUuidAndGroupId(layoutUuid, siteGroupId, privateLayout); Group scopeIdGroup = _groupLocalService.checkScopeGroup(scopeIdLayout, PrincipalThreadLocal.getUserId()); return scopeIdGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_PREFIX)) { // Legacy portlet preferences String scopeIdSuffix = scopeId.substring(SCOPE_ID_LAYOUT_PREFIX.length()); long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix); Layout scopeIdLayout = _layoutLocalService.getLayout(siteGroupId, privateLayout, scopeIdLayoutId); Group scopeIdGroup = scopeIdLayout.getScopeGroup(); return scopeIdGroup.getGroupId(); } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) { String scopeIdSuffix = scopeId.substring(SCOPE_ID_PARENT_GROUP_PREFIX.length()); long parentGroupId = GetterUtil.getLong(scopeIdSuffix); Group parentGroup = _groupLocalService.getGroup(parentGroupId); if (!SitesUtil.isContentSharingWithChildrenEnabled(parentGroup)) { throw new PrincipalException(); } Group group = _groupLocalService.getGroup(siteGroupId); if (!group.hasAncestor(parentGroupId)) { throw new PrincipalException(); } return parentGroupId; } else { throw new IllegalArgumentException("Invalid scope ID " + scopeId); } }
From source file:com.liferay.document.library.document.conversion.internal.DocumentHTMLProcessor.java
License:Open Source License
public InputStream process(InputStream inputStream) { File tempFile = null;/* w w w . j a v a2 s . c o m*/ InputStream processedInputStream = null; Scanner scanner = null; String replacement = ""; try { scanner = new Scanner(inputStream); scanner.useDelimiter(">"); tempFile = FileUtil.createTempFile(); long userId = PrincipalThreadLocal.getUserId(); String imageRequestToken = ImageRequestTokenUtil.createToken(userId); while (scanner.hasNext()) { String token = scanner.next(); if (Validator.isNotNull(token)) { token += ">"; replacement = token.replaceAll(_DOCUMENTS_REGEX, "$1&auth_token=" + imageRequestToken + "$3"); replacement = replacement.replaceAll(_IMAGE_REGEX, "$1&auth_token=" + imageRequestToken + "$3"); replacement = replacement.replaceAll(_PORTLET_FILE_ENTRY_REGEX, "$1?auth_token=" + imageRequestToken + "$3"); replacement = replacement.replaceAll(_WIKI_PAGE_ATTACHMENT_REGEX, "$1$3&auth_token=" + imageRequestToken + "$6"); FileUtil.write(tempFile, replacement, true, true); } } processedInputStream = new AutoDeleteFileInputStream(tempFile); } catch (Exception e) { _log.error(e, e); } finally { scanner.close(); } return processedInputStream; }
From source file:com.liferay.document.library.repository.cmis.internal.model.CMISFileEntry.java
License:Open Source License
@Override public InputStream getContentStream() { ContentStream contentStream = _document.getContentStream(); try {//from w ww .j a v a 2 s. co m DLAppHelperLocalServiceUtil.getFileAsStream(PrincipalThreadLocal.getUserId(), this, true); } catch (Exception e) { _log.error(e, e); } return contentStream.getStream(); }
From source file:com.liferay.document.library.repository.cmis.internal.model.CMISFileEntry.java
License:Open Source License
@Override public InputStream getContentStream(String version) throws PortalException { if (Validator.isNull(version)) { return getContentStream(); }/*from www .j ava 2s .c om*/ for (Document document : getAllVersions()) { if (version.equals(document.getVersionLabel())) { ContentStream contentStream = document.getContentStream(); try { DLAppHelperLocalServiceUtil.getFileAsStream(PrincipalThreadLocal.getUserId(), this, true); } catch (Exception e) { _log.error(e, e); } return contentStream.getStream(); } } throw new NoSuchFileVersionException( "No CMIS file version with {fileEntryId=" + getFileEntryId() + ", version=" + version + "}"); }
From source file:com.liferay.document.library.repository.cmis.internal.model.CMISFileVersion.java
License:Open Source License
@Override public InputStream getContentStream(boolean incrementCounter) { ContentStream contentStream = _document.getContentStream(); try {/*from w w w. j av a2s .c om*/ DLAppHelperLocalServiceUtil.getFileAsStream(PrincipalThreadLocal.getUserId(), getFileEntry(), incrementCounter); } catch (Exception e) { _log.error(e); } return contentStream.getStream(); }
From source file:com.liferay.document.library.repository.external.ExtRepositoryAdapter.java
License:Open Source License
private void _checkAssetEntry(ExtRepositoryFileEntryAdapter extRepositoryFileEntryAdapter) throws PortalException { dlAppHelperLocalService.checkAssetEntry(PrincipalThreadLocal.getUserId(), extRepositoryFileEntryAdapter, extRepositoryFileEntryAdapter.getFileVersion()); }
From source file:com.liferay.document.library.repository.external.model.ExtRepositoryFileEntryAdapter.java
License:Open Source License
@Override public boolean hasLock() { if (!isCheckedOut()) { return false; }// w w w.j a v a2s .co m User checkedOutByUser = getUser(_extRepositoryFileEntry.getCheckedOutBy()); if (checkedOutByUser.getUserId() != PrincipalThreadLocal.getUserId()) { return false; } return true; }
From source file:com.liferay.social.activity.service.test.SocialActivityServiceTest.java
License:Open Source License
@Test public void testPagingFilterActivities() throws Exception { for (int i = 0; i < 4; i++) { addFileEntry(RandomTestUtil.randomString() + ".txt", String.valueOf(i)); FileEntry fileEntry = addFileEntry(RandomTestUtil.randomString() + ".txt", RandomTestUtil.randomString()); deleteGuestPermission(fileEntry); }//from w ww. jav a2 s . co m long userId = PrincipalThreadLocal.getUserId(); ServiceTestUtil.setUser(_user); try { Assert.assertEquals(8, SocialActivityServiceUtil.getGroupActivitiesCount(_group.getGroupId())); List<SocialActivity> activities = SocialActivityServiceUtil.getGroupActivities(_group.getGroupId(), 0, 2); Assert.assertEquals(activities.toString(), 2, activities.size()); int index = 3; for (SocialActivity activity : activities) { String title = String.valueOf(index); Assert.assertEquals(title, activity.getExtraDataValue("title")); index--; } activities = SocialActivityServiceUtil.getGroupActivities(_group.getGroupId(), 2, 4); Assert.assertEquals(activities.toString(), 2, activities.size()); for (SocialActivity activity : activities) { String title = String.valueOf(index); Assert.assertEquals(title, activity.getExtraDataValue("title")); index--; } } finally { User user = UserLocalServiceUtil.getUser(userId); ServiceTestUtil.setUser(user); } }