Class RightsManager
- java.lang.Object
-
- 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:
- 1.1.2, 1.2M2
- Version:
- $Id: 1c73ef98427c77493173b415b26b7d4a1d4f49a8 $
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_USERORGROUP_SPACE
Name of the default space where users and groups are stored.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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)
Deprecated.since 10.8RC1, use org.xwiki.user.group.GroupManager component insteadint
countAllLocalUsersOrGroups(boolean user, Object[][] matchFields, XWikiContext context)
Get the number of users or groups in the current wiki.int
countAllMatchedMembersNamesForGroup(String group, String filter, XWikiContext xcontext)
Filters the members of the specified group using the given text and counts the results.int
countAllMembersNamesForGroup(String group, XWikiContext context)
Deprecated.since 10.8RC1, use org.xwiki.user.group.GroupManager component insteadint
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)
Deprecated.since 10.8RC1, use org.xwiki.user.group.GroupManager component insteadList<?>
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)
Deprecated.since 10.8RC1, use org.xwiki.user.group.GroupManager component insteadstatic RightsManager
getInstance()
Map<String,LevelTree>
getLevelTreeMap(String spaceOrPage, List<String> levelsToMatch, XWikiContext context)
XWikiDocument
getParentPreference(XWikiDocument currentPreference, boolean currentGlobal, XWikiContext context)
Get the document containing inherited rights of provided document.XWikiDocument
getParentPreference(String spaceOrPage, 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.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
removeUserOrGroupFromAllRights(String userOrGroupWiki, String userOrGroupSpace, String userOrGroupName, boolean user, XWikiContext context)
Remove all references to provided user or group from all rights documents.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.void
replaceUserOrGroupFromAllRights(DocumentReference userOrGroupSourceReference, DocumentReference userOrGroupTargetReference, boolean user, XWikiContext context)
Replace a user or a group reference with another one on all rights of the current wiki.Collection<DocumentReference>
resolveUsers(String 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(DocumentReference userOrGroup, XWikiContext context)
Resolve passed user or group into users references list.
-
-
-
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 returnList
orString
orList
ofXWikiDocument
.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
ofString
containing user or group name ifwithdetails
is false, otherwise aList
ofXWikiDocument
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 returnList
orString
orList
ofXWikiDocument
.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
ofString
containing user or group name ifwithdetails
is false, otherwise aList
ofXWikiDocument
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 returnList
orString
orList
ofXWikiDocument
.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
ofString
containing user or group name ifwithdetails
is false, otherwise aList
ofXWikiDocument
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 returnList
orString
orList
ofXWikiDocument
.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
ofString
containing user or group name ifwithdetails
is false, otherwise aList
ofXWikiDocument
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 insteadGet 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
ofString
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 insteadGet 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
ofString
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
ofString
containing member name. - Throws:
XWikiException
- error when browsing groups.- Since:
- 1.6M1
-
countAllMatchedMembersNamesForGroup
public int countAllMatchedMembersNamesForGroup(String group, String filter, XWikiContext xcontext) throws XWikiException
Filters the members of the specified group using the given text and counts the results.- Parameters:
group
- the group whose members are going to be countedfilter
- the text used to filter the group membersxcontext
- the XWiki context- Returns:
- the number of group members that match the given text filter
- Throws:
XWikiException
- if counting the group members fails- Since:
- 10.8RC1
- See Also:
getAllMatchedMembersNamesForGroup(String, String, int, int, Boolean, XWikiContext)
-
countAllGroupsNamesForMember
@Deprecated public int countAllGroupsNamesForMember(String member, XWikiContext context) throws XWikiException
Deprecated.since 10.8RC1, use org.xwiki.user.group.GroupManager component insteadReturn 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 insteadReturn 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
- 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 replaceuserOrGroupTargetReference
- the reference of the user or group that will be used as replacementuser
- iftrue
the reference will be looked in the users properties, else in the groups onecontext
- 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(DocumentReference userOrGroup, XWikiContext context) throws XWikiException
Resolve passed user or group into users references list.- Parameters:
userOrGroup
- the user or groupcontext
- 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 groupcontext
- 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 groupscontext
- the XWikiContext the XWiki context- Returns:
- the list of users references
- Throws:
XWikiException
- error when getting documents
-
-