Example usage for com.liferay.portal.kernel.theme ThemeDisplay getPermissionChecker

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getPermissionChecker

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getPermissionChecker.

Prototype

@JSON(include = false)
public PermissionChecker getPermissionChecker() 

Source Link

Document

Returns the permission checker, which is used to ensure users making resource requests have the necessary access permissions.

Usage

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. j a  va  2s. 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.staging.StagingImpl.java

License:Open Source License

/**
 * @deprecated As of 4.0.0, replaced by {@link
 *             com.liferay.staging.configuration.web.internal.portlet.StagingConfigurationPortlet#editStagingConfiguration(
 *             javax.portlet.ActionRequest, javax.portlet.ActionResponse)}
 *///www .j  ava2 s  .  c o  m
@Deprecated
@Override
public void updateStaging(PortletRequest portletRequest, Group liveGroup) throws PortalException {

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

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    long userId = permissionChecker.getUserId();

    if (!GroupPermissionUtil.contains(permissionChecker, liveGroup, ActionKeys.MANAGE_STAGING)) {

        return;
    }

    int stagingType = getStagingType(portletRequest, liveGroup);

    boolean branchingPublic = getBoolean(portletRequest, liveGroup, "branchingPublic");
    boolean branchingPrivate = getBoolean(portletRequest, liveGroup, "branchingPrivate");
    boolean forceDisable = ParamUtil.getBoolean(portletRequest, "forceDisable");

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    serviceContext.setAttribute("forceDisable", forceDisable);

    if (stagingType == StagingConstants.TYPE_NOT_STAGED) {
        if (liveGroup.hasStagingGroup() || liveGroup.isStagedRemotely()) {
            _stagingLocalService.disableStaging(portletRequest, liveGroup, serviceContext);
        }
    } else if (stagingType == StagingConstants.TYPE_LOCAL_STAGING) {
        _stagingLocalService.enableLocalStaging(userId, liveGroup, branchingPublic, branchingPrivate,
                serviceContext);
    } else if (stagingType == StagingConstants.TYPE_REMOTE_STAGING) {
        String remoteAddress = getString(portletRequest, liveGroup, "remoteAddress");

        remoteAddress = stripProtocolFromRemoteAddress(remoteAddress);

        int remotePort = getInteger(portletRequest, liveGroup, "remotePort");
        String remotePathContext = getString(portletRequest, liveGroup, "remotePathContext");
        boolean secureConnection = getBoolean(portletRequest, liveGroup, "secureConnection");
        long remoteGroupId = getLong(portletRequest, liveGroup, "remoteGroupId");

        _stagingLocalService.enableRemoteStaging(userId, liveGroup, branchingPublic, branchingPrivate,
                remoteAddress, remotePort, remotePathContext, secureConnection, remoteGroupId, serviceContext);
    }
}

From source file:com.liferay.exportimport.web.internal.portlet.action.ActionUtil.java

License:Open Source License

public static Portlet getPortlet(PortletRequest portletRequest) throws Exception {

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

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    String portletId = ParamUtil.getString(portletRequest, "portletResource");

    Layout layout = PortletConfigurationLayoutUtil.getLayout(themeDisplay);

    if (!PortletPermissionUtil.contains(permissionChecker, themeDisplay.getScopeGroupId(), layout, portletId,
            ActionKeys.CONFIGURATION)) {

        throw new PrincipalException.MustHavePermission(permissionChecker, Portlet.class.getName(), portletId,
                ActionKeys.CONFIGURATION);
    }/*from www . jav  a 2  s  . c o  m*/

    return PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId);
}

From source file:com.liferay.exportimport.web.internal.portlet.configuration.icon.ExportImportPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    if (!portletDisplay.isShowExportImportIcon()) {
        return false;
    }//w ww  .java 2  s .co  m

    try {
        return GroupPermissionUtil.contains(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroup(),
                ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
    } catch (PortalException pe) {

        // LPS-52675

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

        return false;
    }
}

From source file:com.liferay.faces.portal.context.internal.LiferayPortletHelperImpl.java

License:Open Source License

@Override
public PermissionChecker getPermissionChecker() {

    ThemeDisplay themeDisplay = getThemeDisplay();

    return themeDisplay.getPermissionChecker();
}

From source file:com.liferay.faces.portal.context.internal.LiferayPortletHelperImpl.java

License:Open Source License

@Override
public boolean userHasPortletPermission(String actionId) {

    ThemeDisplay themeDisplay = getThemeDisplay();
    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    String portletId = portletDisplay.getId();
    boolean hasPermission = false;

    try {/*  w w w.j  av a  2  s  .  c o  m*/
        hasPermission = PortletPermissionUtil.contains(permissionChecker, themeDisplay.getPlid(), portletId,
                actionId);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    return hasPermission;
}

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;
    }/*  ww w . j a v a 2s .c  om*/

    _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.content.web.internal.display.context.JournalContentDisplayContext.java

License:Open Source License

public boolean isShowAddArticleIcon() throws PortalException {
    if (_showAddArticleIcon != null) {
        return _showAddArticleIcon;
    }/*from  w  w  w  .j av  a 2 s  .c  o  m*/

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

    _showAddArticleIcon = false;

    if (!isShowSelectArticleIcon()) {
        return _showAddArticleIcon;
    }

    _showAddArticleIcon = JournalPermission.contains(themeDisplay.getPermissionChecker(),
            themeDisplay.getScopeGroupId(), ActionKeys.ADD_ARTICLE);

    return _showAddArticleIcon;
}

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

License:Open Source License

public boolean isShowEditArticleIcon() {
    if (_showEditArticleIcon != null) {
        return _showEditArticleIcon;
    }//from   w w w  .  j a  v a  2 s. c o  m

    JournalArticle latestArticle = getLatestArticle();

    _showEditArticleIcon = false;

    if (latestArticle == null) {
        return _showEditArticleIcon;
    }

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

    _showEditArticleIcon = JournalArticlePermission.contains(themeDisplay.getPermissionChecker(), latestArticle,
            ActionKeys.UPDATE);

    return _showEditArticleIcon;
}

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

License:Open Source License

public boolean isShowEditTemplateIcon() {
    if (_showEditTemplateIcon != null) {
        return _showEditTemplateIcon;
    }//from   w w  w  .  j av  a 2  s  . c o  m

    _showEditTemplateIcon = false;

    DDMTemplate ddmTemplate = getDDMTemplate();

    if (ddmTemplate == null) {
        return _showEditTemplateIcon;
    }

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    try {
        _showEditTemplateIcon = DDMTemplatePermission.contains(themeDisplay.getPermissionChecker(),
                themeDisplay.getScopeGroupId(), ddmTemplate, portletDisplay.getId(), ActionKeys.UPDATE);
    } catch (PortalException pe) {
        _log.error("Unable to check permission on DDM template " + ddmTemplate.getTemplateId(), pe);
    }

    return _showEditTemplateIcon;
}