Достъп до Liferay 6.1 персонализирана/наследена организационна роля

Използвам Liferay 6.1 CE, Tomcat, Vaadin 6.8.4
Вероятно изключително неправилен подход от моя страна или може би съм пропуснал нещо очевидно.

Трябва да контролирам crud функциите за моите потребители - разрешаване на достъп до организации, към които принадлежат, и всички дъщерни организации под това. (Използвам таблицата organization_ на Liferay)

Опитвайки се да опростя администрирането на разрешенията, се надявах да присвоя потребител на организация в йерархията. След това привилегиите по подразбиране могат да бъдат определени от ролите, присвоени на тази и всяка родителска организация(и). Това изглежда работи сравнително добре за обикновени роли - но след това се опитах да направя персонализирана организационна роля и не мога да се сдобия с подробностите, както се очакваше.

  • I can see the correct data in the control panel definition for the user.
    ( Liferay knows how to retrieve and display the custom Organization Role :-)

  • I can see the actual data values being populated in the back-end table usergrouprole.

  • I am able to detect this role for the default superadmin / owner (test@liferay)
    . . . but I cannot detect the role for other users :(

  • I have been using RoleLocalServiceUtil and GroupLocalServiceUtil without luck.

    Усещането ми подсказва да изоставя моите „пуристки“ представи и вместо това да се върна към позната персонализирана заявка, но искам първо да видя дали някой друг има по-добри предложения.

    В момента не знам как да вляза в кода на Liferay, за да намеря съответния сегмент, така че може би това може да е опция, ако имате материал за четене :)

    Улики?


  • person Robin Martin    schedule 30.10.2012    source източник


    Отговори (2)


    Това ще изглежда грозно (защото е така), но мисля, че ще трябва да се обадите на:

    UserGroupRoleLocalServiceUtil.hasUserGroupRole(long userId, long groupId, long roleId);
    

    Най-общо казано има (ако не винаги) XYZLocalServiceUtil и XYZServiceUtil за XYZ таблица.

    person rp.    schedule 30.10.2012
    comment
    Благодаря за уликата @rp. . . XYZServiceUtil за XYZ таблица. Наистина помогна за достъп до други необходими таблици. - person Robin Martin; 02.11.2012

    В духа на споделянето, ето примерен код за показване на разрешенията.

    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

    Робин

    person Robin Martin    schedule 01.11.2012