use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceImpl method queryAuthorizations.
public List<AuthorizationDto> queryAuthorizations(AuthorizationQueryDto queryDto, Integer firstResult, Integer maxResults) {
queryDto.setObjectMapper(getObjectMapper());
AuthorizationQuery query = queryDto.toQuery(getProcessEngine());
List<Authorization> resultList;
if (firstResult != null || maxResults != null) {
resultList = executePaginatedQuery(query, firstResult, maxResults);
} else {
resultList = query.list();
}
return AuthorizationDto.fromAuthorizationList(resultList);
}
use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceImpl method getAuthorizationCount.
protected CountResultDto getAuthorizationCount(AuthorizationQueryDto queryDto) {
AuthorizationQuery query = queryDto.toQuery(getProcessEngine());
long count = query.count();
return new CountResultDto(count);
}
use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceQueryTest method testSuccessfulPagination.
@Test
public void testSuccessfulPagination() {
AuthorizationQuery mockQuery = setUpMockQuery(MockProvider.createMockAuthorizations());
int firstResult = 0;
int maxResults = 10;
given().queryParam("firstResult", firstResult).queryParam("maxResults", maxResults).then().expect().statusCode(Status.OK.getStatusCode()).when().get(SERVICE_PATH);
verify(mockQuery).listPage(firstResult, maxResults);
}
use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceQueryTest method testCompleteGetParameters.
@Test
public void testCompleteGetParameters() {
List<Authorization> mockAuthorizations = MockProvider.createMockGlobalAuthorizations();
AuthorizationQuery mockQuery = setUpMockQuery(mockAuthorizations);
Map<String, String> queryParameters = getCompleteStringQueryParameters();
RequestSpecification requestSpecification = given().contentType(POST_JSON_CONTENT_TYPE);
for (Entry<String, String> paramEntry : queryParameters.entrySet()) {
requestSpecification.parameter(paramEntry.getKey(), paramEntry.getValue());
}
requestSpecification.expect().statusCode(Status.OK.getStatusCode()).when().get(SERVICE_PATH);
verify(mockQuery).authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID);
verify(mockQuery).authorizationType(MockProvider.EXAMPLE_AUTHORIZATION_TYPE);
verify(mockQuery).userIdIn(new String[] { MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_ID2 });
verify(mockQuery).groupIdIn(new String[] { MockProvider.EXAMPLE_GROUP_ID, MockProvider.EXAMPLE_GROUP_ID2 });
verify(mockQuery).resourceType(MockProvider.EXAMPLE_RESOURCE_TYPE_ID);
verify(mockQuery).resourceId(MockProvider.EXAMPLE_RESOURCE_ID);
verify(mockQuery).list();
}
use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceInteractionTest method testAuthorizationResourceOptionsUnauthorized.
@Test
public void testAuthorizationResourceOptionsUnauthorized() {
String fullAuthorizationUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + AuthorizationRestService.PATH + "/" + MockProvider.EXAMPLE_AUTHORIZATION_ID;
Authorization authorization = MockProvider.createMockGlobalAuthorization();
AuthorizationQuery authorizationQuery = mock(AuthorizationQuery.class);
when(authorizationServiceMock.createAuthorizationQuery()).thenReturn(authorizationQuery);
when(authorizationQuery.authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(authorizationQuery);
when(authorizationQuery.singleResult()).thenReturn(authorization);
Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, null);
when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, AUTHORIZATION, MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(false);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, AUTHORIZATION, MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(false);
when(processEngine.getProcessEngineConfiguration().isAuthorizationEnabled()).thenReturn(true);
given().pathParam("id", MockProvider.EXAMPLE_AUTHORIZATION_ID).then().statusCode(Status.OK.getStatusCode()).body("links[0].href", equalTo(fullAuthorizationUrl)).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1]", nullValue()).body("links[2]", nullValue()).when().options(AUTH_RESOURCE_PATH);
verify(identityServiceMock, times(2)).getCurrentAuthentication();
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, AUTHORIZATION, MockProvider.EXAMPLE_AUTHORIZATION_ID);
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, AUTHORIZATION, MockProvider.EXAMPLE_AUTHORIZATION_ID);
}
Aggregations