Search in sources :

Example 6 with TenantEntity

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

the class DbIdentityServiceProvider method createTenantUserMembership.

public void createTenantUserMembership(String tenantId, String userId) {
    checkAuthorization(Permissions.CREATE, Resources.TENANT_MEMBERSHIP, tenantId);
    TenantEntity tenant = findTenantById(tenantId);
    UserEntity user = findUserById(userId);
    ensureNotNull("No tenant found with id '" + tenantId + "'.", "tenant", tenant);
    ensureNotNull("No user found with id '" + userId + "'.", "user", user);
    TenantMembershipEntity membership = new TenantMembershipEntity();
    membership.setTenant(tenant);
    membership.setUser(user);
    getDbEntityManager().insert(membership);
    createDefaultTenantMembershipAuthorizations(tenant, user);
}
Also used : TenantMembershipEntity(org.camunda.bpm.engine.impl.persistence.entity.TenantMembershipEntity) TenantEntity(org.camunda.bpm.engine.impl.persistence.entity.TenantEntity) UserEntity(org.camunda.bpm.engine.impl.persistence.entity.UserEntity)

Example 7 with TenantEntity

use of org.camunda.bpm.engine.impl.persistence.entity.TenantEntity 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);
}
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