Search in sources :

Example 91 with Group

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

the class GroupRestServiceInteractionTest method testGroupMembersResourceOptionsUnauthorized.

@Test
public void testGroupMembersResourceOptionsUnauthorized() {
    String fullMembersUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + "/group/" + MockProvider.EXAMPLE_GROUP_ID + "/members";
    Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, null);
    when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
    when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, GROUP_MEMBERSHIP, MockProvider.EXAMPLE_GROUP_ID)).thenReturn(false);
    when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, CREATE, GROUP_MEMBERSHIP, MockProvider.EXAMPLE_GROUP_ID)).thenReturn(false);
    Group sampleGroup = MockProvider.createMockGroup();
    GroupQuery sampleGroupQuery = mock(GroupQuery.class);
    when(identityServiceMock.createGroupQuery()).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.groupId(MockProvider.EXAMPLE_GROUP_ID)).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.singleResult()).thenReturn(sampleGroup);
    when(processEngineConfigurationMock.isAuthorizationEnabled()).thenReturn(true);
    given().pathParam("id", MockProvider.EXAMPLE_GROUP_ID).then().expect().statusCode(Status.OK.getStatusCode()).body("links[0].href", equalTo(fullMembersUrl)).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1]", nullValue()).body("links[2]", nullValue()).when().options(GROUP_MEMBERS_URL);
    verify(identityServiceMock, times(2)).getCurrentAuthentication();
    verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, GROUP_MEMBERSHIP, MockProvider.EXAMPLE_GROUP_ID);
    verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, CREATE, GROUP_MEMBERSHIP, MockProvider.EXAMPLE_GROUP_ID);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 92 with Group

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

the class GroupRestServiceInteractionTest method testReadOnlyGroupUpdateFails.

@Test
public void testReadOnlyGroupUpdateFails() {
    Group groupUdpdate = MockProvider.createMockGroup();
    when(identityServiceMock.isReadOnly()).thenReturn(true);
    given().pathParam("id", MockProvider.EXAMPLE_GROUP_ID).body(GroupDto.fromGroup(groupUdpdate)).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(GROUP_URL);
    verify(identityServiceMock, never()).saveGroup(groupUdpdate);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Test(org.junit.Test)

Aggregations

Group (org.camunda.bpm.engine.identity.Group)92 Test (org.junit.Test)34 User (org.camunda.bpm.engine.identity.User)29 GroupQuery (org.camunda.bpm.engine.identity.GroupQuery)22 Authorization (org.camunda.bpm.engine.authorization.Authorization)13 ArrayList (java.util.ArrayList)12 Matchers.anyString (org.mockito.Matchers.anyString)12 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)10 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)9 Tenant (org.camunda.bpm.engine.identity.Tenant)9 IdentityService (org.camunda.bpm.engine.IdentityService)7 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)7 UserQuery (org.camunda.bpm.engine.identity.UserQuery)4 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)4 Before (org.junit.Before)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 AuthorizationService (org.camunda.bpm.engine.AuthorizationService)3 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)3 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)2