Search in sources :

Example 6 with Tenant

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

the class TenantRestServiceInteractionTest method createExistingTenant.

@Test
public void createExistingTenant() {
    Tenant newTenant = MockProvider.createMockTenant();
    when(identityServiceMock.newTenant(MockProvider.EXAMPLE_TENANT_ID)).thenReturn(newTenant);
    String message = "exception expected";
    doThrow(new ProcessEngineException(message)).when(identityServiceMock).saveTenant(newTenant);
    given().body(TenantDto.fromTenant(newTenant)).contentType(ContentType.JSON).then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(ProcessEngineException.class.getSimpleName())).body("message", equalTo(message)).when().post(TENANT_CREATE_URL);
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) Matchers.anyString(org.mockito.Matchers.anyString) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test)

Example 7 with Tenant

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

the class TenantRestServiceInteractionTest method failToCreateTenantForReadOnlyService.

@Test
public void failToCreateTenantForReadOnlyService() {
    Tenant newTenant = MockProvider.createMockTenant();
    when(identityServiceMock.isReadOnly()).thenReturn(true);
    given().body(TenantDto.fromTenant(newTenant)).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("Identity service implementation is read-only.")).when().post(TENANT_CREATE_URL);
    verify(identityServiceMock, never()).newTenant(MockProvider.EXAMPLE_TENANT_ID);
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Test(org.junit.Test)

Example 8 with Tenant

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

the class TenantRestServiceImpl method createTenant.

public void createTenant(TenantDto dto) {
    if (getIdentityService().isReadOnly()) {
        throw new InvalidRequestException(Status.FORBIDDEN, "Identity service implementation is read-only.");
    }
    Tenant newTenant = getIdentityService().newTenant(dto.getId());
    dto.update(newTenant);
    getIdentityService().saveTenant(newTenant);
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 9 with Tenant

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

the class TenantRestServiceImpl method queryTenants.

public List<TenantDto> queryTenants(UriInfo uriInfo, Integer firstResult, Integer maxResults) {
    TenantQueryDto queryDto = new TenantQueryDto(getObjectMapper(), uriInfo.getQueryParameters());
    TenantQuery query = queryDto.toQuery(getProcessEngine());
    List<Tenant> tenants;
    if (firstResult != null || maxResults != null) {
        tenants = executePaginatedQuery(query, firstResult, maxResults);
    } else {
        tenants = query.list();
    }
    return TenantDto.fromTenantList(tenants);
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) TenantQueryDto(org.camunda.bpm.engine.rest.dto.identity.TenantQueryDto) TenantQuery(org.camunda.bpm.engine.identity.TenantQuery)

Example 10 with Tenant

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

the class ProcessEngineAuthenticationFilter method getTenantsOfUser.

protected List<String> getTenantsOfUser(ProcessEngine engine, String userId) {
    List<Tenant> tenants = engine.getIdentityService().createTenantQuery().userMember(userId).includingGroupsOfUser(true).list();
    List<String> tenantIds = new ArrayList<String>();
    for (Tenant tenant : tenants) {
        tenantIds.add(tenant.getId());
    }
    return tenantIds;
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) ArrayList(java.util.ArrayList)

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