use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class FilterAuthorizationsTest method testReadFilterPermittedWithMultiple.
public void testReadFilterPermittedWithMultiple() {
Filter filter = createTestFilter();
grantReadFilter(filter.getId());
Authorization authorization = processEngine.getAuthorizationService().createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
authorization.addPermission(Permissions.READ);
authorization.setUserId(Authorization.ANY);
authorization.setResource(Resources.FILTER);
authorization.setResourceId(Authorization.ANY);
processEngine.getAuthorizationService().saveAuthorization(authorization);
long count = filterService.createFilterQuery().count();
assertEquals(1, count);
Filter returnedFilter = filterService.createFilterQuery().filterId(filter.getId()).singleResult();
assertNotNull(returnedFilter);
returnedFilter = filterService.getFilter(filter.getId());
assertNotNull(returnedFilter);
processEngine.getAuthorizationService().deleteAuthorization(authorization.getId());
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class FilterAuthorizationsTest method createAuthorization.
protected Authorization createAuthorization(Permission permission, String resourceId) {
Authorization authorization = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
authorization.setUserId(testUser.getId());
authorization.setResource(Resources.FILTER);
authorization.addPermission(permission);
if (resourceId != null) {
authorization.setResourceId(resourceId);
}
return authorization;
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class AuthorizationServiceTest method testCreateAuthorizationWithUserId.
public void testCreateAuthorizationWithUserId() {
TestResource resource1 = new TestResource("resource1", 100);
// initially, no authorization exists:
assertEquals(0, authorizationService.createAuthorizationQuery().count());
// simple create / delete with userId
Authorization authorization = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
authorization.setUserId("aUserId");
authorization.setResource(resource1);
// save the authorization
authorizationService.saveAuthorization(authorization);
// authorization exists
assertEquals(1, authorizationService.createAuthorizationQuery().count());
// delete the authorization
authorizationService.deleteAuthorization(authorization.getId());
// it's gone
assertEquals(0, authorizationService.createAuthorizationQuery().count());
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class AuthorizationServiceTest method testPermissions.
public void testPermissions() {
Authorization authorization = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
assertEquals(1, authorization.getPermissions(Permissions.values()).length);
assertFalse(authorization.isPermissionGranted(ACCESS));
assertFalse(authorization.isPermissionGranted(DELETE));
assertFalse(authorization.isPermissionGranted(READ));
assertFalse(authorization.isPermissionGranted(UPDATE));
authorization.addPermission(ACCESS);
assertTrue(authorization.isPermissionGranted(ACCESS));
assertFalse(authorization.isPermissionGranted(DELETE));
assertFalse(authorization.isPermissionGranted(READ));
assertFalse(authorization.isPermissionGranted(UPDATE));
authorization.addPermission(DELETE);
assertTrue(authorization.isPermissionGranted(ACCESS));
assertTrue(authorization.isPermissionGranted(DELETE));
assertFalse(authorization.isPermissionGranted(READ));
assertFalse(authorization.isPermissionGranted(UPDATE));
authorization.addPermission(READ);
assertTrue(authorization.isPermissionGranted(ACCESS));
assertTrue(authorization.isPermissionGranted(DELETE));
assertTrue(authorization.isPermissionGranted(READ));
assertFalse(authorization.isPermissionGranted(UPDATE));
authorization.addPermission(UPDATE);
assertTrue(authorization.isPermissionGranted(ACCESS));
assertTrue(authorization.isPermissionGranted(DELETE));
assertTrue(authorization.isPermissionGranted(READ));
assertTrue(authorization.isPermissionGranted(UPDATE));
authorization.removePermission(ACCESS);
assertFalse(authorization.isPermissionGranted(ACCESS));
assertTrue(authorization.isPermissionGranted(DELETE));
assertTrue(authorization.isPermissionGranted(READ));
assertTrue(authorization.isPermissionGranted(UPDATE));
authorization.removePermission(DELETE);
assertFalse(authorization.isPermissionGranted(ACCESS));
assertFalse(authorization.isPermissionGranted(DELETE));
assertTrue(authorization.isPermissionGranted(READ));
assertTrue(authorization.isPermissionGranted(UPDATE));
authorization.removePermission(READ);
assertFalse(authorization.isPermissionGranted(ACCESS));
assertFalse(authorization.isPermissionGranted(DELETE));
assertFalse(authorization.isPermissionGranted(READ));
assertTrue(authorization.isPermissionGranted(UPDATE));
authorization.removePermission(UPDATE);
assertFalse(authorization.isPermissionGranted(ACCESS));
assertFalse(authorization.isPermissionGranted(DELETE));
assertFalse(authorization.isPermissionGranted(READ));
assertFalse(authorization.isPermissionGranted(UPDATE));
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class AuthorizationServiceTest method testGlobalGrantAuthorizationCheck.
public void testGlobalGrantAuthorizationCheck() {
TestResource resource1 = new TestResource("resource1", 100);
// create global authorization which grants all permissions to all users (on resource1):
Authorization globalAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
globalAuth.setResource(resource1);
globalAuth.setResourceId(ANY);
globalAuth.addPermission(ALL);
authorizationService.saveAuthorization(globalAuth);
List<String> jonnysGroups = Arrays.asList(new String[] { "sales", "marketing" });
List<String> someOneElsesGroups = Arrays.asList(new String[] { "marketing" });
// this authorizes any user to do anything in this resource:
assertTrue(authorizationService.isUserAuthorized("jonny", null, ALL, resource1));
assertTrue(authorizationService.isUserAuthorized("jonny", jonnysGroups, ALL, resource1));
assertTrue(authorizationService.isUserAuthorized("someone", null, CREATE, resource1));
assertTrue(authorizationService.isUserAuthorized("someone", someOneElsesGroups, CREATE, resource1));
assertTrue(authorizationService.isUserAuthorized("someone else", null, DELETE, resource1));
assertTrue(authorizationService.isUserAuthorized("jonny", null, ALL, resource1, "someId"));
assertTrue(authorizationService.isUserAuthorized("jonny", jonnysGroups, ALL, resource1, "someId"));
assertTrue(authorizationService.isUserAuthorized("someone", null, CREATE, resource1, "someId"));
assertTrue(authorizationService.isUserAuthorized("someone else", null, DELETE, resource1, "someOtherId"));
}
Aggregations