com.xpn.xwiki.plugin.rightsmanager
Class RightsManager

java.lang.Object
  extended by com.xpn.xwiki.plugin.rightsmanager.RightsManager

public final class RightsManager
extends Object

Hidden toolkit used by the plugin API that make all the plugin's actions.

Since:
XWiki Core 1.1.2, XWiki Core 1.2M2 (public since 1.4M1)
Version:
$Id: 5eabf47f35e00ccf4aa2ebfe4b7ed19b8062109e $

Field Summary
static String DEFAULT_USERORGROUP_SPACE
          Name of the default space where users and groups are stored.
 
Method Summary
 int countAllGlobalUsersOrGroups(boolean user, Object[][] matchFields, XWikiContext context)
          Get the number of users or groups in the main wiki.
 int countAllGroupsNamesForMember(String member, XWikiContext context)
          Return the number of groups containing provided member.
 int countAllLocalUsersOrGroups(boolean user, Object[][] matchFields, XWikiContext context)
          Get the number of users or groups in the current wiki.
 int countAllMembersNamesForGroup(String group, XWikiContext context)
          Return the number of members provided group contains.
 int countAllUsersOrGroups(boolean user, Object[][] matchFields, XWikiContext context)
          Get the number of users or groups in the main wiki and the current wiki.
 int countAllWikiUsersOrGroups(boolean user, String wikiName, Object[][] matchFields, XWikiContext context)
          Get the number of users or groups in the provided wiki.
 Collection<String> getAllGroupsNamesForMember(String member, int nb, int start, XWikiContext context)
          Get all groups containing provided user.
 List<?> getAllMatchedGlobalUsersOrGroups(boolean user, Object[][] matchFields, boolean withdetails, RequestLimit limit, Object[][] order, XWikiContext context)
          Get all users or groups in the main wiki.
 List<?> getAllMatchedLocalUsersOrGroups(boolean user, Object[][] matchFields, boolean withdetails, RequestLimit limit, Object[][] order, XWikiContext context)
          Get all users or groups in the current wiki.
 Collection<String> getAllMatchedMembersNamesForGroup(String group, String matchField, int nb, int start, Boolean orderAsc, XWikiContext context)
          Get members of provided group.
 List<?> getAllMatchedUsersOrGroups(boolean user, Object[][] matchFields, boolean withdetails, RequestLimit limit, Object[][] order, XWikiContext context)
          Get all users or groups in the main wiki and the current.
 List<?> getAllMatchedWikiUsersOrGroups(boolean user, String wikiName, Object[][] matchFields, boolean withdetails, RequestLimit limit, Object[][] order, XWikiContext context)
          Get all users or groups in the provided wiki.
 Collection<String> getAllMembersNamesForGroup(String group, int nb, int start, XWikiContext context)
          Get all users provided group contains.
static RightsManager getInstance()
           
 Map<String,LevelTree> getLevelTreeMap(String spaceOrPage, List<String> levelsToMatch, XWikiContext context)
          Get the LevelTree Map for he provided rights levels.
 XWikiDocument getParentPreference(String spaceOrPage, XWikiContext context)
          Get the document containing inherited rights of provided document.
 XWikiDocument getParentPreference(XWikiDocument currentPreference, boolean currentGlobal, XWikiContext context)
          Get the document containing inherited rights of provided document.
 LevelTree getTreeLevel(String spaceOrPage, String levelName, XWikiContext context)
          Get level right tree.
 boolean groupContainsMember(String groupName, String memberName, Map<String,Collection<String>> groupCacheIn, XWikiContext context)
          Browse a group and groups it contains to find provided member (user or group).
 void removeDirectRights(String spaceOrPage, List<String> levelNames, String comment, XWikiContext context)
          Remove "direct" rights for wiki, space or document.
 void removeUserOrGroupFromAllRights(String userOrGroupWiki, String userOrGroupSpace, String userOrGroupName, boolean user, XWikiContext context)
          Remove all references to provided user or group from all rights documents.
 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.
 void removeUserOrGroupFromLevel(String spaceOrPage, String userOrGroup, boolean user, String levelName, boolean allow, String comment, XWikiContext context)
          Remove a user or group from rights preferences document for provided level.
 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.
 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.
 Collection<DocumentReference> resolveUsers(DocumentReference userOrGroup, XWikiContext context)
          Resolve passed user or group into users references list.
 Collection<DocumentReference> resolveUsers(List<String> referenceList, XWikiContext context)
          Resolve passed users and groups into users references list.
 Collection<DocumentReference> resolveUsers(String userOrGroup, XWikiContext context)
          Resolve passed user or group into users references list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

public Collection<String> getAllGroupsNamesForMember(String member,
                                                     int nb,
                                                     int start,
                                                     XWikiContext context)
                                              throws XWikiException
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

public Collection<String> getAllMembersNamesForGroup(String group,
                                                     int nb,
                                                     int start,
                                                     XWikiContext context)
                                              throws XWikiException
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

public int countAllGroupsNamesForMember(String member,
                                        XWikiContext context)
                                 throws XWikiException
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

public int countAllMembersNamesForGroup(String group,
                                        XWikiContext context)
                                 throws XWikiException
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.

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(DocumentReference 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(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


Copyright © 2004-2013 XWiki. All Rights Reserved.