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.dynamic.data.mapping.service.test.DDMStructureServiceTest.java

License:Open Source License

@Test
public void testSearchWithSiteAdminPermission() throws Exception {
    DDMStructure structure = addStructure(_classNameId, StringUtil.randomString());

    structure = addStructure(_classNameId, StringUtil.randomString());

    String modelName = ResourceActionsUtil.getCompositeModelName(PortalUtil.getClassName(_classNameId),
            DDMStructure.class.getName());

    List<Role> roles = RoleLocalServiceUtil.getRoles(TestPropsValues.getCompanyId());

    for (Role role : roles) {
        ResourcePermissionServiceUtil.removeResourcePermission(structure.getGroupId(), structure.getCompanyId(),
                modelName, ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(structure.getPrimaryKey()),
                role.getRoleId(), ActionKeys.VIEW);
    }/*  w w  w  . j av a2  s.co m*/

    long[] groupIds = { group.getGroupId(), group.getGroupId() };

    List<DDMStructure> structures = DDMStructureServiceUtil.search(TestPropsValues.getCompanyId(), groupIds,
            _classNameId, StringPool.BLANK, WorkflowConstants.STATUS_ANY, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
            null);

    Assert.assertEquals(structures.toString(), 2, structures.size());
}

From source file:com.liferay.dynamic.data.mapping.service.test.DDMStructureServiceTest.java

License:Open Source License

@Test
public void testSearchWithSiteMemberPermission() throws Exception {
    DDMStructure structure = addStructure(_classNameId, StringUtil.randomString());

    structure = addStructure(_classNameId, StringUtil.randomString());

    String modelName = ResourceActionsUtil.getCompositeModelName(PortalUtil.getClassName(_classNameId),
            DDMStructure.class.getName());

    List<Role> roles = RoleLocalServiceUtil.getRoles(TestPropsValues.getCompanyId());

    for (Role role : roles) {
        ResourcePermissionServiceUtil.removeResourcePermission(structure.getGroupId(), structure.getCompanyId(),
                modelName, ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(structure.getPrimaryKey()),
                role.getRoleId(), ActionKeys.VIEW);
    }/*from w w  w.  j ava 2 s  .  co m*/

    long[] groupIds = { group.getGroupId(), group.getGroupId() };

    User siteMemberUser = UserTestUtil.addGroupUser(group, RoleConstants.SITE_MEMBER);

    PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(siteMemberUser);

    PermissionThreadLocal.setPermissionChecker(permissionChecker);

    List<DDMStructure> structures = DDMStructureServiceUtil.search(TestPropsValues.getCompanyId(), groupIds,
            _classNameId, StringPool.BLANK, WorkflowConstants.STATUS_ANY, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
            null);

    Assert.assertEquals(structures.toString(), 1, structures.size());
}

From source file:com.liferay.expando.taglib.servlet.taglib.CustomAttributesAvailableTag.java

License:Open Source License

@Override
public int doStartTag() throws JspException {
    try {//w w  w .  ja  v a  2  s .co m
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

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

        long companyId = _companyId;

        if (companyId == 0) {
            companyId = themeDisplay.getCompanyId();
        }

        ExpandoBridge expandoBridge = null;

        if (_classPK == 0) {
            expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(companyId, _className);
        } else {
            expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(companyId, _className, _classPK);
        }

        List<String> attributeNames = ListUtil.remove(Collections.list(expandoBridge.getAttributeNames()),
                ListUtil.fromString(_ignoreAttributeNames, StringPool.COMMA));

        if (attributeNames.isEmpty()) {
            return SKIP_BODY;
        }

        if (_classPK == 0) {
            return EVAL_BODY_INCLUDE;
        }

        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

        for (String attributeName : attributeNames) {
            Serializable value = expandoBridge.getAttribute(attributeName);

            if (Validator.isNull(value)) {
                continue;
            }

            UnicodeProperties properties = expandoBridge.getAttributeProperties(attributeName);

            boolean propertyHidden = GetterUtil
                    .getBoolean(properties.get(ExpandoColumnConstants.PROPERTY_HIDDEN));
            boolean propertyVisibleWithUpdatePermission = GetterUtil
                    .getBoolean(properties.get(ExpandoColumnConstants.PROPERTY_VISIBLE_WITH_UPDATE_PERMISSION));

            if (_editable && propertyVisibleWithUpdatePermission) {
                if (ExpandoColumnPermissionUtil.contains(permissionChecker, companyId, _className,
                        ExpandoTableConstants.DEFAULT_TABLE_NAME, attributeName, ActionKeys.UPDATE)) {

                    propertyHidden = false;
                } else {
                    propertyHidden = true;
                }
            }

            if (!propertyHidden && ExpandoColumnPermissionUtil.contains(permissionChecker, companyId,
                    _className, ExpandoTableConstants.DEFAULT_TABLE_NAME, attributeName, ActionKeys.VIEW)) {

                return EVAL_BODY_INCLUDE;
            }
        }

        return SKIP_BODY;
    } catch (Exception e) {
        throw new JspException(e);
    } finally {
        if (!ServerDetector.isResin()) {
            _className = null;
            _classPK = 0;
            _companyId = 0;
            _editable = false;
            _ignoreAttributeNames = null;
        }
    }
}

From source file:com.liferay.exportimport.internal.staging.permission.StagingPermissionImpl.java

License:Open Source License

