use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class DefaultAuthorizationProviderTest method setUp.
protected void setUp() throws Exception {
// we are jonny
identityService.setAuthenticatedUserId("jonny");
// make sure we can do stuff:
Authorization jonnyIsGod = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
jonnyIsGod.setUserId("jonny");
jonnyIsGod.setResource(USER);
jonnyIsGod.setResourceId(ANY);
jonnyIsGod.addPermission(ALL);
authorizationService.saveAuthorization(jonnyIsGod);
jonnyIsGod = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
jonnyIsGod.setUserId("jonny");
jonnyIsGod.setResource(GROUP);
jonnyIsGod.setResourceId(ANY);
jonnyIsGod.addPermission(ALL);
authorizationService.saveAuthorization(jonnyIsGod);
jonnyIsGod = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
jonnyIsGod.setUserId("jonny");
jonnyIsGod.setResource(AUTHORIZATION);
jonnyIsGod.setResourceId(ANY);
jonnyIsGod.addPermission(ALL);
authorizationService.saveAuthorization(jonnyIsGod);
// enable authorizations
processEngineConfiguration.setAuthorizationEnabled(true);
super.setUp();
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class DefaultAuthorizationProviderTest method tearDown.
protected void tearDown() throws Exception {
processEngineConfiguration.setAuthorizationEnabled(false);
List<Authorization> jonnysAuths = authorizationService.createAuthorizationQuery().userIdIn("jonny").list();
for (Authorization authorization : jonnysAuths) {
authorizationService.deleteAuthorization(authorization.getId());
}
super.tearDown();
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class DefaultAuthorizationProviderTest method testCreateUser.
public void testCreateUser() {
// initially there are no authorizations for jonny2:
assertEquals(0, authorizationService.createAuthorizationQuery().userIdIn("jonny2").count());
// create new user
identityService.saveUser(identityService.newUser("jonny2"));
// now there is an authorization for jonny2 which grants him ALL permissions on himself
Authorization authorization = authorizationService.createAuthorizationQuery().userIdIn("jonny2").singleResult();
assertNotNull(authorization);
assertEquals(AUTH_TYPE_GRANT, authorization.getAuthorizationType());
assertEquals(USER.resourceType(), authorization.getResourceType());
assertEquals("jonny2", authorization.getResourceId());
assertTrue(authorization.isPermissionGranted(ALL));
// delete the user
identityService.deleteUser("jonny2");
// the authorization is deleted as well:
assertEquals(0, authorizationService.createAuthorizationQuery().userIdIn("jonny2").count());
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class IdentityServiceAuthorizationsTest method testTenantUserMembershipCreateAuthorizations.
public void testTenantUserMembershipCreateAuthorizations() {
User jonny1 = identityService.newUser("jonny1");
identityService.saveUser(jonny1);
Tenant tenant1 = identityService.newTenant("tenant1");
identityService.saveTenant(tenant1);
// add base permission which allows nobody to create memberships
Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
basePerms.setResource(TENANT_MEMBERSHIP);
basePerms.setResourceId(ANY);
// add all then remove 'create'
basePerms.addPermission(ALL);
basePerms.removePermission(CREATE);
authorizationService.saveAuthorization(basePerms);
processEngineConfiguration.setAuthorizationEnabled(true);
identityService.setAuthenticatedUserId(jonny2);
try {
identityService.createTenantUserMembership("tenant1", "jonny1");
fail("exception expected");
} catch (AuthorizationException e) {
assertEquals(1, e.getMissingAuthorizations().size());
MissingAuthorization info = e.getMissingAuthorizations().get(0);
assertEquals(jonny2, e.getUserId());
assertExceptionInfo(CREATE.getName(), TENANT_MEMBERSHIP.resourceName(), "tenant1", info);
}
}
use of org.camunda.bpm.engine.authorization.Authorization in project camunda-bpm-platform by camunda.
the class IdentityServiceAuthorizationsTest method testTenantUserMembershipDeleteAuthorizations.
public void testTenantUserMembershipDeleteAuthorizations() {
User jonny1 = identityService.newUser("jonny1");
identityService.saveUser(jonny1);
Tenant tenant1 = identityService.newTenant("tenant1");
identityService.saveTenant(tenant1);
// add base permission which allows nobody to delete memberships
Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
basePerms.setResource(TENANT_MEMBERSHIP);
basePerms.setResourceId(ANY);
// add all then remove 'delete'
basePerms.addPermission(ALL);
basePerms.removePermission(DELETE);
authorizationService.saveAuthorization(basePerms);
processEngineConfiguration.setAuthorizationEnabled(true);
identityService.setAuthenticatedUserId(jonny2);
try {
identityService.deleteTenantUserMembership("tenant1", "jonny1");
fail("exception expected");
} catch (AuthorizationException e) {
assertEquals(1, e.getMissingAuthorizations().size());
MissingAuthorization info = e.getMissingAuthorizations().get(0);
assertEquals(jonny2, e.getUserId());
assertExceptionInfo(DELETE.getName(), TENANT_MEMBERSHIP.resourceName(), "tenant1", info);
}
}
Aggregations