Interface PermissionService
-
- All Superinterfaces:
com.nomagic.ci.persistence.services.IProjectService
@OpenApiAll public interface PermissionService extends com.nomagic.ci.persistence.services.IProjectService
An interface for manipulation of package level permissions. This allows clients to query existing permissions, modify or add new permissions accordingly.
In order to start manipulating or reading permissions, one must obtain an implementation of
service
first. This can be achieved by callingServiceable.getService(Class)
method on an instance ofIPrimaryProject
:IPrimaryProject project = Application.getInstance().getProjectsManager() .getActiveProject().getPrimaryProject(); PermissionService service = project.getService(PermissionService.class);
To modify
permissions
client should use setters that are exposed inPackageAccessPermission
. Code below iterates over allpermissions
of an arbitrarypackage
and sets access mode of each permission toread-write
:Package pack = ... // some arbitrary package PackagePermissions permissions = service.getPermissions(pack); for (PackageAccessPermission p : permissions.getAccessPermissions()) { p.setAction(Action.READ_WRITE); }
SecurityFactory
can be used to create newpackage permissions
. Just createdpackage permission
should be added to a packagepermissions list
:PackageAccessPermission newPermission = SecurityFactory.eINSTANCE.createPackageAccessPermission(); newPermission.setAction(Action.READ_WRITE); newPermission.setApplication(com.nomagic.magicdraw.security.Application.PACKAGE_AND_SUBPACKAGES); newPermission.setPrincipal(SecurityFactory.eINSTANCE.createEveryonePrincipal()); service.getPermissions(pack).getAccessPermissions().add(newPermission);
- Version:
- 1.0
- See Also:
SecurityFactory
,PackageAccessPermission
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
getChangeNumber()
Returns number how many times permissions were locally changed.PackagePermissions
getPermissions(Package aPackage)
Returns current permissions of the specified package.<T extends Principal>
TgetPrincipal(java.lang.String name, java.lang.Class<T> type)
Returns a principal of the specified name and type.java.util.Map<java.lang.String,PackagePermissions>
getProjectPermissions()
Method returns all permissions from the currently active project.boolean
hasPermissions(Package aPackage)
Returns whether the specified package has permissions set.void
setChanged()
Sets that package permissions has changedvoid
setPermissions(Package aPackage, PackagePermissions permissions)
Sets permissions for the specified package.
-
-
-
Method Detail
-
getPermissions
PackagePermissions getPermissions(Package aPackage) throws PermissionException
Returns current permissions of the specified package. The returned object is persistent and any modification will persisted on the project resource commit.- Parameters:
aPackage
- a package.- Returns:
- list of permissions.
- Throws:
PermissionException
-
hasPermissions
boolean hasPermissions(Package aPackage) throws PermissionException
Returns whether the specified package has permissions set.- Parameters:
aPackage
- a package.- Returns:
- true if the package has permissions.
- Throws:
PermissionException
-
setPermissions
void setPermissions(Package aPackage, @CheckForNull PackagePermissions permissions) throws PermissionException
Sets permissions for the specified package. After the completion the specified permissions become persistent and any modification of the permissions will be saved on the project resource commit.- Parameters:
aPackage
- a package.permissions
- a package permissions.- Throws:
PermissionException
- identifies that the method invocation failed. The message or the cause can be checked to find the reason of the problem.
-
getPrincipal
<T extends Principal> T getPrincipal(java.lang.String name, java.lang.Class<T> type) throws PermissionException
Returns a principal of the specified name and type.- Type Parameters:
T
- any object that extendsPrincipal
class.- Parameters:
name
- name of the principal.type
- type of the principal.- Returns:
- a principal.
- Throws:
PermissionException
- identifies that the method invocation failed. The message or the cause can be checked to find the reason of the problem.
-
getProjectPermissions
java.util.Map<java.lang.String,PackagePermissions> getProjectPermissions() throws PermissionException
Method returns all permissions from the currently active project.- Returns:
- map of current project permissions
- Throws:
PermissionException
- identifies that method invocation failed. The message or the cause can be checked to find the reason of the problem.
-
getChangeNumber
int getChangeNumber() throws PermissionException
Returns number how many times permissions were locally changed.- Returns:
- number how many times permissions were locally changed
- Throws:
PermissionException
- identifies that method invocation failed. The message or the cause can be checked to find the reason of the problem.
-
setChanged
void setChanged() throws PermissionException
Sets that package permissions has changed- Throws:
PermissionException
- identifies that method invocation failed. The message or the cause can be checked to find the reason of the problem.
-
-