户添加PortletResource权限以按程序查看定制port

户添加PortletResource权限以按程序查看定制port

本文介绍了为特定用户添加PortletResource权限以按程序查看定制portlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我希望我的自定义portlet对特定用户可见,但是他们都是同一组/站点的成员.即...

I want my custom portlet to be view-able by specific users but they're ALL MEMBERS OF SAME GROUP/SITE.i.e...

用户1:我的自定义Portlet无法查看

User 1: my custom Portlet is not view-able

管理员:我的自定义portlet是可见的

Admin: my custom portlet is view-able

用户2:我的自定义portlet是可查看的

User 2: my custom portlet is view-able

如何为特定用户添加Portlet-资源权限以在我的Jsp中以编程方式查看定制portlet?

How to ADD Portlet-Resource permission for particular user to VIEW custom portlet PROGRAMATICALLY in my Jsp???

这是我的代码.

<%@page import="com.liferay.portal.security.permission.ActionKeys"%>
<%@page import="com.liferay.portal.security.permission.PermissionChecker"%>
<%@page import="com.liferay.portal.model.Permission"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ page import="com.liferay.portal.theme.ThemeDisplay" %>
<%@ page import="com.liferay.portal.kernel.util.WebKeys" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@page import="com.liferay.portal.service.RoleLocalServiceUtil"%>
<%@page import="com.liferay.portal.service.UserLocalServiceUtil"%>

<portlet:defineObjects />

<theme:defineObjects/>

<% ThemeDisplay themeDisplay = ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
long companyId = themeDisplay.getCompanyId();
long roleId = RoleLocalServiceUtil.getRole(companyId, "Administrator").getRoleId();
long userId = themeDisplay.getUserId();
UserLocalServiceUtil.hasRoleUser(roleId, userId);

if(permissionChecker.hasPermission(roleId, "com.test.sokbu", 10162, ActionKeys.VIEW)){System.out.println("Ok!");}%>

提前谢谢!

最好的问候,

乔恩

推荐答案

我刚刚点击了此链接 http://agile-reflections.opnworks.com/2011/07/experimenting-with-liferay-permissions.html 和中提琴!现在正在工作! =)感谢 Laurent Gauthier

I just followed this link http://agile-reflections.opnworks.com/2011/07/experimenting-with-liferay-permissions.html and viola! it's now working! =) Thanks to Sir Laurent Gauthier

这是我的样品.

STEP 1

  • docroot/WEB-INF/src

创建 perm.xml

Create perm.xml

<?xml version='1.0' encoding='UTF-8'?>
<resource-action-mapping>
  <portlet-resource>
    <portlet-name>permissions</portlet-name>
    <permissions>
      <supports>
        <action-key>VIEW</action-key>
        <!-- <action-key>DELETE</action-key> -->
      </supports>
      <site-member-defaults>
        <!-- <action-key>VIEW</action-key> -->
        <!-- <action-key>DELETE</action-key> -->
      </site-member-defaults>
      <guest-defaults>
        <!-- <action-key>VIEW</action-key> -->
      </guest-defaults>
      <guest-unsupported>
        <action-key>VIEW</action-key>
      </guest-unsupported>
    </permissions>
  </portlet-resource>
</resource-action-mapping>

  • 创建 default.xml
    • Create default.xml
    • <?xml version="1.0"?>
      <resource-action-mapping>
        <resource file="resource-actions/perm.xml" />
      </resource-action-mapping>
      

      第2步
      -在 docroot/WEB-INF/src
      中创建一个名为 portlet.properties 的文件-插入.. resource.actions.configs=resource-actions/default.xml

      STEP 2
      - Create a file named portlet.properties inside docroot/WEB-INF/src
      - Insert this.. resource.actions.configs=resource-actions/default.xml

      第3步
      -在 liferay-portlet.xml 中的</css-class-wrapper>标记后插入 <add-default-resource>true</add-default-resource> .

      STEP 3
      - Insert <add-default-resource>true</add-default-resource> after </css-class-wrapper> tag in liferay-portlet.xml.

      第4步在这里,我关注了劳伦爵士(Sir Laurent)博客上的内容.

      STEP 4Here I followed what's on the blog of Sir Laurent..

      • 以Liferay管理员的身份在Liferay实例上打开浏览器
      • 创建一个名为示例角色"的新角色
      • 创建一个名为"Example User"的新用户并设置该用户的密码
      • 将示例角色"分配给新创建的用户
      • 在Liferay实例上打开其他浏览器,以进行不同的会话,以"Example User"身份登录并导航到包含此portlet的页面

      请注意 每当我对perm.xml进行更改时,我都会重新启动服务器以使更改生效.

      Pls Note Whenever I have changes in perm.xml, I restart my server for changes to take effect.

      这篇关于为特定用户添加PortletResource权限以按程序查看定制portlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

      1403页,肝出来的..

09-06 13:44