Interface PermissionService
-
- All Superinterfaces:
com.nomagic.ci.persistence.services.IProjectService
@OpenApiAll public interface PermissionService extends com.nomagic.ci.persistence.services.IProjectServiceAn 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
servicefirst. 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
permissionsclient should use setters that are exposed inPackageAccessPermission. Code below iterates over allpermissionsof an arbitrarypackageand 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); }SecurityFactorycan be used to create newpackage permissions. Just createdpackage permissionshould 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);- See Also:
SecurityFactory,PackageAccessPermission
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intgetChangeNumber()Returns number how many times permissions were locally changed.PackagePermissionsgetPermissions(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.booleanhasPermissions(Package aPackage)Returns whether the specified package has permissions set.voidsetChanged()Sets that package permissions has changedvoidsetPermissions(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 extendsPrincipalclass.- 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 PermissionExceptionReturns 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 PermissionExceptionSets 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.
-
-