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 Summary
Modifier and TypeMethodDescriptionint
Returns number how many times permissions were locally changed.getPermissions
(Package aPackage) Returns current permissions of the specified package.<T extends Principal>
TgetPrincipal
(String name, Class<T> type) Returns a principal of the specified name and type.Method returns all permissions from the currently active project.boolean
hasPermissions
(Package aPackage) Returns whether the specified package has permissions set.void
Sets that package permissions has changedvoid
setPermissions
(Package aPackage, PackagePermissions permissions) Sets permissions for the specified package.Methods inherited from interface com.nomagic.ci.persistence.services.IProjectService
getProject
-
Method Details
-
getPermissions
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
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
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
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
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
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.
-