Class RightsManager


  • public final class RightsManager
    extends Object
    Hidden toolkit used by the plugin API that make all the plugin's actions.
    Since:
    1.1.2, 1.2M2
    Version:
    $Id: 1c73ef98427c77493173b415b26b7d4a1d4f49a8 $
    • Field Detail

      • DEFAULT_USERORGROUP_SPACE

        public static final String DEFAULT_USERORGROUP_SPACE
        Name of the default space where users and groups are stored.
        See Also:
        Constant Field Values
    • Method Detail

      • getInstance

        public static RightsManager getInstance()
        Returns:
        a unique instance of RightsManager. Thread safe.
      • countAllUsersOrGroups

        public int countAllUsersOrGroups​(boolean user,
                                         Object[][] matchFields,
                                         XWikiContext context)
                                  throws XWikiException
        Get the number of users or groups in the main wiki and the current wiki.
        Parameters:
        user - indicate if methods search for users or groups.
        matchFields - the field to math with values. It is a table of table with :
        • fiedname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        • pattern matching : based on HQL "like" command
        context - the XWiki context.
        Returns:
        the number of groups in the main wiki and the current wiki.
        Throws:
        XWikiException - error when getting number of users or groups.
      • countAllWikiUsersOrGroups

        public int countAllWikiUsersOrGroups​(boolean user,
                                             String wikiName,
                                             Object[][] matchFields,
                                             XWikiContext context)
                                      throws XWikiException
        Get the number of users or groups in the provided wiki.
        Parameters:
        user - indicate if methods search for users or groups.
        wikiName - the name of the wiki where to search for users or groups.
        matchFields - the field to math with values. It is a table of table with :
        • fiedname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        • pattern matching : based on HQL "like" command
        context - the XWiki context.
        Returns:
        the number of groups in the provided wiki.
        Throws:
        XWikiException - error when getting number of users or groups.
      • countAllGlobalUsersOrGroups

        public int countAllGlobalUsersOrGroups​(boolean user,
                                               Object[][] matchFields,
                                               XWikiContext context)
                                        throws XWikiException
        Get the number of users or groups in the main wiki.
        Parameters:
        user - indicate if methods search for users or groups.
        matchFields - the field to math with values. It is a table of table with :
        • fiedname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        • pattern matching : based on HQL "like" command
        context - the XWiki context.
        Returns:
        the number of groups in the main wiki.
        Throws:
        XWikiException - error when getting number of users or groups.
      • countAllLocalUsersOrGroups

        public int countAllLocalUsersOrGroups​(boolean user,
                                              Object[][] matchFields,
                                              XWikiContext context)
                                       throws XWikiException
        Get the number of users or groups in the current wiki.
        Parameters:
        user - indicate if methods search for users or groups.
        matchFields - the field to math with values. It is a table of table with :
        • fiedname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        • pattern matching : based on HQL "like" command
        context - the XWiki context.
        Returns:
        the number of groups in the current wiki.
        Throws:
        XWikiException - error when getting number of users or groups.
      • getAllMatchedUsersOrGroups

        public List<?> getAllMatchedUsersOrGroups​(boolean user,
                                                  Object[][] matchFields,
                                                  boolean withdetails,
                                                  RequestLimit limit,
                                                  Object[][] order,
                                                  XWikiContext context)
                                           throws XWikiException
        Get all users or groups in the main wiki and the current.
        Parameters:
        user - indicate if it is a user or a group.
        matchFields - the field to math with values. It is a table of table with :
        • fiedname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        • pattern matching : based on HQL "like" command
        withdetails - indicate if the methods return List or String or List of XWikiDocument.
        limit - the maximum number of result to return and index of the first element.
        order - the fields to order from. It is a table of table with :
        • fieldname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        context - the XWiki context.
        Returns:
        a List of String containing user or group name if withdetails is false, otherwise a List of XWikiDocument containing user or group.
        Throws:
        XWikiException - error when searching from users or groups.
      • getAllMatchedGlobalUsersOrGroups

        public List<?> getAllMatchedGlobalUsersOrGroups​(boolean user,
                                                        Object[][] matchFields,
                                                        boolean withdetails,
                                                        RequestLimit limit,
                                                        Object[][] order,
                                                        XWikiContext context)
                                                 throws XWikiException
        Get all users or groups in the main wiki.
        Parameters:
        user - indicate if it is a user or a group.
        matchFields - the field to math with values. It is a table of table with :
        • fiedname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        • pattern matching : based on HQL "like" command
        withdetails - indicate if the methods return List or String or List of XWikiDocument.
        limit - the maximum number of result to return and index of the first element.
        order - the fields to order from. It is a table of table with :
        • fieldname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        context - the XWiki context.
        Returns:
        a List of String containing user or group name if withdetails is false, otherwise a List of XWikiDocument containing user or group.
        Throws:
        XWikiException - error when searching from users or groups.
      • getAllMatchedWikiUsersOrGroups

        public List<?> getAllMatchedWikiUsersOrGroups​(boolean user,
                                                      String wikiName,
                                                      Object[][] matchFields,
                                                      boolean withdetails,
                                                      RequestLimit limit,
                                                      Object[][] order,
                                                      XWikiContext context)
                                               throws XWikiException
        Get all users or groups in the provided wiki.
        Parameters:
        user - indicate if it is a user or a group.
        wikiName - the name of the wiki where to search.
        matchFields - the field to math with values. It is a table of table with :
        • fiedname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        • pattern matching : based on HQL "like" command
        withdetails - indicate if the methods return List or String or List of XWikiDocument.
        limit - the maximum number of result to return and index of the first element.
        order - the fields to order from. It is a table of table with :
        • fieldname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        context - the XWiki context.
        Returns:
        a List of String containing user or group name if withdetails is false, otherwise a List of XWikiDocument containing user or group.
        Throws:
        XWikiException - error when searching from users or groups.
      • getAllMatchedLocalUsersOrGroups

        public List<?> getAllMatchedLocalUsersOrGroups​(boolean user,
                                                       Object[][] matchFields,
                                                       boolean withdetails,
                                                       RequestLimit limit,
                                                       Object[][] order,
                                                       XWikiContext context)
                                                throws XWikiException
        Get all users or groups in the current wiki.
        Parameters:
        user - indicate if it is a user or a group.
        matchFields - the field to math with values. It is a table of table with :
        • fiedname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        • pattern matching : based on HQL "like" command
        withdetails - indicate if the methods return List or String or List of XWikiDocument.
        limit - the maximum number of result to return and index of the first element.
        order - the fields to order from. It is a table of table with :
        • fieldname : the name of the field
        • fieldtype : for example StringProperty. If null the field is considered as document field
        context - the XWiki context.
        Returns:
        a List of String containing user or group name if withdetails is false, otherwise a List of XWikiDocument containing user or group.
        Throws:
        XWikiException - error when searching from users or groups.
      • getAllGroupsNamesForMember

        @Deprecated
        public Collection<String> getAllGroupsNamesForMember​(String member,
                                                             int nb,
                                                             int start,
                                                             XWikiContext context)
                                                      throws XWikiException
        Deprecated.
        since 10.8RC1, use org.xwiki.user.group.GroupManager component instead
        Get all groups containing provided user.
        Parameters:
        member - the name of the member (user or group).
        nb - the maximum number of result to return.
        start - the index of the first found member to return.
        context - the XWiki context.
        Returns:
        the Collection of String containing group name.
        Throws:
        XWikiException - error when browsing groups.
      • getAllMembersNamesForGroup

        @Deprecated
        public Collection<String> getAllMembersNamesForGroup​(String group,
                                                             int nb,
                                                             int start,
                                                             XWikiContext context)
                                                      throws XWikiException
        Deprecated.
        since 10.8RC1, use org.xwiki.user.group.GroupManager component instead
        Get all users provided group contains.
        Parameters:
        group - the name of the group.
        nb - the maximum number of result to return.
        start - the index of the first found user to return.
        context - the XWiki context.
        Returns:
        the Collection of String containing user name.
        Throws:
        XWikiException - error when browsing groups.
      • getAllMatchedMembersNamesForGroup

        public Collection<String> getAllMatchedMembersNamesForGroup​(String group,
                                                                    String matchField,
                                                                    int nb,
                                                                    int start,
                                                                    Boolean orderAsc,
                                                                    XWikiContext context)
                                                             throws XWikiException
        Get members of provided group.
        Parameters:
        group - the group.
        matchField - a string to search in result to filter.
        nb - the maximum number of result to return.
        start - the index of the first found user to return.
        orderAsc - if true, the result is ordered ascendent, if false it descendant. If null no order is applied.
        context - the XWiki context.
        Returns:
        the Collection of String containing member name.
        Throws:
        XWikiException - error when browsing groups.
        Since:
        1.6M1
      • countAllGroupsNamesForMember

        @Deprecated
        public int countAllGroupsNamesForMember​(String member,
                                                XWikiContext context)
                                         throws XWikiException
        Deprecated.
        since 10.8RC1, use org.xwiki.user.group.GroupManager component instead
        Return the number of groups containing provided member.
        Parameters:
        member - the name of the member (user or group).
        context - the XWiki context.
        Returns:
        the number of groups.
        Throws:
        XWikiException - error when getting number of users.
      • countAllMembersNamesForGroup

        @Deprecated
        public int countAllMembersNamesForGroup​(String group,
                                                XWikiContext context)
                                         throws XWikiException
        Deprecated.
        since 10.8RC1, use org.xwiki.user.group.GroupManager component instead
        Return the number of members provided group contains.
        Parameters:
        group - the name of the group.
        context - the XWiki context.
        Returns:
        the number of members.
        Throws:
        XWikiException - error when getting number of groups.
      • getLevelTreeMap

        public Map<String,​LevelTree> getLevelTreeMap​(String spaceOrPage,
                                                           List<String> levelsToMatch,
                                                           XWikiContext context)
                                                    throws XWikiException
        Get the LevelTree Map for he provided rights levels.
        Parameters:
        spaceOrPage - the space of page where to get XWikiRights. If null get wiki rights.
        levelsToMatch - the levels names to check ("view", "edit", etc.).
        context - the XWiki context.
        Returns:
        the Map containing [levelname : LevelTree].
        Throws:
        XWikiException - error when browsing rights preferences.
      • getParentPreference

        public XWikiDocument getParentPreference​(XWikiDocument currentPreference,
                                                 boolean currentGlobal,
                                                 XWikiContext context)
                                          throws XWikiException
        Get the document containing inherited rights of provided document.
        Parameters:
        currentPreference - the document for which to find parent preferences document.
        currentGlobal - indicate if current preferences document is global.
        context - the XWiki context.
        Returns:
        the document containing inherited rights of provided document.
        Throws:
        XWikiException - error when browsing rights preferences.
      • getParentPreference

        public XWikiDocument getParentPreference​(String spaceOrPage,
                                                 XWikiContext context)
                                          throws XWikiException
        Get the document containing inherited rights of provided document.
        Parameters:
        spaceOrPage - the space of page where to get XWikiRights. If null get wiki rights.
        context - the XWiki context.
        Returns:
        the document containing inherited rights of provided document.
        Throws:
        XWikiException - error when browsing rights preferences.
      • getTreeLevel

        public LevelTree getTreeLevel​(String spaceOrPage,
                                      String levelName,
                                      XWikiContext context)
                               throws XWikiException
        Get level right tree.
        Parameters:
        spaceOrPage - the space of page where to get XWikiRights. If null get wiki rights.
        levelName - the level right name ("view", "delete"...).
        context - the XWiki context.
        Returns:
        the LevelTree.
        Throws:
        XWikiException - error when browsing rights.
      • removeUserOrGroupFromLevel

        public void removeUserOrGroupFromLevel​(String spaceOrPage,
                                               String userOrGroup,
                                               boolean user,
                                               String levelName,
                                               boolean allow,
                                               String comment,
                                               XWikiContext context)
                                        throws XWikiException
        Remove a user or group from rights preferences document for provided level.
        Parameters:
        spaceOrPage - the space of page where to get XWikiRights. If null get wiki rights.
        userOrGroup - the name of the user or group.
        user - indicate if it is a user or group.
        levelName - the name of the right level.
        allow - indicate if user is removed from allow right or deny right.
        comment - the comment to use when saving preferences document.
        context - the XWiki context.
        Throws:
        XWikiException - error when browsing rights.
      • removeUserOrGroupFromRight

        public boolean removeUserOrGroupFromRight​(BaseObject right,
                                                  String userOrGroupWiki,
                                                  String userOrGroupSpace,
                                                  String userOrGroupName,
                                                  boolean user,
                                                  XWikiContext context)
        Remove all references to provided user or group from provided right object.
        Parameters:
        right - the object containing the right preferences.
        userOrGroupWiki - the name of the wiki of the use or group.
        userOrGroupSpace - the name of the space of the use or group.
        userOrGroupName - the name of the use or group.
        user - indicate if it is a user or a group.
        context - the XWiki context.
        Returns:
        true if user or group has been found and removed.
      • removeUserOrGroupFromRights

        public boolean removeUserOrGroupFromRights​(XWikiDocument rightsDocument,
                                                   String userOrGroupWiki,
                                                   String userOrGroupSpace,
                                                   String userOrGroupName,
                                                   boolean user,
                                                   boolean global,
                                                   XWikiContext context)
        Remove all references to provided user or group from provided rights document.
        Parameters:
        rightsDocument - the document containing the rights preferences.
        userOrGroupWiki - the name of the wiki of the use or group.
        userOrGroupSpace - the name of the space of the use or group.
        userOrGroupName - the name of the use or group.
        user - indicate if it is a user or a group.
        global - indicate if user or group is removed from global or document rights.
        context - the XWiki context.
        Returns:
        true if user or group has been found and removed.
      • removeUserOrGroupFromAllRights

        public boolean removeUserOrGroupFromAllRights​(XWikiDocument rightsDocument,
                                                      String userOrGroupWiki,
                                                      String userOrGroupSpace,
                                                      String userOrGroupName,
                                                      boolean user,
                                                      XWikiContext context)
        Remove all references to provided user or group from provided rights document.
        Parameters:
        rightsDocument - the document containing the rights preferences.
        userOrGroupWiki - the name of the wiki of the use or group.
        userOrGroupSpace - the name of the space of the use or group.
        userOrGroupName - the name of the use or group.
        user - indicate if it is a user or a group.
        context - the XWiki context.
        Returns:
        true if user or group has been found and removed.
      • removeUserOrGroupFromAllRights

        public void removeUserOrGroupFromAllRights​(String userOrGroupWiki,
                                                   String userOrGroupSpace,
                                                   String userOrGroupName,
                                                   boolean user,
                                                   XWikiContext context)
                                            throws XWikiException
        Remove all references to provided user or group from all rights documents.
        Parameters:
        userOrGroupWiki - the name of the wiki of the use or group.
        userOrGroupSpace - the name of the space of the use or group.
        userOrGroupName - the name of the use or group.
        user - indicate if it is a user or a group.
        context - the XWiki context.
        Throws:
        XWikiException - error when browsing rights.
      • replaceUserOrGroupFromAllRights

        public void replaceUserOrGroupFromAllRights​(DocumentReference userOrGroupSourceReference,
                                                    DocumentReference userOrGroupTargetReference,
                                                    boolean user,
                                                    XWikiContext context)
                                             throws XWikiException
        Replace a user or a group reference with another one on all rights of the current wiki.
        Parameters:
        userOrGroupSourceReference - the reference of the user or group that we need to replace
        userOrGroupTargetReference - the reference of the user or group that will be used as replacement
        user - if true the reference will be looked in the users properties, else in the groups one
        context - the current context
        Throws:
        XWikiException - in case of errors
        Since:
        11.9RC1
      • removeDirectRights

        public void removeDirectRights​(String spaceOrPage,
                                       List<String> levelNames,
                                       String comment,
                                       XWikiContext context)
                                throws XWikiException
        Remove "direct" rights for wiki, space or document. This means that after that inherited right will be used.
        Parameters:
        spaceOrPage - the space of page where to get XWikiRights. If null get wiki rights.
        levelNames - the levels names to check ("view", "edit", etc.).
        comment - the comment to use when saving preferences document.
        context - the XWiki context.
        Throws:
        XWikiException - error when browsing rights.
      • groupContainsMember

        public boolean groupContainsMember​(String groupName,
                                           String memberName,
                                           Map<String,​Collection<String>> groupCacheIn,
                                           XWikiContext context)
                                    throws XWikiException
        Browse a group and groups it contains to find provided member (user or group).
        Parameters:
        groupName - the group name where to search for member.
        memberName - the name of the member to find.
        groupCacheIn - a map containing a set a group and its corresponding members already retrieved.
        context - the XWiki context.
        Returns:
        true if the member has been found, false otherwise.
        Throws:
        XWikiException - error when browsing groups.
      • resolveUsers

        public Collection<DocumentReference> resolveUsers​(String userOrGroup,
                                                          XWikiContext context)
                                                   throws XWikiException
        Resolve passed user or group into users references list.
        Parameters:
        userOrGroup - the user or group
        context - the XWikiContext the XWiki context
        Returns:
        the list of users references
        Throws:
        XWikiException - error when getting documents
      • resolveUsers

        public Collection<DocumentReference> resolveUsers​(List<String> referenceList,
                                                          XWikiContext context)
                                                   throws XWikiException
        Resolve passed users and groups into users references list.
        Parameters:
        referenceList - the list of users and groups
        context - the XWikiContext the XWiki context
        Returns:
        the list of users references
        Throws:
        XWikiException - error when getting documents