Search in sources :

Example 1 with AuthorizationQuery

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);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery)

Example 2 with AuthorizationQuery

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);
}
Also used : AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) CountResultDto(org.camunda.bpm.engine.rest.dto.CountResultDto)

Example 3 with AuthorizationQuery

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);
}
Also used : AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) Test(org.junit.Test)

Example 4 with AuthorizationQuery

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();
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) RequestSpecification(com.jayway.restassured.specification.RequestSpecification) Test(org.junit.Test)

Example 5 with AuthorizationQuery

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);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

AuthorizationQuery (org.camunda.bpm.engine.authorization.AuthorizationQuery)23 Test (org.junit.Test)19 Authorization (org.camunda.bpm.engine.authorization.Authorization)16 AuthorizationDto (org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto)6 Matchers.anyString (org.mockito.Matchers.anyString)5 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)2 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)2 Response (com.jayway.restassured.response.Response)1 RequestSpecification (com.jayway.restassured.specification.RequestSpecification)1 Deployment (org.camunda.bpm.engine.repository.Deployment)1 CountResultDto (org.camunda.bpm.engine.rest.dto.CountResultDto)1 InOrder (org.mockito.InOrder)1