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.wiki.web.internal.portlet.configuration.icon.PagePermissionsPortletConfigurationIcon.java

License:Open Source License

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

    try {/* www .  j  av a2s.  c om*/
        WikiPage page = ActionUtil.getPage(portletRequest);

        return WikiNodePermissionChecker.contains(themeDisplay.getPermissionChecker(), page.getNodeId(),
                ActionKeys.PERMISSIONS);
    } catch (Exception e) {
    }

    return false;
}

From source file:com.liferay.wiki.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);

    User user = themeDisplay.getUser();/*from www.  j  a va 2  s. c o  m*/

    if (user.isDefaultUser()) {
        return false;
    }

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    try {
        if (!WikiResourcePermissionChecker.contains(permissionChecker, themeDisplay.getScopeGroupId(),
                ActionKeys.PERMISSIONS)) {

            return false;
        }
    } catch (Exception e) {
        return false;
    }

    return true;
}

From source file:com.liferay.wiki.web.internal.portlet.toolbar.item.WikiPortletToolbarContributor.java

License:Open Source License

protected void addPortletTitleMenuItem(List<MenuItem> menuItems, WikiNode node, ThemeDisplay themeDisplay,
        PortletRequest portletRequest) throws PortalException {

    if (!containsPermission(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(),
            node.getNodeId(), ActionKeys.ADD_PAGE)) {

        return;//ww w.  java  2s  .c  o  m
    }

    URLMenuItem urlMenuItem = new URLMenuItem();

    urlMenuItem.setIcon("icon-plus-sign-2");
    urlMenuItem.setLabel(LanguageUtil.get(PortalUtil.getHttpServletRequest(portletRequest), "add-page"));

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    PortletURL portletURL = PortletURLFactoryUtil.create(portletRequest, portletDisplay.getId(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/wiki/edit_page");
    portletURL.setParameter("redirect", PortalUtil.getCurrentURL(portletRequest));
    portletURL.setParameter("nodeId", String.valueOf(node.getNodeId()));
    portletURL.setParameter("title", StringPool.BLANK);
    portletURL.setParameter("editTitle", "1");

    urlMenuItem.setURL(portletURL.toString());

    menuItems.add(urlMenuItem);
}

From source file:com.liferay.wiki.web.internal.search.NodesChecker.java

License:Open Source License

public NodesChecker(LiferayPortletRequest liferayPortletRequest,
        LiferayPortletResponse liferayPortletResponse) {

    super(liferayPortletResponse);

    _liferayPortletResponse = liferayPortletResponse;

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

    _permissionChecker = themeDisplay.getPermissionChecker();
}

From source file:com.liferay.wiki.web.internal.search.PagesChecker.java

License:Open Source License

public PagesChecker(LiferayPortletRequest liferayPortletRequest,
        LiferayPortletResponse liferayPortletResponse) {

    super(liferayPortletResponse);

    _liferayPortletResponse = liferayPortletResponse;

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

    _permissionChecker = themeDisplay.getPermissionChecker();
}

From source file:com.liferay.wiki.web.internal.upload.PageAttachmentWikiUploadFileEntryHandler.java

License:Open Source License

@Override
public FileEntry upload(UploadPortletRequest uploadPortletRequest) throws IOException, PortalException {

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

    long resourcePrimKey = ParamUtil.getLong(uploadPortletRequest, "resourcePrimKey");

    WikiPage page = _wikiPageService.getPage(resourcePrimKey);

    _wikiNodeModelResourcePermission.check(themeDisplay.getPermissionChecker(), page.getNodeId(),
            ActionKeys.ADD_ATTACHMENT);//w  ww.  j  a v  a2  s  . co m

    String fileName = uploadPortletRequest.getFileName(_PARAMETER_NAME);
    String contentType = uploadPortletRequest.getContentType(_PARAMETER_NAME);
    String[] mimeTypes = ParamUtil.getParameterValues(uploadPortletRequest, "mimeTypes");

    _validateFile(fileName, contentType, mimeTypes);

    try (InputStream inputStream = uploadPortletRequest.getFileAsStream(_PARAMETER_NAME)) {

        return _wikiPageService.addPageAttachment(page.getNodeId(), page.getTitle(), fileName, inputStream,
                contentType);
    }
}