Example usage for com.liferay.portal.kernel.security.permission ActionKeys VIEW

List of usage examples for com.liferay.portal.kernel.security.permission ActionKeys VIEW

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.security.permission ActionKeys VIEW.

Prototype

String VIEW

To view the source code for com.liferay.portal.kernel.security.permission ActionKeys VIEW.

Click Source Link

Usage

From source file:com.liferay.asset.categories.internal.search.AssetVocabularyIndexer.java

License:Open Source License

@Override
public boolean hasPermission(PermissionChecker permissionChecker, String entryClassName, long entryClassPK,
        String actionId) throws Exception {

    AssetVocabulary vocabulary = _assetVocabularyLocalService.getVocabulary(entryClassPK);

    return AssetVocabularyPermission.contains(permissionChecker, vocabulary, ActionKeys.VIEW);
}

From source file:com.liferay.asset.category.property.service.impl.AssetCategoryPropertyServiceImpl.java

License:Open Source License

@Override
public List<AssetCategoryProperty> getCategoryProperties(long entryId) {
    try {/*from  w ww  .j  av a2 s.c om*/
        if (AssetCategoryPermission.contains(getPermissionChecker(), entryId, ActionKeys.VIEW)) {

            return assetCategoryPropertyLocalService.getCategoryProperties(entryId);
        }
    } catch (PortalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug("Unable to get asset category property for asset entry " + entryId, pe);
        }
    }

    return new ArrayList<>();
}

From source file:com.liferay.asset.category.property.service.impl.AssetCategoryPropertyServiceImpl.java

License:Open Source License

protected List<AssetCategoryProperty> filterAssetCategoryProperties(
        List<AssetCategoryProperty> assetCategoryProperties) {

    List<AssetCategoryProperty> filteredAssetCategoryProperties = new ArrayList<>(
            assetCategoryProperties.size());

    for (AssetCategoryProperty assetCategoryProperty : assetCategoryProperties) {

        try {// w ww .  j ava2  s .  c o m
            if (AssetCategoryPermission.contains(getPermissionChecker(), assetCategoryProperty.getCategoryId(),
                    ActionKeys.VIEW)) {

                filteredAssetCategoryProperties.add(assetCategoryProperty);
            }
        } catch (PortalException pe) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(pe, pe);
            }
        }
    }

    return filteredAssetCategoryProperties;
}

From source file:com.liferay.asset.internal.util.AssetServiceUtil.java

License:Open Source License

public static long[] filterCategoryIds(PermissionChecker permissionChecker, long[] categoryIds)
        throws PortalException {

    List<Long> viewableCategoryIds = new ArrayList<>();

    for (long categoryId : categoryIds) {
        AssetCategory category = AssetCategoryLocalServiceUtil.fetchCategory(categoryId);

        if ((category != null)
                && AssetCategoryPermission.contains(permissionChecker, category, ActionKeys.VIEW)) {

            viewableCategoryIds.add(categoryId);
        }// ww w . j  a  v a  2s .  c o  m
    }

    return ArrayUtil.toArray(viewableCategoryIds.toArray(new Long[viewableCategoryIds.size()]));
}

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

public void setLayoutAssetEntry(AssetEntry assetEntry) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    String defaultAssetPublisherPortletId = _assetPublisherWebUtil
            .getDefaultAssetPublisherId(themeDisplay.getLayout());

    if (isDefaultAssetPublisher() || Validator.isNull(defaultAssetPublisherPortletId)
            || !PortletPermissionUtil.contains(themeDisplay.getPermissionChecker(), themeDisplay.getLayout(),
                    defaultAssetPublisherPortletId, ActionKeys.VIEW)) {

        _request.setAttribute(WebKeys.LAYOUT_ASSET_ENTRY, assetEntry);
    }//from   w  w w  . ja v a  2s  .c  o  m
}

From source file:com.liferay.asset.publisher.web.internal.messaging.AssetEntriesCheckerUtil.java

License:Open Source License

