use of org.camunda.bpm.engine.identity.Tenant in project camunda-bpm-platform by camunda.
the class IdentityServiceAuthorizationsTest method testTenanGroupMembershipDeleteAuthorizations.
public void testTenanGroupMembershipDeleteAuthorizations() {
Group group1 = identityService.newGroup("group1");
identityService.saveGroup(group1);
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.deleteTenantGroupMembership("tenant1", "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(), TENANT_MEMBERSHIP.resourceName(), "tenant1", info);
}
}
use of org.camunda.bpm.engine.identity.Tenant in project camunda-bpm-platform by camunda.
the class IdentityServiceAuthorizationsTest method testTenantUpdateAuthorizations.
public void testTenantUpdateAuthorizations() {
// create tenant
Tenant tenant = new TenantEntity("tenant");
identityService.saveTenant(tenant);
// create global auth
Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
basePerms.setResource(TENANT);
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:
tenant = identityService.createTenantQuery().singleResult();
tenant.setName("newName");
try {
identityService.saveTenant(tenant);
fail("exception expected");
} catch (AuthorizationException e) {
assertEquals(1, e.getMissingAuthorizations().size());
MissingAuthorization info = e.getMissingAuthorizations().get(0);
assertEquals(jonny2, e.getUserId());
assertExceptionInfo(UPDATE.getName(), TENANT.resourceName(), "tenant", info);
}
// but I can create a new tenant:
Tenant newTenant = identityService.newTenant("newTenant");
identityService.saveTenant(newTenant);
}
use of org.camunda.bpm.engine.identity.Tenant in project camunda-bpm-platform by camunda.
the class IdentityServiceAuthorizationsTest method testTenantGroupMembershipCreateAuthorizations.
public void testTenantGroupMembershipCreateAuthorizations() {
Group group1 = identityService.newGroup("group1");
identityService.saveGroup(group1);
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.createTenantGroupMembership("tenant1", "group1");
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.identity.Tenant in project camunda-bpm-platform by camunda.
the class PurgeDatabaseTest method createAuthenticationData.
private void createAuthenticationData() {
IdentityService identityService = engineRule.getIdentityService();
Group group = identityService.newGroup("group");
identityService.saveGroup(group);
User user = identityService.newUser("user");
User user2 = identityService.newUser("user2");
identityService.saveUser(user);
identityService.saveUser(user2);
Tenant tenant = identityService.newTenant("tenant");
identityService.saveTenant(tenant);
Tenant tenant2 = identityService.newTenant("tenant2");
identityService.saveTenant(tenant2);
identityService.createMembership("user", "group");
identityService.createTenantUserMembership("tenant", "user");
identityService.createTenantUserMembership("tenant2", "user2");
TestResource resource1 = new TestResource("resource1", 100);
// create global authorization which grants all permissions to all users (on resource1):
AuthorizationService authorizationService = engineRule.getAuthorizationService();
Authorization globalAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
globalAuth.setResource(resource1);
globalAuth.setResourceId(ANY);
globalAuth.addPermission(ALL);
authorizationService.saveAuthorization(globalAuth);
// grant user read auth on resource2
TestResource resource2 = new TestResource("resource2", 200);
Authorization userGrant = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
userGrant.setUserId("user");
userGrant.setResource(resource2);
userGrant.setResourceId(ANY);
userGrant.addPermission(READ);
authorizationService.saveAuthorization(userGrant);
identityService.setAuthenticatedUserId("user");
}
use of org.camunda.bpm.engine.identity.Tenant in project camunda-bpm-platform by camunda.
the class TenantRestServiceInteractionTest method updateTenant.
@Test
public void updateTenant() {
Tenant updatedTenant = MockProvider.createMockTenant();
when(updatedTenant.getName()).thenReturn("updatedName");
given().pathParam("id", MockProvider.EXAMPLE_TENANT_ID).body(TenantDto.fromTenant(updatedTenant)).contentType(ContentType.JSON).then().expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().put(TENANT_URL);
// tenant was updated
verify(mockTenant).setName(updatedTenant.getName());
// and then saved
verify(identityServiceMock).saveTenant(mockTenant);
}
Aggregations