Example usage for com.liferay.portal.kernel.service.permission PortletPermissionUtil contains

List of usage examples for com.liferay.portal.kernel.service.permission PortletPermissionUtil contains

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service.permission PortletPermissionUtil contains.

Prototype

public static boolean contains(PermissionChecker permissionChecker, long plid, String portletId,
            String actionId) throws PortalException 

Source Link

Usage

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);
    }/*w w  w  .  j a v  a2 s .c o  m*/
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.display.context.DDLFormDisplayContext.java

License:Open Source License

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

    if (isPreview() || (isSharedURL() && isFormShared())) {
        _showConfigurationIcon = false;

        return _showConfigurationIcon;
    }

    ThemeDisplay themeDisplay = getThemeDisplay();

    _showConfigurationIcon = PortletPermissionUtil.contains(themeDisplay.getPermissionChecker(),
            themeDisplay.getLayout(), getPortletId(), ActionKeys.CONFIGURATION);

    return _showConfigurationIcon;
}

From source file:com.liferay.dynamic.data.lists.web.internal.display.context.DDLDisplayContext.java

License:Open Source License

public boolean isShowConfigurationIcon() throws PortalException {
    if (_showConfigurationIcon != null) {
        return _showConfigurationIcon;
    }//from w  ww. j  ava2  s.  c om

    _showConfigurationIcon = PortletPermissionUtil.contains(getPermissionChecker(), getLayout(), getPortletId(),
            ActionKeys.CONFIGURATION);

    return _showConfigurationIcon;
}

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 {/*from  w w  w  . j  a  va 2s  .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 isShowSelectArticleIcon() throws PortalException {
    if (_showSelectArticleIcon != null) {
        return _showSelectArticleIcon;
    }// www  .  j  av  a 2  s.  c o m

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    _showSelectArticleIcon = PortletPermissionUtil.contains(themeDisplay.getPermissionChecker(),
            themeDisplay.getLayout(), portletDisplay.getId(), ActionKeys.CONFIGURATION);

    return _showSelectArticleIcon;
}

From source file:com.liferay.portlet.configuration.css.web.internal.portlet.PortletConfigurationCSSPortlet.java

License:Open Source License

public void getLookAndFeel(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws PortletException {

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

    try {//from  w ww.  jav  a  2 s .  c  om
        Layout layout = themeDisplay.getLayout();

        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

        String portletId = ParamUtil.getString(resourceRequest, "portletId");

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

            return;
        }

        PortletPreferences portletSetup = PortletPreferencesFactoryUtil.getStrictLayoutPortletSetup(layout,
                portletId);

        JSONObject portletSetupJSONObject = PortletSetupUtil.cssToJSONObject(portletSetup);

        JSONObject defaultPortletTitlesJSONObject = JSONFactoryUtil.createJSONObject();

        for (Locale locale : LanguageUtil.getAvailableLocales(themeDisplay.getSiteGroupId())) {

            String rootPortletId = PortletConstants.getRootPortletId(portletId);
            String languageId = LocaleUtil.toLanguageId(locale);

            defaultPortletTitlesJSONObject.put(languageId, _portal.getPortletTitle(rootPortletId, languageId));
        }

        portletSetupJSONObject.put("defaultPortletTitles", defaultPortletTitlesJSONObject);

        writeJSON(resourceRequest, resourceResponse, portletSetupJSONObject.toString());
    } catch (Exception e) {
        throw new PortletException(e);
    }
}

From source file:com.liferay.portlet.configuration.css.web.internal.portlet.PortletConfigurationCSSPortlet.java

License:Open Source License

public void updateLookAndFeel(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    String portletId = ParamUtil.getString(actionRequest, "portletId");

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

        return;//from   w w w  .  j av a  2s  . co m
    }

    PortletPreferences portletSetup = PortletPreferencesFactoryUtil.getStrictLayoutPortletSetup(layout,
            portletId);

    String css = ParamUtil.getString(actionRequest, "css");

    if (_log.isDebugEnabled()) {
        _log.debug("Updating css " + css);
    }

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(css);

    JSONObject portletDataJSONObject = jsonObject.getJSONObject("portletData");

    jsonObject.remove("portletData");

    css = jsonObject.toString();

    String linkToLayoutUuid = GetterUtil.getString(portletDataJSONObject.getString("portletLinksTarget"));
    String portletDecoratorId = portletDataJSONObject.getString("portletDecoratorId");
    JSONObject titlesJSONObject = portletDataJSONObject.getJSONObject("titles");
    boolean useCustomTitle = portletDataJSONObject.getBoolean("useCustomTitle");

    Set<Locale> locales = LanguageUtil.getAvailableLocales(themeDisplay.getSiteGroupId());

    for (Locale locale : locales) {
        String languageId = LocaleUtil.toLanguageId(locale);

        String title = null;

        if (titlesJSONObject.has(languageId)) {
            title = GetterUtil.getString(titlesJSONObject.getString(languageId));
        }

        String rootPortletId = PortletConstants.getRootPortletId(portletId);

        String defaultPortletTitle = _portal.getPortletTitle(rootPortletId, languageId);

        if ((title != null) && !Objects.equals(defaultPortletTitle, title)) {

            portletSetup.setValue("portletSetupTitle_" + languageId, title);
        } else {
            portletSetup.reset("portletSetupTitle_" + languageId);
        }
    }

    portletSetup.setValue("portletSetupUseCustomTitle", String.valueOf(useCustomTitle));

    if (Validator.isNotNull(linkToLayoutUuid)) {
        portletSetup.setValue("portletSetupLinkToLayoutUuid", linkToLayoutUuid);
    } else {
        portletSetup.reset("portletSetupLinkToLayoutUuid");
    }

    if (Validator.isNotNull(portletDecoratorId)) {
        portletSetup.setValue("portletSetupPortletDecoratorId", portletDecoratorId);
    } else {
        portletSetup.reset("portletSetupPortletDecoratorId");
    }

    portletSetup.setValue("portletSetupCss", css);

    portletSetup.store();
}

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

License:Open Source License

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    String rootPortletId = portletDisplay.getRootPortletId();

    if (Validator.isNotNull(portletDisplay.getPortletResource())) {
        String portletResource = portletDisplay.getPortletResource();

        Portlet portlet = _portletLocalService.getPortletById(themeDisplay.getCompanyId(), portletResource);

        rootPortletId = portlet.getRootPortletId();
    }//w w  w . ja v a2  s  .c  o  m

    boolean showPermissionsIcon = false;

    Layout layout = themeDisplay.getLayout();

    Group group = themeDisplay.getScopeGroup();

    if (!group.hasStagingGroup() || _STAGING_LIVE_GROUP_LOCKING_ENABLED) {
        try {
            if (PortletPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout, rootPortletId,
                    ActionKeys.PERMISSIONS)) {

                showPermissionsIcon = true;
            }
        } catch (PortalException pe) {

            // LPS-52675

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

            showPermissionsIcon = false;
        }
    }

    if (layout.isLayoutPrototypeLinkActive()) {
        showPermissionsIcon = false;
    }

    if (layout.isTypeControlPanel()) {
        showPermissionsIcon = false;
    }

    return showPermissionsIcon;
}