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 calling Serviceable.getService(Class) method on an instance of IPrimaryProject:


 IPrimaryProject project = Application.getInstance().getProjectsManager()
     .getActiveProject().getPrimaryProject();
 PermissionService service = project.getService(PermissionService.class);
 

To modify permissions client should use setters that are exposed in PackageAccessPermission. Code below iterates over all permissions of an arbitrary package and sets access mode of each permission to read-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 new package permissions. Just created package permission should be added to a package permissions 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:
  • Method Details

    • 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(String name, Class<T> type) throws PermissionException
      Returns a principal of the specified name and type.
      Type Parameters:
      T - any object that extends Principal 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

      Map<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.