use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class IdentityServiceAuthorizationsTest method testUserUpdateAuthorizations.
public void testUserUpdateAuthorizations() {
// crate user while still in god-mode:
User jonny1 = identityService.newUser("jonny1");
identityService.saveUser(jonny1);
// create global auth
Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
basePerms.setResource(USER);
basePerms.setResourceId(ANY);
basePerms.addPermission(ALL);
// revoke update
basePerms.removePermission(UPDATE);
authorizationService.saveAuthorization(basePerms);
// turn on authorization
processEngineConfiguration.setAuthorizationEnabled(true);
identityService.setAuthenticatedUserId(jonny2);
// fetch user:
jonny1 = identityService.createUserQuery().singleResult();
jonny1.setFirstName("Jonny");
try {
identityService.saveUser(jonny1);
fail("exception expected");
} catch (AuthorizationException e) {
assertEquals(1, e.getMissingAuthorizations().size());
MissingAuthorization info = e.getMissingAuthorizations().get(0);
assertEquals(jonny2, e.getUserId());
assertExceptionInfo(UPDATE.getName(), USER.resourceName(), "jonny1", info);
}
// but I can create a new user:
User jonny3 = identityService.newUser("jonny3");
identityService.saveUser(jonny3);
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class IdentityServiceAuthorizationsTest method testGroupDeleteAuthorizations.
public void testGroupDeleteAuthorizations() {
// crate group while still in god-mode:
Group group1 = identityService.newGroup("group1");
identityService.saveGroup(group1);
// create global auth
Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
basePerms.setResource(GROUP);
basePerms.setResourceId(ANY);
basePerms.addPermission(ALL);
// revoke delete
basePerms.removePermission(DELETE);
authorizationService.saveAuthorization(basePerms);
// turn on authorization
processEngineConfiguration.setAuthorizationEnabled(true);
identityService.setAuthenticatedUserId(jonny2);
try {
identityService.deleteGroup("group1");
fail("exception expected");
} catch (AuthorizationException e) {
assertEquals(1, e.getMissingAuthorizations().size());
MissingAuthorization info = e.getMissingAuthorizations().get(0);
assertEquals(jonny2, e.getUserId());
assertExceptionInfo(DELETE.getName(), GROUP.resourceName(), "group1", info);
}
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class IdentityServiceAuthorizationsTest method testUserQueryAuthorizationsMultipleGroups.
public void testUserQueryAuthorizationsMultipleGroups() {
// we are jonny2
String authUserId = "jonny2";
identityService.setAuthenticatedUserId(authUserId);
User demo = identityService.newUser("demo");
identityService.saveUser(demo);
User mary = identityService.newUser("mary");
identityService.saveUser(mary);
User peter = identityService.newUser("peter");
identityService.saveUser(peter);
User john = identityService.newUser("john");
identityService.saveUser(john);
Group sales = identityService.newGroup("sales");
identityService.saveGroup(sales);
Group accounting = identityService.newGroup("accounting");
identityService.saveGroup(accounting);
Group management = identityService.newGroup("management");
identityService.saveGroup(management);
identityService.createMembership("demo", "sales");
identityService.createMembership("demo", "accounting");
identityService.createMembership("demo", "management");
identityService.createMembership("john", "sales");
identityService.createMembership("mary", "accounting");
identityService.createMembership("peter", "management");
Authorization demoAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
demoAuth.setUserId("demo");
demoAuth.setResource(USER);
demoAuth.setResourceId("demo");
demoAuth.addPermission(ALL);
authorizationService.saveAuthorization(demoAuth);
Authorization johnAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
johnAuth.setUserId("john");
johnAuth.setResource(USER);
johnAuth.setResourceId("john");
johnAuth.addPermission(ALL);
authorizationService.saveAuthorization(johnAuth);
Authorization maryAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
maryAuth.setUserId("mary");
maryAuth.setResource(USER);
maryAuth.setResourceId("mary");
maryAuth.addPermission(ALL);
authorizationService.saveAuthorization(maryAuth);
Authorization peterAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
peterAuth.setUserId("peter");
peterAuth.setResource(USER);
peterAuth.setResourceId("peter");
peterAuth.addPermission(ALL);
authorizationService.saveAuthorization(peterAuth);
Authorization accAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
accAuth.setGroupId("accounting");
accAuth.setResource(GROUP);
accAuth.setResourceId("accounting");
accAuth.addPermission(READ);
authorizationService.saveAuthorization(accAuth);
Authorization salesAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
salesAuth.setGroupId("sales");
salesAuth.setResource(GROUP);
salesAuth.setResourceId("sales");
salesAuth.addPermission(READ);
authorizationService.saveAuthorization(salesAuth);
Authorization manAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
manAuth.setGroupId("management");
manAuth.setResource(GROUP);
manAuth.setResourceId("management");
manAuth.addPermission(READ);
authorizationService.saveAuthorization(manAuth);
Authorization salesDemoAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
salesDemoAuth.setGroupId("sales");
salesDemoAuth.setResource(USER);
salesDemoAuth.setResourceId("demo");
salesDemoAuth.addPermission(READ);
authorizationService.saveAuthorization(salesDemoAuth);
Authorization salesJohnAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
salesJohnAuth.setGroupId("sales");
salesJohnAuth.setResource(USER);
salesJohnAuth.setResourceId("john");
salesJohnAuth.addPermission(READ);
authorizationService.saveAuthorization(salesJohnAuth);
Authorization manDemoAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
manDemoAuth.setGroupId("management");
manDemoAuth.setResource(USER);
manDemoAuth.setResourceId("demo");
manDemoAuth.addPermission(READ);
authorizationService.saveAuthorization(manDemoAuth);
Authorization manPeterAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
manPeterAuth.setGroupId("management");
manPeterAuth.setResource(USER);
manPeterAuth.setResourceId("peter");
manPeterAuth.addPermission(READ);
authorizationService.saveAuthorization(manPeterAuth);
Authorization accDemoAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
accDemoAuth.setGroupId("accounting");
accDemoAuth.setResource(USER);
accDemoAuth.setResourceId("demo");
accDemoAuth.addPermission(READ);
authorizationService.saveAuthorization(accDemoAuth);
Authorization accMaryAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
accMaryAuth.setGroupId("accounting");
accMaryAuth.setResource(USER);
accMaryAuth.setResourceId("mary");
accMaryAuth.addPermission(READ);
authorizationService.saveAuthorization(accMaryAuth);
List<String> groups = new ArrayList<String>();
groups.add("management");
groups.add("accounting");
groups.add("sales");
identityService.setAuthentication("demo", groups);
processEngineConfiguration.setAuthorizationEnabled(true);
List<User> salesUser = identityService.createUserQuery().memberOfGroup("sales").list();
assertEquals(2, salesUser.size());
for (User user : salesUser) {
if (!user.getId().equals("demo") && !user.getId().equals("john")) {
Assert.fail("Unexpected user for group sales: " + user.getId());
}
}
List<User> accountingUser = identityService.createUserQuery().memberOfGroup("accounting").list();
assertEquals(2, accountingUser.size());
for (User user : accountingUser) {
if (!user.getId().equals("demo") && !user.getId().equals("mary")) {
Assert.fail("Unexpected user for group accounting: " + user.getId());
}
}
List<User> managementUser = identityService.createUserQuery().memberOfGroup("management").list();
assertEquals(2, managementUser.size());
for (User user : managementUser) {
if (!user.getId().equals("demo") && !user.getId().equals("peter")) {
Assert.fail("Unexpected user for group managment: " + user.getId());
}
}
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class AuthorizationQueryTest method testOrderByQueries.
public void testOrderByQueries() {
Resource resource1 = new TestResource("resource1", 100);
Resource resource2 = new TestResource("resource2", 101);
List<Authorization> list = authorizationService.createAuthorizationQuery().orderByResourceType().asc().list();
assertEquals(resource1.resourceType(), list.get(0).getResourceType());
assertEquals(resource1.resourceType(), list.get(1).getResourceType());
assertEquals(resource1.resourceType(), list.get(2).getResourceType());
assertEquals(resource1.resourceType(), list.get(3).getResourceType());
assertEquals(resource2.resourceType(), list.get(4).getResourceType());
assertEquals(resource2.resourceType(), list.get(5).getResourceType());
assertEquals(resource2.resourceType(), list.get(6).getResourceType());
assertEquals(resource2.resourceType(), list.get(7).getResourceType());
list = authorizationService.createAuthorizationQuery().orderByResourceType().desc().list();
assertEquals(resource2.resourceType(), list.get(0).getResourceType());
assertEquals(resource2.resourceType(), list.get(1).getResourceType());
assertEquals(resource2.resourceType(), list.get(2).getResourceType());
assertEquals(resource2.resourceType(), list.get(3).getResourceType());
assertEquals(resource1.resourceType(), list.get(4).getResourceType());
assertEquals(resource1.resourceType(), list.get(5).getResourceType());
assertEquals(resource1.resourceType(), list.get(6).getResourceType());
assertEquals(resource1.resourceType(), list.get(7).getResourceType());
list = authorizationService.createAuthorizationQuery().orderByResourceId().asc().list();
assertEquals("resource1-1", list.get(0).getResourceId());
assertEquals("resource1-1", list.get(1).getResourceId());
assertEquals("resource1-2", list.get(2).getResourceId());
assertEquals("resource1-2", list.get(3).getResourceId());
assertEquals("resource2-1", list.get(4).getResourceId());
assertEquals("resource2-1", list.get(5).getResourceId());
assertEquals("resource2-2", list.get(6).getResourceId());
assertEquals("resource2-3", list.get(7).getResourceId());
list = authorizationService.createAuthorizationQuery().orderByResourceId().desc().list();
assertEquals("resource2-3", list.get(0).getResourceId());
assertEquals("resource2-2", list.get(1).getResourceId());
assertEquals("resource2-1", list.get(2).getResourceId());
assertEquals("resource2-1", list.get(3).getResourceId());
assertEquals("resource1-2", list.get(4).getResourceId());
assertEquals("resource1-2", list.get(5).getResourceId());
assertEquals("resource1-1", list.get(6).getResourceId());
assertEquals("resource1-1", list.get(7).getResourceId());
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class AuthorizationQueryTest method tearDown.
protected void tearDown() throws Exception {
List<Authorization> list = authorizationService.createAuthorizationQuery().list();
for (Authorization authorization : list) {
authorizationService.deleteAuthorization(authorization.getId());
}
super.tearDown();
}
Aggregations