protected Boolean doHasPermission(PermissionChecker permissionChecker, Group group, String className,
        long classPK, String portletId, String actionId) throws Exception {

    if (!PropsValues.STAGING_LIVE_GROUP_LOCKING_ENABLED) {
        return null;
    }//from www  . j  a v a  2s . c om

    if (!actionId.equals(ActionKeys.ACCESS) && !actionId.equals(ActionKeys.ACCESS_IN_CONTROL_PANEL)
            && !actionId.equals(ActionKeys.ADD_TO_PAGE) && !actionId.equals(ActionKeys.ASSIGN_MEMBERS)
            && !actionId.equals(ActionKeys.CONFIGURATION) && !actionId.equals(ActionKeys.CUSTOMIZE)
            && !actionId.equals(ActionKeys.DELETE) && !actionId.equals(ActionKeys.VIEW)
            && group.hasLocalOrRemoteStagingGroup()
            && (Validator.isNull(portletId) || group.isStagedPortlet(portletId))) {

        return false;
    } else {
        return null;
    }
}

From source file:com.liferay.journal.content.web.internal.display.context.JournalContentDisplayContext.java

License:Open Source License

public boolean hasViewPermission() throws PortalException {
    if (_hasViewPermission != null) {
        return _hasViewPermission;
    }/* w  w  w  . j  a v a 2  s  . c  o m*/

    _hasViewPermission = true;

    JournalArticle article = getArticle();

    if (article != null) {
        ThemeDisplay themeDisplay = (ThemeDisplay) _portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        _hasViewPermission = JournalArticlePermission.contains(themeDisplay.getPermissionChecker(), article,
                ActionKeys.VIEW);
    }

    return _hasViewPermission;
}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

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

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

From source file:com.liferay.journal.search.JournalFolderIndexer.java

License:Open Source License

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

    JournalFolder folder = _journalFolderLocalService.getFolder(entryClassPK);

    return JournalFolderPermission.contains(permissionChecker, folder, ActionKeys.VIEW);
}

From source file:com.liferay.journal.search.JournalOpenSearchImpl.java

License:Open Source License

protected String getLayoutURL(ThemeDisplay themeDisplay, String articleId) throws Exception {

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    List<JournalContentSearch> contentSearches = _journalContentSearchLocalService
            .getArticleContentSearches(articleId);

    for (JournalContentSearch contentSearch : contentSearches) {
        if (LayoutPermissionUtil.contains(permissionChecker, contentSearch.getGroupId(),
                contentSearch.isPrivateLayout(), contentSearch.getLayoutId(), ActionKeys.VIEW)) {

            if (contentSearch.isPrivateLayout()) {
                if (!_groupLocalService.hasUserGroup(themeDisplay.getUserId(), contentSearch.getGroupId())) {

                    continue;
                }//from www  .j a  va2s  .  c o m
            }

            Layout hitLayout = _layoutLocalService.getLayout(contentSearch.getGroupId(),
                    contentSearch.isPrivateLayout(), contentSearch.getLayoutId());

            return _portal.getLayoutURL(hitLayout, themeDisplay);
        }
    }

    return null;
}

From source file:com.liferay.journal.search.JournalOpenSearchImpl.java

License:Open Source License

@Override
protected String getURL(ThemeDisplay themeDisplay, long groupId, Document result, PortletURL portletURL)
        throws Exception {

    String articleId = result.get("articleId");

    JournalArticle article = _journalArticleService.getArticle(groupId, articleId);

    if (Validator.isNotNull(article.getLayoutUuid())) {
        String groupFriendlyURL = _portal.getGroupFriendlyURL(
                _layoutSetLocalService.getLayoutSet(article.getGroupId(), false), themeDisplay);

        return groupFriendlyURL.concat(JournalArticleConstants.CANONICAL_URL_SEPARATOR)
                .concat(article.getUrlTitle());
    }/*from  ww  w.  j  a  v  a 2 s .  c o m*/

    Layout layout = themeDisplay.getLayout();

    List<Long> hitLayoutIds = _journalContentSearchLocalService.getLayoutIds(layout.getGroupId(),
            layout.isPrivateLayout(), articleId);

    for (Long hitLayoutId : hitLayoutIds) {
        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

        if (LayoutPermissionUtil.contains(permissionChecker, layout.getGroupId(), layout.isPrivateLayout(),
                hitLayoutId, ActionKeys.VIEW)) {

            Layout hitLayout = _layoutLocalService.getLayout(layout.getGroupId(), layout.isPrivateLayout(),
                    hitLayoutId.longValue());

            return _portal.getLayoutURL(hitLayout, themeDisplay);
        }
    }

    String layoutURL = getLayoutURL(themeDisplay, articleId);

    if (layoutURL != null) {
        return layoutURL;
    }

    AssetEntry assetEntry = _assetEntryLocalService.fetchEntry(JournalArticle.class.getName(),
            article.getResourcePrimKey());

    if (assetEntry == null) {
        return null;
    }

    portletURL.setParameter("assetEntryId", String.valueOf(assetEntry.getEntryId()));
    portletURL.setParameter("groupId", String.valueOf(groupId));
    portletURL.setParameter("articleId", articleId);

    return portletURL.toString();
}

From source file:com.liferay.journal.service.impl.JournalArticleServiceImpl.java

License:Open Source License

@Override
public JournalArticle fetchArticle(long groupId, String articleId) throws PortalException {

    JournalArticle article = journalArticleLocalService.fetchArticle(groupId, articleId);

    if (article != null) {
        JournalArticlePermission.check(getPermissionChecker(), article, ActionKeys.VIEW);
    }/*w  w w  .  j  a v  a2s.c  om*/

    return article;
}