共有の精神で、権限を表示するためのサンプルコードを次に示します。
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
User i_user = themeDisplay.getUser();
PortletDisplay portDisplay = themeDisplay.getPortletDisplay();
String myRootname = portDisplay.getRootPortletId();
String strOrgGroupRoles = "";
//== 1. Display permission provided to user by Organisation(Group) Roles
//== 2. User is assigned to the org.
//== 3. Org is a member of the OrgRole.
//== 4. OrgRole has permission defined from current selected portlet permissions (action-key)
List<UserGroupRole> ugRoles = new ArrayList<UserGroupRole>();
ugRoles.addAll(UserGroupRoleLocalServiceUtil.getUserGroupRoles(i_user.getUserId() ) );
for (UserGroupRole ugRole : ugRoles){
//== For each role this user has allocated, display the Rolename and the Organisation
strOrgGroupRoles += "'" +ugRole.getRole().getName() + "' (roleId="+ugRole.getRoleId()+")";
strOrgGroupRoles += " for organization '"+OrganizationLocalServiceUtil.getOrganization(ugRole.getGroup().getClassPK()).getName();
strOrgGroupRoles += "' (groupId=" +ugRole.getGroupId()+ ")\n";
//== Permissions for the role is harder to find - linked to a resource
//== Data shows the `actionId` equates to relative action number column 'bitwiseValue' in `resourceaction`.
//== Snag is ResourcePermission needs a tie-breaker of the portlet name, not just the roleId
//== Get this from ThemeDisplay getRootPortletId()
//==
//== I think Liferay 6.1.0 API may be broken here: ResourceActionLocalServiceUtil.getResourceAction expects String, String . . .
//== . . . yet the `bitwiseValue` column is BIGINT(20) so nothing is returned.
//== This causes us to attack it from a different angle
List<ResourcePermission> resourcePerms = new ArrayList<ResourcePermission>();
resourcePerms.addAll( ResourcePermissionLocalServiceUtil.getRoleResourcePermissions(ugRole.getRoleId()) );
for (ResourcePermission resourcePerm : resourcePerms){
//== For each of the ResourcePermissions of this role, get the actionId (equals Role Permissions aka action-key)
//== The link is a relative number, not unique in this table so ensure it is for this portlet only
if ( resourcePerm.getName().equals(myRootname)){
List<ResourceAction> resourceActions = new ArrayList<ResourceAction>();
resourceActions.addAll( ResourceActionLocalServiceUtil.getResourceActions(myRootname) );
for (ResourceAction resourceAction : resourceActions) {
//== For each listed action, ensure it is the relative action number we want (actionId)
if (resourceAction.getBitwiseValue() == resourcePerm.getActionIds() ) {
strOrgGroupRoles += " +-- action= " + resourceAction.getActionId() + "\n";
}
} //== End of actionIds for this portlet
} //== End if this portlet only
} //== End ResourcePermissions for this role
} //== End roles for this user
HTH
ロビン