Package net.sf.basedb.core
Class MultiPermissions
java.lang.Object
net.sf.basedb.core.MultiPermissions
This is a helper class that is very useful when you have a collection of
Shareable
items and want to modify some permissions on
all of them without affecting the rest of the permissions.
For example it is possible to add write permission for a new user while preserving the permissions already given to other user, groups and projects. This works even if the logged in user doesn't have read permission to all other user, groups and projects the items have been shared to.
It is a four-step procedure:
- Create a new object using the
MultiPermissions(Collection)
constructor. - Add, remove or modify permissions as required.
- Call the
updateKeys(DbControl)
method to generate the new keys and assign those to the items - Commit the transaction.
- Version:
- 2.0
- Author:
- Nicklas
- Last modified
- $Date: 2016-10-19 14:16:14 +0200 (on, 19 okt 2016) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate final Map<ItemKey,
GroupPermissions> private final boolean
private final Set<SharedItem>
private final Map<ProjectKey,
ProjectPermissions> private final Map<ItemKey,
UserPermissions> -
Constructor Summary
ConstructorDescriptionMultiPermissions
(Collection<? extends SharedItem> itemsToShare) Create a newMultiPermissions
object and feed it the collection ofShareable
items that you want to modify. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPermissions
(Group group, Set<Permission> permissions) Grant permissions to a group, keeping those that have already been set.void
addPermissions
(Project project, Set<Permission> permissions) Grant permissions to a project, keeping those that have already been set.void
addPermissions
(User user, Set<Permission> permissions) Grant permissions to a user, keeping those that have already been set.static boolean
allSame
(Collection<Set<Permission>> permissions) Check if a collection ofSet
:s all contain the same permissions.Get a query that returns all groups appearing in at least one of the item keys.getItems()
Returns the items that are handled within this class.getItems
(Collection<Item> types) Get all items of specific item types.Get all items of a specific item type.getPermissions
(Group group) Get the permissions for a group.getPermissions
(Project project) Get the permissions for a project.getPermissions
(User user) Get the permissions for a user.Get a query that returns all projects appearing in at least one of the project keys.getUsers()
Get a query that returns all users appearing in at least one of the item keys.boolean
Is any of the items to share an annotatable item?void
Merge the permissions from the given item key keeping those that has already been set.void
merge
(ProjectKey projectKey) Merge the permissions from the given project key keeping those that has already been set.void
setPermissions
(Group group, Set<Permission> permissions) Grant permissions to a group.void
setPermissions
(Project project, Set<Permission> permissions) Grant permissions to a project.void
setPermissions
(User user, Set<Permission> permissions) Grant permissions to a user.void
updateKeys
(DbControl dc) Generate the new keys and update all items with the new keys.void
updateKeys
(DbControl dc, boolean recursive) Generate the new keys and update all items with the new keys.
-
Field Details
-
items
-
userPermissions
-
groupPermissions
-
projectPermissions
-
hasAnnotatableItem
private final boolean hasAnnotatableItem
-
-
Constructor Details
-
MultiPermissions
public MultiPermissions(Collection<? extends SharedItem> itemsToShare) throws InvalidDataException, BaseException Create a newMultiPermissions
object and feed it the collection ofShareable
items that you want to modify.- Parameters:
itemsToShare
- The collection of items- Throws:
InvalidDataException
- If the collection is null or emptyBaseException
- If there is another error
-
-
Method Details
-
allSame
Check if a collection ofSet
:s all contain the same permissions.- Parameters:
permissions
- The collection of sets to check- Returns:
- TRUE If all sets in the collection contains the same permissions
- See Also:
-
hasAnnotatableItem
public boolean hasAnnotatableItem()Is any of the items to share an annotatable item?- Since:
- 3.10
-
setPermissions
Grant permissions to a user. Use an emptySet
or null to remove all permissions for the user.- Parameters:
user
- TheUser
permissions
- The permissions to grant- Throws:
InvalidDataException
- If the user is null- See Also:
-
addPermissions
Grant permissions to a user, keeping those that have already been set.- Parameters:
user
- TheUser
permissions
- The permissions to grant- Throws:
InvalidDataException
- If the user is null- See Also:
-
getPermissions
Get the permissions for a user. The returned map contains one entry for each uniqueItemKey
found among the items passed to the constructor, including the null item key if present. The value of each entry is aSet
containing the granted permissions.- Parameters:
user
- TheUser
for which we want to get the permission- Returns:
- A
Map
containing aSet
of the granted permissions for eachItemKey
- Throws:
InvalidDataException
- If the user is null- See Also:
-
setPermissions
Grant permissions to a group. Use an emptySet
or null to remove all permissions for the group.- Parameters:
group
- TheGroup
permissions
- The permissions to grant- Throws:
InvalidDataException
- If the group is null- See Also:
-
addPermissions
Grant permissions to a group, keeping those that have already been set.- Parameters:
group
- TheGroup
permissions
- The permissions to grant- Throws:
InvalidDataException
- If the group is null- See Also:
-
getPermissions
Get the permissions for a group. The returned map contains one entry for each uniqueItemKey
found among the items passed to the constructor, including the null item key if present. The value of each entry is aSet
containing the granted permissions.- Parameters:
group
- TheGroup
for which we want to get the permission- Returns:
- A
Map
containing aSet
of the granted permissions for eachItemKey
- Throws:
InvalidDataException
- If the group is null- See Also:
-
setPermissions
public void setPermissions(Project project, Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException Grant permissions to a project. Use an emptySet
or null to remove all permissions for the project.- Parameters:
project
- TheProject
permissions
- The permissions to grant- Throws:
InvalidDataException
- If the project is nullPermissionDeniedException
- If the logged in user's doesn't havePermission.USE
permission to the project- See Also:
-
addPermissions
public void addPermissions(Project project, Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException Grant permissions to a project, keeping those that have already been set.- Parameters:
project
- TheProject
permissions
- The permissions to grant- Throws:
InvalidDataException
- If the project is nullPermissionDeniedException
- If the logged in user's doesn't havePermission.USE
permission to the project- See Also:
-
getPermissions
Get the permissions for a project. The returned map contains one entry for each uniqueProjectKey
found among the items passed to the constructor, including the null project key if present. The value of each entry is aSet
containing the granted permissions.- Parameters:
project
- TheProject
for which we want to get the permission- Returns:
- A
Map
containing aSet
of the granted permissions for eachProjectKey
- Throws:
InvalidDataException
- If the project is null- See Also:
-
merge
Merge the permissions from the given item key keeping those that has already been set.- Parameters:
itemKey
- An item key (if null, this method simply returns)- Since:
- 2.16
- See Also:
-
merge
Merge the permissions from the given project key keeping those that has already been set.- Parameters:
projectKey
- An project key (if null, this method simply returns)- Since:
- 2.16
- See Also:
-
getUsers
Get a query that returns all users appearing in at least one of the item keys. The query will not return users that the logged in user doesn't have permission to read. -
getGroups
Get a query that returns all groups appearing in at least one of the item keys. The query will not return groups that the logged in user doesn't have permission to read. -
getProjects
Get a query that returns all projects appearing in at least one of the project keys. The query will not return projects that the logged in user doesn't have permission to read. -
getItems
Returns the items that are handled within this class. -
getItems
Get all items of a specific item type. The returned set is never null, but may be empty if no items of the specified type was found.- Parameters:
type
- The item type to search for- Returns:
- A set with the items
- Since:
- 2.8
-
getItems
Get all items of specific item types. The returned set is never null, but may be empty if no items of the specified types was found.- Parameters:
types
- A collection with the item types to search for- Returns:
- A set with the items
- Since:
- 2.8
-
updateKeys
Generate the new keys and update all items with the new keys.- Parameters:
dc
- TheDbControl
object to use for database access- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.SET_PERMISSION
permission on all itemsBaseException
- If there is another error
-
updateKeys
public void updateKeys(DbControl dc, boolean recursive) throws PermissionDeniedException, BaseException Generate the new keys and update all items with the new keys.- Parameters:
dc
- TheDbControl
object to use for database accessrecursive
- If TRUE, files and subdirectories to a selected directory will also shared with the same permissions as the parent directory- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.SET_PERMISSION
permission on all itemsBaseException
- If there is another error- Since:
- 2.8
-