Search in sources :

Example 21 with Tenant

use of org.camunda.bpm.engine.identity.Tenant in project camunda-bpm-platform by camunda.

the class IdentityServiceTenantTest method createTenantMembershipUnexistingUser.

@Test
public void createTenantMembershipUnexistingUser() {
    Tenant tenant = identityService.newTenant(TENANT_ONE);
    identityService.saveTenant(tenant);
    thrown.expect(ProcessEngineException.class);
    thrown.expectMessage("No user found with id 'nonExisting'.");
    identityService.createTenantUserMembership(tenant.getId(), "nonExisting");
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) Test(org.junit.Test)

Example 22 with Tenant

use of org.camunda.bpm.engine.identity.Tenant in project camunda-bpm-platform by camunda.

the class IdentityServiceTenantTest method deleteTenantMembershipsWhileDeleteGroup.

@Test
public void deleteTenantMembershipsWhileDeleteGroup() {
    Tenant tenant = identityService.newTenant(TENANT_ONE);
    identityService.saveTenant(tenant);
    Group group = identityService.newGroup(GROUP_ONE);
    identityService.saveGroup(group);
    identityService.createTenantGroupMembership(TENANT_ONE, GROUP_ONE);
    TenantQuery query = identityService.createTenantQuery().groupMember(GROUP_ONE);
    assertThat(query.count(), is(1L));
    identityService.deleteGroup(GROUP_ONE);
    assertThat(query.count(), is(0L));
}
Also used : Group(org.camunda.bpm.engine.identity.Group) Tenant(org.camunda.bpm.engine.identity.Tenant) TenantQuery(org.camunda.bpm.engine.identity.TenantQuery) Test(org.junit.Test)

Example 23 with Tenant

use of org.camunda.bpm.engine.identity.Tenant in project camunda-bpm-platform by camunda.

the class IdentityServiceTenantTest method createTenantUserMembershipAlreadyExisting.

@Test
public void createTenantUserMembershipAlreadyExisting() {
    Tenant tenant = identityService.newTenant(TENANT_ONE);
    identityService.saveTenant(tenant);
    User user = identityService.newUser(USER_ONE);
    identityService.saveUser(user);
    identityService.createTenantUserMembership(TENANT_ONE, USER_ONE);
    thrown.expect(ProcessEngineException.class);
    identityService.createTenantUserMembership(TENANT_ONE, USER_ONE);
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) User(org.camunda.bpm.engine.identity.User) Test(org.junit.Test)

Example 24 with Tenant

use of org.camunda.bpm.engine.identity.Tenant in project camunda-bpm-platform by camunda.

the class IdentityServiceTenantTest method deleteTenant.

@Test
public void deleteTenant() {
    // create
    Tenant tenant = identityService.newTenant(TENANT_ONE);
    identityService.saveTenant(tenant);
    TenantQuery query = identityService.createTenantQuery();
    assertThat(query.count(), is(1L));
    identityService.deleteTenant("nonExisting");
    assertThat(query.count(), is(1L));
    identityService.deleteTenant(TENANT_ONE);
    assertThat(query.count(), is(0L));
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) TenantQuery(org.camunda.bpm.engine.identity.TenantQuery) Test(org.junit.Test)

Example 25 with Tenant

use of org.camunda.bpm.engine.identity.Tenant 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);
    }
}
Also used : MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) Authorization(org.camunda.bpm.engine.authorization.Authorization) User(org.camunda.bpm.engine.identity.User) Tenant(org.camunda.bpm.engine.identity.Tenant) MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) AuthorizationException(org.camunda.bpm.engine.AuthorizationException)

Aggregations

Tenant (org.camunda.bpm.engine.identity.Tenant)47 Test (org.junit.Test)24 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)10 TenantQuery (org.camunda.bpm.engine.identity.TenantQuery)10 Authorization (org.camunda.bpm.engine.authorization.Authorization)9 Group (org.camunda.bpm.engine.identity.Group)9 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)8 User (org.camunda.bpm.engine.identity.User)8 Matchers.anyString (org.mockito.Matchers.anyString)7 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)6 ArrayList (java.util.ArrayList)5 TenantEntity (org.camunda.bpm.engine.impl.persistence.entity.TenantEntity)3 IdentityService (org.camunda.bpm.engine.IdentityService)2 RepositoryService (org.camunda.bpm.engine.RepositoryService)2 GroupQuery (org.camunda.bpm.engine.identity.GroupQuery)2 AuthorizationServiceImpl (org.camunda.bpm.engine.impl.AuthorizationServiceImpl)2 IdentityServiceImpl (org.camunda.bpm.engine.impl.IdentityServiceImpl)2 Before (org.junit.Before)2 AuthorizationService (org.camunda.bpm.engine.AuthorizationService)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1