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();
}
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);
}
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);
}
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;
}
Aggregations