Class BranchPermissionsManager
java.lang.Object
com.activeviam.tech.mvcc.api.security.impl.BranchPermissionsManager
- All Implemented Interfaces:
IBranchPermissionsManager
Simple implementation of the
IBranchPermissionsManager
, with a map associating a BranchPermissions
to each branch name.- Author:
- ActiveViam
-
Constructor Summary
ConstructorsConstructorDescriptionBranchPermissionsManager
(Set<String> allowedBranchCreators, Set<String> defaultOwnerPermissions, Set<String> defaultReaderPermissions) Constructor ofBranchPermissionsManager
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canCreateBranch
(Set<String> userNameAndRoles) Given their username and their roles, returnstrue
if the current user can create a branch,false
otherwise.static BranchPermissionsManager
forTests()
Gets aBranchPermissionsManager
which allows all users to create, read and edit all branches.getBranchPermissions
(String branchName) Gets the permissions of a specific branch.getOwnedBranches
(Set<String> userRoles) Gets the set of branches (registered in this service) that the user with the given roles own.getReadableBranches
(Set<String> userRoles) Gets the set of branches (registered in this service) that the given roles can read.void
registerBranchPermissionsListener
(IBranchPermissionsListener branchPermissionsListener) Registers a listener for the permissions of a set of branches.void
removeBranchPermissions
(String branchName) Removes the branch's permissions from the service.void
setBranchPermissions
(String branchName, IBranchPermissions permissions) Sets the permissions of a specific branch.void
unregisterBranchPermissionsListener
(IBranchPermissionsListener branchPermissionsListener) Unregisters a listener for the permissions of a set of branches.static BranchPermissionsManager
Gets aBranchPermissionsManager
which allows all users to create, read and edit all branches.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.activeviam.tech.mvcc.api.security.IBranchPermissionsManager
canDeleteBranch, canEditBranch, canReadBranch
-
Constructor Details
-
BranchPermissionsManager
public BranchPermissionsManager(Set<String> allowedBranchCreators, Set<String> defaultOwnerPermissions, Set<String> defaultReaderPermissions) Constructor ofBranchPermissionsManager
. Null values or empty sets are interpreted as "no user has the permission for [...]"; useIBranchPermissions.ALL_USERS_ALLOWED
for "all users have the permission for [...]".- Parameters:
allowedBranchCreators
- the set of users and roles allowed to create branches, useIBranchPermissions.ALL_USERS_ALLOWED
to allow all users to create branchesdefaultOwnerPermissions
- the default set of users who own branches, it is the fallback to retrieve user write permissions in the case where a branch exists but was not registered in this manager, useIBranchPermissions.ALL_USERS_ALLOWED
to allow all users to edit branchesdefaultReaderPermissions
- the default set of users who can read branches, it is the fallback to retrieve user read permissions in the case where a branch exists but was not registered in this manager, useIBranchPermissions.ALL_USERS_ALLOWED
to allow all users to read branches
-
-
Method Details
-
withoutRestrictions
Gets aBranchPermissionsManager
which allows all users to create, read and edit all branches. -
forTests
Gets aBranchPermissionsManager
which allows all users to create, read and edit all branches.- Returns:
- a new
BranchPermissionsManager
with all users allowed for all operations
-
canCreateBranch
Description copied from interface:IBranchPermissionsManager
Given their username and their roles, returnstrue
if the current user can create a branch,false
otherwise.- Specified by:
canCreateBranch
in interfaceIBranchPermissionsManager
- Parameters:
userNameAndRoles
- the current user's set of roles/name- Returns:
true
if the current user can create a branch,false
otherwise
-
removeBranchPermissions
Description copied from interface:IBranchPermissionsManager
Removes the branch's permissions from the service. The default permissions for this manager will become the new permissions of this branch.- Specified by:
removeBranchPermissions
in interfaceIBranchPermissionsManager
- Parameters:
branchName
- the name of the branch which will be removed
-
getBranchPermissions
Description copied from interface:IBranchPermissionsManager
Gets the permissions of a specific branch.- Specified by:
getBranchPermissions
in interfaceIBranchPermissionsManager
- Parameters:
branchName
- the name of the branch of which we want to know the permissions- Returns:
- the permissions for this branch
-
getOwnedBranches
Description copied from interface:IBranchPermissionsManager
Gets the set of branches (registered in this service) that the user with the given roles own.- Specified by:
getOwnedBranches
in interfaceIBranchPermissionsManager
- Parameters:
userRoles
- the given user's authorized roles- Returns:
- the set of branches (registered in this service) that the user with the given roles owns
-
getReadableBranches
Description copied from interface:IBranchPermissionsManager
Gets the set of branches (registered in this service) that the given roles can read.- Specified by:
getReadableBranches
in interfaceIBranchPermissionsManager
- Parameters:
userRoles
- the given user's authorized roles- Returns:
- the set of branches (registered in this service) that the given user can read
-
setBranchPermissions
Description copied from interface:IBranchPermissionsManager
Sets the permissions of a specific branch.- Specified by:
setBranchPermissions
in interfaceIBranchPermissionsManager
- Parameters:
branchName
- the name of the branch of which we want to edit the permissionspermissions
- the updated permissions for this branch
-
registerBranchPermissionsListener
Description copied from interface:IBranchPermissionsManager
Registers a listener for the permissions of a set of branches.- Specified by:
registerBranchPermissionsListener
in interfaceIBranchPermissionsManager
- Parameters:
branchPermissionsListener
- the listener which should be registered
-
unregisterBranchPermissionsListener
public void unregisterBranchPermissionsListener(IBranchPermissionsListener branchPermissionsListener) Description copied from interface:IBranchPermissionsManager
Unregisters a listener for the permissions of a set of branches.- Specified by:
unregisterBranchPermissionsListener
in interfaceIBranchPermissionsManager
- Parameters:
branchPermissionsListener
- the listener which should be unregistered
-