Search in sources :

Example 1 with Tenant

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

the class HalTenantResolver method resolveNotCachedLinks.

@Override
protected List<HalResource<?>> resolveNotCachedLinks(String[] linkedIds, ProcessEngine processEngine) {
    IdentityService identityService = processEngine.getIdentityService();
    List<Tenant> tenants = identityService.createTenantQuery().tenantIdIn(linkedIds).list();
    List<HalResource<?>> resolvedTenants = new ArrayList<HalResource<?>>();
    for (Tenant tenant : tenants) {
        resolvedTenants.add(HalTenant.fromTenant(tenant));
    }
    return resolvedTenants;
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) Tenant(org.camunda.bpm.engine.identity.Tenant) ArrayList(java.util.ArrayList) HalResource(org.camunda.bpm.engine.rest.hal.HalResource)

Example 2 with Tenant

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

the class TenantRestServiceInteractionTest method saveTenantThrowsAuthorizationException.

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

Example 3 with Tenant

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

the class TenantRestServiceInteractionTest method updateNonExistingTenant.

@Test
public void updateNonExistingTenant() {
    Tenant updatedTenant = MockProvider.createMockTenant();
    when(updatedTenant.getName()).thenReturn("updatedName");
    when(mockQuery.singleResult()).thenReturn(null);
    given().pathParam("id", "aNonExistingTenant").body(TenantDto.fromTenant(updatedTenant)).contentType(ContentType.JSON).then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("Tenant with id aNonExistingTenant does not exist")).when().put(TENANT_URL);
    verify(identityServiceMock, never()).saveTenant(any(Tenant.class));
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Test(org.junit.Test)

Example 4 with Tenant

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

the class TenantRestServiceInteractionTest method failToUpdateTenantForReadOnlyService.

@Test
public void failToUpdateTenantForReadOnlyService() {
    Tenant updatedTenant = MockProvider.createMockTenant();
    when(identityServiceMock.isReadOnly()).thenReturn(true);
    given().pathParam("id", MockProvider.EXAMPLE_TENANT_ID).body(TenantDto.fromTenant(updatedTenant)).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().put(TENANT_URL);
    verify(identityServiceMock, never()).saveTenant(mockTenant);
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Test(org.junit.Test)

Example 5 with Tenant

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

the class TenantRestServiceInteractionTest method updateTenantThrowsAuthorizationException.

@Test
public void updateTenantThrowsAuthorizationException() {
    Tenant updatedTenant = MockProvider.createMockTenant();
    when(updatedTenant.getName()).thenReturn("updatedName");
    String message = "exception expected";
    doThrow(new AuthorizationException(message)).when(identityServiceMock).saveTenant(any(Tenant.class));
    given().pathParam("id", MockProvider.EXAMPLE_TENANT_ID).body(TenantDto.fromTenant(updatedTenant)).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().put(TENANT_URL);
}
Also used : Tenant(org.camunda.bpm.engine.identity.Tenant) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

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