@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);
SecurityFactory
,
PackageAccessPermission
Modifier and Type | Method and Description |
---|---|
int |
getChangeNumber()
Returns number how many times permissions were locally changed.
|
com.nomagic.magicdraw.security.PackagePermissions |
getPermissions(Package aPackage)
Returns current permissions of the specified package.
|
<T extends com.nomagic.magicdraw.security.Principal> |
getPrincipal(java.lang.String name,
java.lang.Class<T> type)
Returns a principal of the specified name and type.
|
java.util.Map<java.lang.String,com.nomagic.magicdraw.security.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 changed
|
void |
setPermissions(Package aPackage,
com.nomagic.magicdraw.security.PackagePermissions permissions)
Sets permissions for the specified package.
|
com.nomagic.magicdraw.security.PackagePermissions getPermissions(Package aPackage) throws PermissionException
aPackage
- a package.PermissionException
boolean hasPermissions(Package aPackage) throws PermissionException
aPackage
- a package.PermissionException
void setPermissions(Package aPackage, @CheckForNull com.nomagic.magicdraw.security.PackagePermissions permissions) throws PermissionException
aPackage
- a package.permissions
- a package permissions.PermissionException
- identifies that the method invocation failed. The message or the cause can be
checked to find the reason of the problem.<T extends com.nomagic.magicdraw.security.Principal> T getPrincipal(java.lang.String name, java.lang.Class<T> type) throws PermissionException
T
- any object that extends Principal
class.name
- name of the principal.type
- type of the principal.PermissionException
- identifies that the method invocation failed. The message or the cause can be
checked to find the reason of the problem.java.util.Map<java.lang.String,com.nomagic.magicdraw.security.PackagePermissions> getProjectPermissions() throws PermissionException
PermissionException
- identifies that method invocation failed. The message or the cause can be
checked to find the reason of the problem.int getChangeNumber() throws PermissionException
PermissionException
- identifies that method invocation failed. The message or the cause can be
checked to find the reason of the problem.void setChanged() throws PermissionException
PermissionException
- identifies that method invocation failed. The message or the cause can be
checked to find the reason of the problem.