private static List<AssetEntry> _filterAssetEntries(long userId, List<AssetEntry> assetEntries) {

    User user = _userLocalService.fetchUser(userId);

    if (user == null) {
        return Collections.emptyList();
    }/*  w  w w  .  j a  v a2s.c o m*/

    PermissionChecker permissionChecker = null;

    try {
        permissionChecker = PermissionCheckerFactoryUtil.create(user);
    } catch (Exception e) {
        return Collections.emptyList();
    }

    List<AssetEntry> filteredAssetEntries = new ArrayList<>();

    for (AssetEntry assetEntry : assetEntries) {
        try {
            if (AssetEntryPermission.contains(permissionChecker, assetEntry, ActionKeys.VIEW)) {

                filteredAssetEntries.add(assetEntry);
            }
        } catch (Exception e) {
            continue;
        }
    }

    return filteredAssetEntries;
}

From source file:com.liferay.asset.search.test.AssetSearcherStagingTest.java

License:Open Source License

@Test
public void testSiteRolePermissions() throws Exception {
    Role role = addRole(RoleConstants.TYPE_SITE);

    String className = "com.liferay.journal.model.JournalArticle";

    RoleTestUtil.addResourcePermission(role, className, ResourceConstants.SCOPE_GROUP_TEMPLATE, "0",
            ActionKeys.VIEW);

    User user = addUser();/*from ww w .  j av a2 s .co  m*/

    ServiceTestUtil.setUser(user);

    addUserGroupRole(user, role);

    addJournalArticle();

    GroupTestUtil.enableLocalStaging(_group);

    SearchContext searchContext = getSearchContext();

    Group stagingGroup = _group.getStagingGroup();

    searchContext.setGroupIds(new long[] { stagingGroup.getGroupId() });

    searchContext.setUserId(user.getUserId());

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.addSelectedFieldNames(Field.GROUP_ID, Field.STAGING_GROUP);

    AssetEntryQuery assetEntryQuery = getAssetEntryQuery(className);

    Hits hits = search(assetEntryQuery, searchContext);

    Document[] documents = hits.getDocs();

    DocumentsAssert.assertCount(hits.toString(), documents, Field.COMPANY_ID, 1);

    Document document = documents[0];

    assertField(document, Field.GROUP_ID, String.valueOf(stagingGroup.getGroupId()));
    assertField(document, Field.STAGING_GROUP, StringPool.TRUE);
}

From source file:com.liferay.blogs.internal.search.BlogsEntryIndexer.java

License:Open Source License

@Override
public boolean hasPermission(PermissionChecker permissionChecker, String entryClassName, long entryClassPK,
        String actionId) throws Exception {

    return BlogsEntryPermission.contains(permissionChecker, entryClassPK, ActionKeys.VIEW);
}

From source file:com.liferay.blogs.service.impl.BlogsEntryServiceImpl.java

License:Open Source License

@Override
public List<BlogsEntry> getCompanyEntries(long companyId, Date displayDate, int status, int max)
        throws PortalException {

    List<BlogsEntry> entries = new ArrayList<>();

    boolean listNotExhausted = true;

    QueryDefinition<BlogsEntry> queryDefinition = new QueryDefinition<>(status, false, 0, 0,
            new EntryDisplayDateComparator());

    if (status == WorkflowConstants.STATUS_ANY) {
        queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH, true);
    }//w w w.  j a v  a  2s .c  o m

    while ((entries.size() < max) && listNotExhausted) {
        queryDefinition.setEnd(queryDefinition.getStart() + max);

        List<BlogsEntry> entryList = blogsEntryLocalService.getCompanyEntries(companyId, displayDate,
                queryDefinition);

        queryDefinition.setStart(queryDefinition.getStart() + max);

        listNotExhausted = (entryList.size() == max);

        for (BlogsEntry entry : entryList) {
            if (entries.size() >= max) {
                break;
            }

            if (BlogsEntryPermission.contains(getPermissionChecker(), entry, ActionKeys.VIEW)) {

                entries.add(entry);
            }
        }
    }

    return entries;
}

From source file:com.liferay.blogs.service.impl.BlogsEntryServiceImpl.java

License:Open Source License

@Override
public BlogsEntry getEntry(long entryId) throws PortalException {
    BlogsEntryPermission.check(getPermissionChecker(), entryId, ActionKeys.VIEW);

    return blogsEntryLocalService.getEntry(entryId);
}