Search in sources :

Example 96 with AuthorizationException

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

the class JobAuthorizationTest method testSetJobRetriesWithoutAuthorization.

// set job retries ////////////////////////////////////////////////
public void testSetJobRetriesWithoutAuthorization() {
    // given
    Job job = selectAnyJob();
    String jobId = job.getId();
    try {
        // when
        managementService.setJobRetries(jobId, 1);
        fail("Exception expected: It should not be possible to set job retries");
    } catch (AuthorizationException e) {
        // then
        String message = e.getMessage();
        assertTextPresent(userId, message);
        assertTextPresent(UPDATE.getName(), message);
        assertTextPresent(PROCESS_INSTANCE.resourceName(), message);
        assertTextPresent(UPDATE_INSTANCE.getName(), message);
        assertTextPresent(job.getProcessDefinitionKey(), message);
        assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
    }
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Job(org.camunda.bpm.engine.runtime.Job)

Example 97 with AuthorizationException

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

the class ProcessInstanceAuthorizationTest method testSuspendProcessInstanceByProcessDefinitionIdWithUpdatePermissionOnProcessInstance.

public void testSuspendProcessInstanceByProcessDefinitionIdWithUpdatePermissionOnProcessInstance() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    String processDefinitionId = instance.getProcessDefinitionId();
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    try {
        // when
        runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinitionId);
        fail("Exception expected: It should not be posssible to suspend a process instance.");
    } catch (AuthorizationException e) {
        // then
        String message = e.getMessage();
        assertTextPresent(userId, message);
        assertTextPresent(UPDATE_INSTANCE.getName(), message);
        assertTextPresent(PROCESS_KEY, message);
        assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
    }
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance)

Example 98 with AuthorizationException

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

the class ProcessInstanceAuthorizationTest method testSuspendProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnProcessInstance.

public void testSuspendProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnProcessInstance() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    try {
        // when
        runtimeService.suspendProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
        fail("Exception expected: It should not be posssible to suspend a process instance.");
    } catch (AuthorizationException e) {
        // then
        String message = e.getMessage();
        assertTextPresent(userId, message);
        assertTextPresent(UPDATE_INSTANCE.getName(), message);
        assertTextPresent(PROCESS_KEY, message);
        assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
    }
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance)

Example 99 with AuthorizationException

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

the class ProcessInstanceAuthorizationTest method testActivateProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnProcessInstance.

public void testActivateProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnProcessInstance() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    try {
        // when
        runtimeService.activateProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
        fail("Exception expected: It should not be posssible to suspend a process instance.");
    } catch (AuthorizationException e) {
        // then
        String message = e.getMessage();
        assertTextPresent(userId, message);
        assertTextPresent(UPDATE_INSTANCE.getName(), message);
        assertTextPresent(PROCESS_KEY, message);
        assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
    }
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance)

Example 100 with AuthorizationException

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

the class IdentityServiceAuthorizationsTest method testTenantUserMembershipCreateAuthorizations.

public void testTenantUserMembershipCreateAuthorizations() {
    User jonny1 = identityService.newUser("jonny1");
    identityService.saveUser(jonny1);
    Tenant tenant1 = identityService.newTenant("tenant1");
    identityService.saveTenant(tenant1);
    // add base permission which allows nobody to create memberships
    Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    basePerms.setResource(TENANT_MEMBERSHIP);
    basePerms.setResourceId(ANY);
    // add all then remove 'create'
    basePerms.addPermission(ALL);
    basePerms.removePermission(CREATE);
    authorizationService.saveAuthorization(basePerms);
    processEngineConfiguration.setAuthorizationEnabled(true);
    identityService.setAuthenticatedUserId(jonny2);
    try {
        identityService.createTenantUserMembership("tenant1", "jonny1");
        fail("exception expected");
    } catch (AuthorizationException e) {
        assertEquals(1, e.getMissingAuthorizations().size());
        MissingAuthorization info = e.getMissingAuthorizations().get(0);
        assertEquals(jonny2, e.getUserId());
        assertExceptionInfo(CREATE.getName(), TENANT_MEMBERSHIP.resourceName(), "tenant1", info);
    }
}
Also used : MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) Authorization(org.camunda.bpm.engine.authorization.Authorization) User(org.camunda.bpm.engine.identity.User) Tenant(org.camunda.bpm.engine.identity.Tenant) MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) AuthorizationException(org.camunda.bpm.engine.AuthorizationException)

Aggregations

AuthorizationException (org.camunda.bpm.engine.AuthorizationException)213 Test (org.junit.Test)142 Matchers.anyString (org.mockito.Matchers.anyString)116 Matchers.containsString (org.hamcrest.Matchers.containsString)55 HashMap (java.util.HashMap)50 Authorization (org.camunda.bpm.engine.authorization.Authorization)22 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)21 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)21 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)20 RestException (org.camunda.bpm.engine.rest.exception.RestException)14 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)13 User (org.camunda.bpm.engine.identity.User)12 Group (org.camunda.bpm.engine.identity.Group)10 Tenant (org.camunda.bpm.engine.identity.Tenant)10 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)10 ArrayList (java.util.ArrayList)8 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 ExampleVariableObject (org.camunda.bpm.engine.rest.helper.ExampleVariableObject)7 ManagementService (org.camunda.bpm.engine.ManagementService)6