Search in sources :

Example 81 with AuthorizationException

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

the class JobResourceImpl method setJobRetries.

@Override
public void setJobRetries(RetriesDto dto) {
    try {
        ManagementService managementService = engine.getManagementService();
        managementService.setJobRetries(jobId, dto.getRetries());
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new InvalidRequestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : ManagementService(org.camunda.bpm.engine.ManagementService) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 82 with AuthorizationException

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

the class AuthorizationManager method checkAuthorization.

public void checkAuthorization(List<PermissionCheck> permissionChecks) {
    if (isAuthCheckExecuted()) {
        Authentication currentAuthentication = getCurrentAuthentication();
        String userId = currentAuthentication.getUserId();
        boolean isAuthorized = isAuthorized(userId, currentAuthentication.getGroupIds(), permissionChecks);
        if (!isAuthorized) {
            List<MissingAuthorization> missingAuthorizations = new ArrayList<MissingAuthorization>();
            for (PermissionCheck check : permissionChecks) {
                missingAuthorizations.add(new MissingAuthorization(check.getPermission().getName(), check.getResource().resourceName(), check.getResourceId()));
            }
            throw new AuthorizationException(userId, missingAuthorizations);
        }
    }
}
Also used : MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) PermissionCheck(org.camunda.bpm.engine.impl.db.PermissionCheck) CompositePermissionCheck(org.camunda.bpm.engine.impl.db.CompositePermissionCheck) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) ArrayList(java.util.ArrayList)

Example 83 with AuthorizationException

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

the class AuthorizationManager method checkAuthorization.

public void checkAuthorization(CompositePermissionCheck compositePermissionCheck) {
    if (isAuthCheckExecuted()) {
        Authentication currentAuthentication = getCurrentAuthentication();
        String userId = currentAuthentication.getUserId();
        boolean isAuthorized = isAuthorized(compositePermissionCheck);
        if (!isAuthorized) {
            List<MissingAuthorization> missingAuthorizations = new ArrayList<MissingAuthorization>();
            for (PermissionCheck check : compositePermissionCheck.getAllPermissionChecks()) {
                missingAuthorizations.add(new MissingAuthorization(check.getPermission().getName(), check.getResource().resourceName(), check.getResourceId()));
            }
            throw new AuthorizationException(userId, missingAuthorizations);
        }
    }
}
Also used : MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) PermissionCheck(org.camunda.bpm.engine.impl.db.PermissionCheck) CompositePermissionCheck(org.camunda.bpm.engine.impl.db.CompositePermissionCheck) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) ArrayList(java.util.ArrayList)

Example 84 with AuthorizationException

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

the class DeploymentAuthorizationTest method testRegisterProcessApplicationWithoutAuthorization.

// register process application ///////////////////////////////////
public void testRegisterProcessApplicationWithoutAuthorization() {
    // given
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication();
    ProcessApplicationReference reference = processApplication.getReference();
    String deploymentId = createDeployment(null, FIRST_RESOURCE).getId();
    try {
        // when
        managementService.registerProcessApplication(deploymentId, reference);
        fail("Exception expected: It should not be possible to register a process application");
    } catch (AuthorizationException e) {
        // then
        String message = e.getMessage();
        assertTextPresent("ENGINE-03029 Required authenticated group 'camunda-admin'", message);
    }
    deleteDeployment(deploymentId);
}
Also used : ProcessApplicationReference(org.camunda.bpm.application.ProcessApplicationReference) EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AuthorizationException(org.camunda.bpm.engine.AuthorizationException)

Example 85 with AuthorizationException

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

the class JobAuthorizationTest method testExecuteJobWithoutAuthorization.

// execute job ////////////////////////////////////////////////
public void testExecuteJobWithoutAuthorization() {
    // given
    Job job = selectAnyJob();
    String jobId = job.getId();
    try {
        // when
        managementService.executeJob(jobId);
        fail("Exception expected: It should not be possible to execute the job");
    } 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)

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