use of org.camunda.bpm.engine.authorization.Permission in project camunda-bpm-platform by camunda.
the class DefaultAuthorizationProvider method updateAuthorization.
protected AuthorizationEntity updateAuthorization(AuthorizationEntity authorization, String userId, String groupId, Resource resource, String resourceId, Permission... permissions) {
if (authorization == null) {
authorization = createGrantAuthorization(userId, groupId, resource, resourceId);
updateAuthorizationBasedOnCacheEntries(authorization, userId, groupId, resource, resourceId);
}
if (permissions != null) {
for (Permission permission : permissions) {
authorization.addPermission(permission);
}
}
return authorization;
}
use of org.camunda.bpm.engine.authorization.Permission in project camunda-bpm-platform by camunda.
the class AuthorizationServiceTest method testGlobalAuthPermissions.
public void testGlobalAuthPermissions() {
AuthorizationEntity authorization = new AuthorizationEntity(AUTH_TYPE_GRANT);
assertFalse(authorization.isPermissionGranted(ALL));
assertTrue(authorization.isPermissionGranted(NONE));
List<Permission> perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
assertTrue(perms.contains(NONE));
assertEquals(1, perms.size());
authorization.addPermission(READ);
perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
assertTrue(perms.contains(NONE));
assertTrue(perms.contains(READ));
assertEquals(2, perms.size());
assertTrue(authorization.isPermissionGranted(READ));
// (none is always granted => you are always authorized to do nothing)
assertTrue(authorization.isPermissionGranted(NONE));
try {
authorization.isPermissionRevoked(READ);
fail("Exception expected");
} catch (IllegalStateException e) {
assertTextPresent("ENGINE-03026 Method 'isPermissionRevoked' cannot be used for authorization with type 'GRANT'.", e.getMessage());
}
}
use of org.camunda.bpm.engine.authorization.Permission in project camunda-bpm-platform by camunda.
the class AuthorizationServiceTest method testRevokeAuthPermissions.
public void testRevokeAuthPermissions() {
AuthorizationEntity authorization = new AuthorizationEntity(AUTH_TYPE_REVOKE);
assertFalse(authorization.isPermissionRevoked(ALL));
List<Permission> perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
assertEquals(0, perms.size());
authorization.removePermission(READ);
perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
assertTrue(perms.contains(READ));
assertTrue(perms.contains(ALL));
assertEquals(2, perms.size());
try {
authorization.isPermissionGranted(READ);
fail("Exception expected");
} catch (IllegalStateException e) {
assertTextPresent("ENGINE-03026 Method 'isPermissionGranted' cannot be used for authorization with type 'REVOKE'.", e.getMessage());
}
}
use of org.camunda.bpm.engine.authorization.Permission in project camunda-bpm-platform by camunda.
the class AuthorizationServiceTest method testGrantAuthPermissions.
public void testGrantAuthPermissions() {
AuthorizationEntity authorization = new AuthorizationEntity(AUTH_TYPE_GRANT);
assertFalse(authorization.isPermissionGranted(ALL));
assertTrue(authorization.isPermissionGranted(NONE));
List<Permission> perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
assertTrue(perms.contains(NONE));
assertEquals(1, perms.size());
authorization.addPermission(READ);
perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
assertTrue(perms.contains(NONE));
assertTrue(perms.contains(READ));
assertEquals(2, perms.size());
assertTrue(authorization.isPermissionGranted(READ));
// (none is always granted => you are always authorized to do nothing)
assertTrue(authorization.isPermissionGranted(NONE));
try {
authorization.isPermissionRevoked(READ);
fail("Exception expected");
} catch (IllegalStateException e) {
assertTextPresent("ENGINE-03026 Method 'isPermissionRevoked' cannot be used for authorization with type 'GRANT'.", e.getMessage());
}
}
use of org.camunda.bpm.engine.authorization.Permission in project camunda-bpm-platform by camunda.
the class AuthorizationTest method createGrantAuthorization.
// authorization ///////////////////////////////////////////////////////
protected void createGrantAuthorization(Resource resource, String resourceId, String userId, Permission... permissions) {
Authorization authorization = createGrantAuthorization(resource, resourceId);
authorization.setUserId(userId);
for (Permission permission : permissions) {
authorization.addPermission(permission);
}
saveAuthorization(authorization);
}
Aggregations