Search in sources :

Example 16 with AuthorizationQuery

use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.

the class AuthorizationRestServiceInteractionTest method testAuthorizationResourceOptions.

@Test
public void testAuthorizationResourceOptions() {
    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);
    when(identityServiceMock.getCurrentAuthentication()).thenReturn(null);
    when(processEngineConfigurationMock.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].href", equalTo(fullAuthorizationUrl)).body("links[1].method", equalTo(HttpMethod.DELETE)).body("links[1].rel", equalTo("delete")).body("links[2].href", equalTo(fullAuthorizationUrl)).body("links[2].method", equalTo(HttpMethod.PUT)).body("links[2].rel", equalTo("update")).when().options(AUTH_RESOURCE_PATH);
    verify(identityServiceMock, times(2)).getCurrentAuthentication();
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 17 with AuthorizationQuery

use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.

the class AuthorizationRestServiceInteractionTest method testUpdateAuthorizationThrowsAuthorizationException.

@Test
public void testUpdateAuthorizationThrowsAuthorizationException() {
    Authorization authorization = MockProvider.createMockGlobalAuthorization();
    AuthorizationDto dto = AuthorizationDto.fromAuthorization(authorization);
    AuthorizationQuery authorizationQuery = mock(AuthorizationQuery.class);
    when(authorizationServiceMock.createAuthorizationQuery()).thenReturn(authorizationQuery);
    when(authorizationQuery.authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(authorizationQuery);
    when(authorizationQuery.singleResult()).thenReturn(authorization);
    String message = "expected authorization exception";
    when(authorizationServiceMock.saveAuthorization(any(Authorization.class))).thenThrow(new AuthorizationException(message));
    given().pathParam("id", MockProvider.EXAMPLE_AUTHORIZATION_ID).body(dto).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().put(AUTH_RESOURCE_PATH);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationDto(org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto) AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 18 with AuthorizationQuery

use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.

the class AuthorizationRestServiceInteractionTest method testDeleteNonExistingAuthorization.

@Test
public void testDeleteNonExistingAuthorization() {
    AuthorizationQuery authorizationQuery = mock(AuthorizationQuery.class);
    when(authorizationServiceMock.createAuthorizationQuery()).thenReturn(authorizationQuery);
    when(authorizationQuery.authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(authorizationQuery);
    when(authorizationQuery.singleResult()).thenReturn(null);
    given().pathParam("id", MockProvider.EXAMPLE_AUTHORIZATION_ID).then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON).body("message", equalTo("Authorization with id " + MockProvider.EXAMPLE_AUTHORIZATION_ID + " does not exist.")).when().delete(AUTH_RESOURCE_PATH);
    verify(authorizationServiceMock, never()).deleteAuthorization(MockProvider.EXAMPLE_AUTHORIZATION_ID);
}
Also used : AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) Test(org.junit.Test)

Example 19 with AuthorizationQuery

use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.

the class DeploymentAuthorizationTest method testClearAuthorizationOnDeleteDeployment.

// clear authorization /////////////////////////////////////
public void testClearAuthorizationOnDeleteDeployment() {
    // given
    createGrantAuthorization(DEPLOYMENT, ANY, userId, CREATE);
    Deployment deployment = repositoryService.createDeployment().addClasspathResource(FIRST_RESOURCE).deploy();
    String deploymentId = deployment.getId();
    AuthorizationQuery query = authorizationService.createAuthorizationQuery().userIdIn(userId).resourceId(deploymentId);
    Authorization authorization = query.singleResult();
    assertNotNull(authorization);
    // when
    repositoryService.deleteDeployment(deploymentId);
    authorization = query.singleResult();
    assertNull(authorization);
    deleteDeployment(deploymentId);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) Deployment(org.camunda.bpm.engine.repository.Deployment)

Example 20 with AuthorizationQuery

use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.

the class AuthorizationRestServiceQueryTest method testNoParametersQuery.

@Test
public void testNoParametersQuery() {
    AuthorizationQuery mockQuery = setUpMockQuery(MockProvider.createMockAuthorizations());
    expect().statusCode(Status.OK.getStatusCode()).when().get(SERVICE_PATH);
    verify(mockQuery).list();
    verifyNoMoreInteractions(mockQuery);
}
Also used : AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) 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