Liferay 7中如何获取角色的所有权限
How to Fetch all Permission of Role in Liferay 7
我想获取特定角色的所有权限,我尝试使用 ResourcePermissionLocalServiceUtil 但它只获取角色内部的权限。
System.out.println("userGroupGroupRole:::" + userGroupGroupRole);
List<ResourcePermission> listOfPermission = new
ArrayList<ResourcePermission>();
for (UserGroupGroupRole uggrole : userGroupGroupRole) {
listOfPermission
.addAll(ResourcePermissionLocalServiceUtil.getRoleResourcePermissions(uggrole.getRoleId()));
System.out.println("Title::" + uggrole.getRole().getTitle(locale));
System.out.println("Site:::" + uggrole.getGroup().getGroupKey());
System.out.println("user-group:::::" + uggrole.getUserGroup().getName());
}
System.out.println("listOfPermission::" + listOfPermission);
获取权限查看图片获取了哪些角色:
我需要如下图所示的权限。
我想获得这些权限:
这样我们可以获取所有权限
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
我想获取特定角色的所有权限,我尝试使用 ResourcePermissionLocalServiceUtil 但它只获取角色内部的权限。
System.out.println("userGroupGroupRole:::" + userGroupGroupRole);
List<ResourcePermission> listOfPermission = new
ArrayList<ResourcePermission>();
for (UserGroupGroupRole uggrole : userGroupGroupRole) {
listOfPermission
.addAll(ResourcePermissionLocalServiceUtil.getRoleResourcePermissions(uggrole.getRoleId()));
System.out.println("Title::" + uggrole.getRole().getTitle(locale));
System.out.println("Site:::" + uggrole.getGroup().getGroupKey());
System.out.println("user-group:::::" + uggrole.getUserGroup().getName());
}
System.out.println("listOfPermission::" + listOfPermission);
获取权限查看图片获取了哪些角色:
我需要如下图所示的权限。 我想获得这些权限:
这样我们可以获取所有权限
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