Search in sources :

Example 16 with Group

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

the class GroupRestServiceInteractionTest method testReadOnlyGroupCreateFails.

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

Example 17 with Group

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

the class GroupRestServiceInteractionTest method testGroupResourceOptionsUnauthorized.

@Test
public void testGroupResourceOptionsUnauthorized() {
    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(false);
    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]", nullValue()).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 18 with Group

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

the class GroupRestServiceInteractionTest method testSaveGroupThrowsAuthorizationException.

@Test
public void testSaveGroupThrowsAuthorizationException() {
    Group newGroup = MockProvider.createMockGroup();
    String message = "exception expected";
    when(identityServiceMock.newGroup(newGroup.getId())).thenReturn(newGroup);
    doThrow(new AuthorizationException(message)).when(identityServiceMock).saveGroup(newGroup);
    given().body(GroupDto.fromGroup(newGroup)).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().post(GROUP_CREATE_URL);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 19 with Group

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

the class GroupRestServiceInteractionTest method testUpdateNonExistingGroup.

@Test
public void testUpdateNonExistingGroup() {
    Group groupUpdate = MockProvider.createMockGroupUpdate();
    GroupQuery sampleGroupQuery = mock(GroupQuery.class);
    when(identityServiceMock.createGroupQuery()).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.groupId("aNonExistingGroup")).thenReturn(sampleGroupQuery);
    // this time the query returns null
    when(sampleGroupQuery.singleResult()).thenReturn(null);
    given().pathParam("id", "aNonExistingGroup").body(GroupDto.fromGroup(groupUpdate)).contentType(ContentType.JSON).then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("Group with id aNonExistingGroup does not exist")).when().put(GROUP_URL);
    verify(identityServiceMock, never()).saveGroup(any(Group.class));
}
Also used : Group(org.camunda.bpm.engine.identity.Group) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Test(org.junit.Test)

Example 20 with Group

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

the class IdentityRestServiceQueryTest method createMockIdentityQueries.

private void createMockIdentityQueries() {
    UserQuery sampleUserQuery = mock(UserQuery.class);
    List<User> mockUsers = new ArrayList<User>();
    mockUser = MockProvider.createMockUser();
    mockUsers.add(mockUser);
    when(sampleUserQuery.list()).thenReturn(mockUsers);
    when(sampleUserQuery.memberOfGroup(anyString())).thenReturn(sampleUserQuery);
    when(sampleUserQuery.count()).thenReturn((long) mockUsers.size());
    GroupQuery sampleGroupQuery = mock(GroupQuery.class);
    List<Group> mockGroups = MockProvider.createMockGroups();
    when(sampleGroupQuery.list()).thenReturn(mockGroups);
    when(sampleGroupQuery.groupMember(anyString())).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.orderByGroupName()).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.orderByGroupId()).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.orderByGroupType()).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.asc()).thenReturn(sampleGroupQuery);
    when(sampleGroupQuery.desc()).thenReturn(sampleGroupQuery);
    when(processEngine.getIdentityService().createGroupQuery()).thenReturn(sampleGroupQuery);
    when(processEngine.getIdentityService().createUserQuery()).thenReturn(sampleUserQuery);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) UserQuery(org.camunda.bpm.engine.identity.UserQuery) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) ArrayList(java.util.ArrayList)

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