如何在Liferay 7中获取角色的所有权限

时间:2019-06-27 11:17:12

标签: liferay liferay-7

我想获取特定角色的所有权限,我尝试使用ResourcePermissionLocalServiceUtil,但它仅获取角色内部的权限。

var complexArray = "<div id='post' class='post'>First content<\/div><div class='post'>Second Content<\/div><div class='post'>Third Content<\/div>";

let doc = new DOMParser().parseFromString(complexArray, "text/html");
console.log(doc.getElementById('post').innerHTML); //
/// query selector All for all elements

doc.querySelectorAll('.post').forEach((ele, i) => {
  if (i == 1) {
    console.log(ele.innerHTML)
  }

})

获取权限,请参阅获取角色的图片:

enter image description here

我需要此许可,如下图所示。 我想获得的这些权限:

enter image description here

1 个答案:

答案 0 :(得分:1)

通过这种方式,我们可以获取所有权限

PortletConfigurationPermissionsDisplayContext portletConfigurationPermissionsDisplayContext = new PortletConfigurationPermissionsDisplayContext(
            request, renderRequest);

    Resource resource = portletConfigurationPermissionsDisplayContext.getResource();

    if (Validator.isNotNull(portletConfigurationPermissionsDisplayContext.getModelResource())) {
        PortalUtil.addPortletBreadcrumbEntry(request,
                HtmlUtil.unescape(portletConfigurationPermissionsDisplayContext.getSelResourceDescription()),
                null);
        PortalUtil.addPortletBreadcrumbEntry(request, LanguageUtil.get(request, "permissions"), currentURL);
    }
    System.out.println("Resource::" + resource);

    boolean role_a_hasPermissionToView = false;
    List<Role> allRoles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount());
    //System.out.println(allRoles + "-all roles");
    for (Role role : allRoles) {


                System.out.println("---------------------------------------");
                String rolename = role.getName();
                System.out.println("Primary Key::" + role.getPrimaryKey() + "----Role Name::" + rolename);
                System.out.println("---------------------------------------");

                List<String> currentIndividualActions1 = new ArrayList<String>();
                List<String> currentGroupActions1 = new ArrayList<String>();
                List<String> currentGroupTemplateActions1 = new ArrayList<String>();
                List<String> currentCompanyActions1 = new ArrayList<String>();
                ResourcePermissionUtil.populateResourcePermissionActionIds(
                        portletConfigurationPermissionsDisplayContext.getGroupId(), role, resource,
                        portletConfigurationPermissionsDisplayContext.getActions(), currentIndividualActions1,
                        currentGroupActions1, currentGroupTemplateActions1, currentCompanyActions1);

                for (String action : portletConfigurationPermissionsDisplayContext.getActions()) {
                    System.out.println("action::" + action);
                    System.out
                            .println("Resource Action Util:" + ResourceActionsUtil.getAction(request, action));
                    if (action.equals(ActionKeys.ACCESS_IN_CONTROL_PANEL)) {
                        continue;
                    }

                    boolean checked1 = false;

                    if (currentIndividualActions1.contains(action) || currentGroupActions1.contains(action)
                            || currentGroupTemplateActions1.contains(action)
                            || currentCompanyActions1.contains(action)) {
                        checked1 = true;
                    }

                    String preselectedMsg = StringPool.BLANK;

                    if (currentGroupActions1.contains(action)
                            || currentGroupTemplateActions1.contains(action)) {
                        preselectedMsg = "x-is-allowed-to-do-action-x-in-all-items-of-type-x-in-x";
                    } else if (currentCompanyActions1.contains(action)) {
                        preselectedMsg = "x-is-allowed-to-do-action-x-in-all-items-of-type-x-in-this-portal-instance";
                    }

                    List<String> guestUnsupportedActions1 = portletConfigurationPermissionsDisplayContext
                            .getGuestUnsupportedActions();

                    boolean disabled1 = false;

                    if (rolename.equals(RoleConstants.GUEST) && guestUnsupportedActions1.contains(action)) {
                        disabled1 = true;
                    }

                    String dataMessage = StringPool.BLANK;

                    if (Validator.isNotNull(preselectedMsg)) {
                        String type1 = portletConfigurationPermissionsDisplayContext
                                .getSelResourceDescription();

                        if (Validator.isNull(type1)) {
                            type1 = ResourceActionsUtil.getModelResource(locale, resource.getName());
                        }

                        dataMessage = HtmlUtil.escapeAttribute(LanguageUtil.format(request, preselectedMsg,
                                new Object[]{role.getTitle(locale),
                                        ResourceActionsUtil.getAction(request, action), type1,
                                        HtmlUtil.escape(portletConfigurationPermissionsDisplayContext
                                                .getGroupDescriptiveName())},
                                false));
                    }

                    String actionSeparator = Validator.isNotNull(preselectedMsg)
                            ? ActionUtil.PRESELECTED
                            : ActionUtil.ACTION;
                    System.out.println("Checked:::" + checked1);

                } //for loops ends here

    } //loops end here

[此权限获取1