Search in sources :

Example 1 with TenantEntity

use of org.camunda.bpm.engine.impl.persistence.entity.TenantEntity in project camunda-bpm-platform by camunda.

the class DbIdentityServiceProvider method deleteTenant.

public void deleteTenant(String tenantId) {
    checkAuthorization(Permissions.DELETE, Resources.TENANT, tenantId);
    TenantEntity tenant = findTenantById(tenantId);
    if (tenant != null) {
        deleteTenantMembershipsOfTenant(tenantId);
        deleteAuthorizations(Resources.TENANT, tenantId);
        getDbEntityManager().delete(tenant);
    }
}
Also used : TenantEntity(org.camunda.bpm.engine.impl.persistence.entity.TenantEntity)

Example 2 with TenantEntity

use of org.camunda.bpm.engine.impl.persistence.entity.TenantEntity in project camunda-bpm-platform by camunda.

the class DbIdentityServiceProvider method saveTenant.

public Tenant saveTenant(Tenant tenant) {
    TenantEntity tenantEntity = (TenantEntity) tenant;
    if (tenantEntity.getRevision() == 0) {
        checkAuthorization(Permissions.CREATE, Resources.TENANT, null);
        getDbEntityManager().insert(tenantEntity);
        createDefaultAuthorizations(tenant);
    } else {
        checkAuthorization(Permissions.UPDATE, Resources.TENANT, tenant.getId());
        getDbEntityManager().merge(tenantEntity);
    }
    return tenantEntity;
}
Also used : TenantEntity(org.camunda.bpm.engine.impl.persistence.entity.TenantEntity)

Example 3 with TenantEntity

use of org.camunda.bpm.engine.impl.persistence.entity.TenantEntity in project camunda-bpm-platform by camunda.

the class DbIdentityServiceProvider method createTenantGroupMembership.

public void createTenantGroupMembership(String tenantId, String groupId) {
    checkAuthorization(Permissions.CREATE, Resources.TENANT_MEMBERSHIP, tenantId);
    TenantEntity tenant = findTenantById(tenantId);
    GroupEntity group = findGroupById(groupId);
    ensureNotNull("No tenant found with id '" + tenantId + "'.", "tenant", tenant);
    ensureNotNull("No group found with id '" + groupId + "'.", "group", group);
    TenantMembershipEntity membership = new TenantMembershipEntity();
    membership.setTenant(tenant);
    membership.setGroup(group);
    getDbEntityManager().insert(membership);
    createDefaultTenantMembershipAuthorizations(tenant, group);
}
Also used : TenantMembershipEntity(org.camunda.bpm.engine.impl.persistence.entity.TenantMembershipEntity) TenantEntity(org.camunda.bpm.engine.impl.persistence.entity.TenantEntity) GroupEntity(org.camunda.bpm.engine.impl.persistence.entity.GroupEntity)

Example 4 with TenantEntity

use of org.camunda.bpm.engine.impl.persistence.entity.TenantEntity in project camunda-bpm-platform by camunda.

the class IdentityServiceAuthorizationsTest method testTenantCreateAuthorizations.

public void testTenantCreateAuthorizations() {
    // add base permission which allows nobody to create tenants:
    Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    basePerms.setResource(TENANT);
    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.newTenant("tenant");
        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.resourceName(), null, info);
    }
    // circumvent auth check to get new transient userobject
    Tenant tenant = new TenantEntity("tenant");
    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(CREATE.getName(), TENANT.resourceName(), null, info);
    }
}
Also used : MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) Authorization(org.camunda.bpm.engine.authorization.Authorization) Tenant(org.camunda.bpm.engine.identity.Tenant) MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) TenantEntity(org.camunda.bpm.engine.impl.persistence.entity.TenantEntity)

Example 5 with TenantEntity

use of org.camunda.bpm.engine.impl.persistence.entity.TenantEntity in project camunda-bpm-platform by camunda.

the class IdentityServiceAuthorizationsTest method testTenantDeleteAuthorizations.

public void testTenantDeleteAuthorizations() {
    // 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 delete
    basePerms.removePermission(DELETE);
    authorizationService.saveAuthorization(basePerms);
    // turn on authorization
    processEngineConfiguration.setAuthorizationEnabled(true);
    identityService.setAuthenticatedUserId(jonny2);
    try {
        identityService.deleteTenant("tenant");
        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.resourceName(), "tenant", info);
    }
}
Also used : MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) Authorization(org.camunda.bpm.engine.authorization.Authorization) Tenant(org.camunda.bpm.engine.identity.Tenant) MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) TenantEntity(org.camunda.bpm.engine.impl.persistence.entity.TenantEntity) AuthorizationException(org.camunda.bpm.engine.AuthorizationException)

Aggregations

TenantEntity (org.camunda.bpm.engine.impl.persistence.entity.TenantEntity)7 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)3 Authorization (org.camunda.bpm.engine.authorization.Authorization)3 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)3 Tenant (org.camunda.bpm.engine.identity.Tenant)3 TenantMembershipEntity (org.camunda.bpm.engine.impl.persistence.entity.TenantMembershipEntity)2 GroupEntity (org.camunda.bpm.engine.impl.persistence.entity.GroupEntity)1 UserEntity (org.camunda.bpm.engine.impl.persistence.entity.UserEntity)1