Search in sources :

Example 31 with GroupQuery

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

the class GroupRestServiceInteractionTest method testGroupResourceOptionsUnauthenticated.

@Test
public void testGroupResourceOptionsUnauthenticated() {
    String fullGroupUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + "/group/" + MockProvider.EXAMPLE_GROUP_ID;
    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(fullGroupUrl)).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1].href", equalTo(fullGroupUrl)).body("links[1].method", equalTo(HttpMethod.DELETE)).body("links[1].rel", equalTo("delete")).body("links[2].href", equalTo(fullGroupUrl)).body("links[2].method", equalTo(HttpMethod.PUT)).body("links[2].rel", equalTo("update")).when().options(GROUP_URL);
    verify(identityServiceMock, times(2)).getCurrentAuthentication();
}
Also used : Group(org.camunda.bpm.engine.identity.Group) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 32 with GroupQuery

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

the class GroupRestServiceInteractionTest method testGroupResourceOptionsAuthorized.

@Test
public void testGroupResourceOptionsAuthorized() {
    String fullGroupUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + "/group/" + MockProvider.EXAMPLE_GROUP_ID;
    Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, null);
    when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
    when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, GROUP, MockProvider.EXAMPLE_GROUP_ID)).thenReturn(true);
    when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, GROUP, 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(fullGroupUrl)).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1].href", equalTo(fullGroupUrl)).body("links[1].method", equalTo(HttpMethod.DELETE)).body("links[1].rel", equalTo("delete")).body("links[2]", nullValue()).when().options(GROUP_URL);
    verify(identityServiceMock, times(2)).getCurrentAuthentication();
    verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, GROUP, MockProvider.EXAMPLE_GROUP_ID);
    verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, GROUP, 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 33 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery 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 34 with GroupQuery

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

the class GroupRestServiceQueryTest method setUpMockGroupQuery.

private GroupQuery setUpMockGroupQuery(List<Group> list) {
    GroupQuery sampleGroupQuery = mock(GroupQuery.class);
    when(sampleGroupQuery.list()).thenReturn(list);
    when(sampleGroupQuery.count()).thenReturn((long) list.size());
    when(processEngine.getIdentityService().createGroupQuery()).thenReturn(sampleGroupQuery);
    return sampleGroupQuery;
}
Also used : GroupQuery(org.camunda.bpm.engine.identity.GroupQuery)

Aggregations

GroupQuery (org.camunda.bpm.engine.identity.GroupQuery)34 Group (org.camunda.bpm.engine.identity.Group)22 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)10 ArrayList (java.util.ArrayList)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 User (org.camunda.bpm.engine.identity.User)5 UserQuery (org.camunda.bpm.engine.identity.UserQuery)4 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)4 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)3 Tenant (org.camunda.bpm.engine.identity.Tenant)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Response (com.jayway.restassured.response.Response)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 IdentityService (org.camunda.bpm.engine.IdentityService)1 RepositoryService (org.camunda.bpm.engine.RepositoryService)1