Java Code Examples for org.camunda.bpm.engine.impl.interceptor.CommandContext#runWithoutAuthorization()

The following examples show how to use org.camunda.bpm.engine.impl.interceptor.CommandContext#runWithoutAuthorization() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransitionInstanceCancellationCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected ExecutionEntity determineSourceInstanceExecution(final CommandContext commandContext) {
  ActivityInstance instance = commandContext.runWithoutAuthorization(new Callable<ActivityInstance>() {
    public ActivityInstance call() throws Exception {
      return new GetActivityInstanceCmd(processInstanceId).execute(commandContext);
    }
  });
  TransitionInstance instanceToCancel = findTransitionInstance(instance, transitionInstanceId);
  EnsureUtil.ensureNotNull(NotValidException.class,
      describeFailure("Transition instance '" + transitionInstanceId + "' does not exist"),
      "transitionInstance",
      instanceToCancel);

  ExecutionEntity transitionExecution = commandContext.getExecutionManager().findExecutionById(instanceToCancel.getExecutionId());

  return transitionExecution;
}
 
Example 2
Source File: GetDeploymentCaseModelCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public InputStream execute(final CommandContext commandContext) {
  ensureNotNull("caseDefinitionId", caseDefinitionId);

  CaseDefinitionEntity caseDefinition = Context
          .getProcessEngineConfiguration()
          .getDeploymentCache()
          .findDeployedCaseDefinitionById(caseDefinitionId);

  for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
    checker.checkReadCaseDefinition(caseDefinition);
  }

  final String deploymentId = caseDefinition.getDeploymentId();
  final String resourceName = caseDefinition.getResourceName();

  InputStream inputStream = commandContext.runWithoutAuthorization(new Callable<InputStream>() {
    public InputStream call() throws Exception {
      return new GetDeploymentResourceCmd(deploymentId, resourceName).execute(commandContext);
    }
  });

  return inputStream;
}
 
Example 3
Source File: GetDeploymentProcessDiagramCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public InputStream execute(final CommandContext commandContext) {
  ProcessDefinitionEntity processDefinition = Context
          .getProcessEngineConfiguration()
          .getDeploymentCache()
          .findDeployedProcessDefinitionById(processDefinitionId);

  for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
    checker.checkReadProcessDefinition(processDefinition);
  }

  final String deploymentId = processDefinition.getDeploymentId();
  final String resourceName = processDefinition.getDiagramResourceName();

  if (resourceName == null ) {
    return null;
  } else {

    InputStream processDiagramStream = commandContext.runWithoutAuthorization(new Callable<InputStream>() {
      public InputStream call() throws Exception {
        return new GetDeploymentResourceCmd(deploymentId, resourceName).execute(commandContext);
      }
    });

    return processDiagramStream;
  }
}
 
Example 4
Source File: GetDeploymentDecisionDiagramCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public InputStream execute(final CommandContext commandContext) {
  DecisionDefinition decisionDefinition = new GetDeploymentDecisionDefinitionCmd(decisionDefinitionId).execute(commandContext);

  final String deploymentId = decisionDefinition.getDeploymentId();
  final String resourceName = decisionDefinition.getDiagramResourceName();

  if (resourceName != null ) {
    return commandContext.runWithoutAuthorization(new Callable<InputStream>() {
      public InputStream call() throws Exception {
        return new GetDeploymentResourceCmd(deploymentId, resourceName).execute(commandContext);
      }
    });
  }
  else {
    return null;
  }
}
 
Example 5
Source File: GetDeploymentProcessDiagramLayoutCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public DiagramLayout execute(final CommandContext commandContext) {
  ProcessDefinitionEntity processDefinition = Context
      .getProcessEngineConfiguration()
      .getDeploymentCache()
      .findDeployedProcessDefinitionById(processDefinitionId);

  for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
    checker.checkReadProcessDefinition(processDefinition);
  }

  InputStream processModelStream = commandContext.runWithoutAuthorization(new Callable<InputStream>() {
    public InputStream call() throws Exception {
      return new GetDeploymentProcessModelCmd(processDefinitionId).execute(commandContext);
    }
  });

  InputStream processDiagramStream = commandContext.runWithoutAuthorization(new Callable<InputStream>() {
    public InputStream call() throws Exception {
      return new GetDeploymentProcessDiagramCmd(processDefinitionId).execute(commandContext);
    }
  });

  return new ProcessDiagramLayoutFactory().getProcessDiagramLayout(processModelStream, processDiagramStream);
}
 
Example 6
Source File: GetStartFormVariablesCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public VariableMap execute(final CommandContext commandContext) {
  StartFormData startFormData = commandContext.runWithoutAuthorization(new Callable<StartFormData>() {
    public StartFormData call() throws Exception {
      return new GetStartFormCmd(resourceId).execute(commandContext);
    }
  });

  ProcessDefinition definition = startFormData.getProcessDefinition();
  checkGetStartFormVariables((ProcessDefinitionEntity) definition, commandContext);

  VariableMap result = new VariableMapImpl();

  for (FormField formField : startFormData.getFormFields()) {
    if(formVariableNames == null || formVariableNames.contains(formField.getId())) {
      result.put(formField.getId(), createVariable(formField, null));
    }
  }

  return result;
}
 
Example 7
Source File: GetDeploymentProcessModelCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public InputStream execute(final CommandContext commandContext) {
  ProcessDefinitionEntity processDefinition = Context
          .getProcessEngineConfiguration()
          .getDeploymentCache()
          .findDeployedProcessDefinitionById(processDefinitionId);

  for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
    checker.checkReadProcessDefinition(processDefinition);
  }

  final String deploymentId = processDefinition.getDeploymentId();
  final String resourceName = processDefinition.getResourceName();

  InputStream processModelStream = commandContext.runWithoutAuthorization(new Callable<InputStream>() {
    public InputStream call() throws Exception {
      return new GetDeploymentResourceCmd(deploymentId, resourceName).execute(commandContext);
    }
  });

  return processModelStream;
}
 
Example 8
Source File: ActivityInstanceCancellationCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected ExecutionEntity determineSourceInstanceExecution(final CommandContext commandContext) {
  ExecutionEntity processInstance = commandContext.getExecutionManager().findExecutionById(processInstanceId);

  // rebuild the mapping because the execution tree changes with every iteration
  ActivityExecutionTreeMapping mapping = new ActivityExecutionTreeMapping(commandContext, processInstanceId);

  ActivityInstance instance = commandContext.runWithoutAuthorization(new Callable<ActivityInstance>() {
    public ActivityInstance call() throws Exception {
      return new GetActivityInstanceCmd(processInstanceId).execute(commandContext);
    }
  });

  ActivityInstance instanceToCancel = findActivityInstance(instance, activityInstanceId);
  EnsureUtil.ensureNotNull(NotValidException.class,
      describeFailure("Activity instance '" + activityInstanceId + "' does not exist"),
      "activityInstance",
      instanceToCancel);
  ExecutionEntity scopeExecution = getScopeExecutionForActivityInstance(processInstance, mapping, instanceToCancel);

  return scopeExecution;
}
 
Example 9
Source File: CorrelateMessageCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public MessageCorrelationResultImpl execute(final CommandContext commandContext) {
  ensureAtLeastOneNotNull(
      "At least one of the following correlation criteria has to be present: " + "messageName, businessKey, correlationKeys, processInstanceId", messageName,
      builder.getBusinessKey(), builder.getCorrelationProcessInstanceVariables(), builder.getProcessInstanceId());

  final CorrelationHandler correlationHandler = Context.getProcessEngineConfiguration().getCorrelationHandler();
  final CorrelationSet correlationSet = new CorrelationSet(builder);

  CorrelationHandlerResult correlationResult = null;
  if (startMessageOnly) {
    List<CorrelationHandlerResult> correlationResults = commandContext.runWithoutAuthorization(new Callable<List<CorrelationHandlerResult>>() {
      public List<CorrelationHandlerResult> call() throws Exception {
        return correlationHandler.correlateStartMessages(commandContext, messageName, correlationSet);
      }
    });
    if (correlationResults.isEmpty()) {
      throw new MismatchingMessageCorrelationException(messageName, "No process definition matches the parameters");
    } else if (correlationResults.size() > 1) {
      throw LOG.exceptionCorrelateMessageToSingleProcessDefinition(messageName, correlationResults.size(), correlationSet);
    } else {
      correlationResult = correlationResults.get(0);
    }
  } else {
    correlationResult = commandContext.runWithoutAuthorization(new Callable<CorrelationHandlerResult>() {
      public CorrelationHandlerResult call() throws Exception {
        return correlationHandler.correlateMessage(commandContext, messageName, correlationSet);
      }
    });

    if (correlationResult == null) {
      throw new MismatchingMessageCorrelationException(messageName, "No process definition or execution matches the parameters");
    }
  }

  // check authorization
  checkAuthorization(correlationResult);

  return createMessageCorrelationResult(commandContext, correlationResult);
}
 
Example 10
Source File: ProcessInstanceModificationCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ProcessInstanceModificationBuilderImpl createProcessInstanceModificationBuilder(
    String processInstanceId, CommandContext commandContext) {

  ProcessInstanceModificationBuilderImpl processInstanceModificationBuilder =
      new ProcessInstanceModificationBuilderImpl(commandContext, processInstanceId);

  List<AbstractProcessInstanceModificationCommand> operations =
      processInstanceModificationBuilder.getModificationOperations();

  ActivityInstance activityInstanceTree = null;

  for (AbstractProcessInstanceModificationCommand instruction : builder.getInstructions()) {

    instruction.setProcessInstanceId(processInstanceId);

    if (!(instruction instanceof ActivityCancellationCmd) ||
        !((ActivityCancellationCmd)instruction).isCancelCurrentActiveActivityInstances()) {
      operations.add(instruction);
    }
    else {

      if (activityInstanceTree == null) {
        activityInstanceTree = commandContext.runWithoutAuthorization(() ->
            new GetActivityInstanceCmd(processInstanceId).execute(commandContext));
      }

      ActivityCancellationCmd cancellationInstruction = (ActivityCancellationCmd) instruction;
      List<AbstractInstanceCancellationCmd> cmds =
          cancellationInstruction.createActivityInstanceCancellations(activityInstanceTree,
              commandContext);

      operations.addAll(cmds);
    }

  }

  return processInstanceModificationBuilder;
}
 
Example 11
Source File: AbstractSetStateCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Void execute(final CommandContext commandContext) {
  checkParameters(commandContext);
  checkAuthorization(commandContext);

  if (executionDate == null) {

    updateSuspensionState(commandContext, getNewSuspensionState());

    if (isIncludeSubResources()) {
      final AbstractSetStateCmd cmd = getNextCommand();
      if (cmd != null) {
        cmd.disableLogUserOperation();
        // avoids unnecessary authorization checks
        // pre-requirement: the necessary authorization check
        // for included resources should be done before this
        // call.
        commandContext.runWithoutAuthorization(new Callable<Void>() {
          public Void call() throws Exception {
            cmd.execute(commandContext);
            return null;
          }
        });
      }
    }

    triggerHistoryEvent(commandContext);
  } else {
    scheduleSuspensionStateUpdate(commandContext);
  }

  if (!isLogUserOperationDisabled()) {
    logUserOperation(commandContext);
  }

  return null;
}
 
Example 12
Source File: GetDeploymentDecisionRequirementsModelCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public InputStream execute(final CommandContext commandContext) {
  DecisionRequirementsDefinition decisionRequirementsDefinition = new GetDeploymentDecisionRequirementsDefinitionCmd(decisionRequirementsDefinitionId).execute(commandContext);

  final String deploymentId = decisionRequirementsDefinition.getDeploymentId();
  final String resourceName = decisionRequirementsDefinition.getResourceName();

  return commandContext.runWithoutAuthorization(new Callable<InputStream>() {
    public InputStream call() throws Exception {
      return new GetDeploymentResourceCmd(deploymentId, resourceName).execute(commandContext);
    }
  });
}
 
Example 13
Source File: GetDeployedStartFormCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected FormData getFormData(final CommandContext commandContext) {
  return commandContext.runWithoutAuthorization(new Callable<FormData>() {
    @Override
    public FormData call() throws Exception {
      return new GetStartFormCmd(processDefinitionId).execute(commandContext);
    }
  });
}
 
Example 14
Source File: ModifyProcessInstanceCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void checkCancellation(final CommandContext commandContext) {
  for (final AbstractProcessInstanceModificationCommand instruction : builder.getModificationOperations()) {
    if (instruction instanceof ActivityCancellationCmd
        && ((ActivityCancellationCmd) instruction).cancelCurrentActiveActivityInstances) {
      ActivityInstance activityInstanceTree = commandContext.runWithoutAuthorization(new Callable<ActivityInstance>() {
        @Override
        public ActivityInstance call() throws Exception {
          return new GetActivityInstanceCmd(((ActivityCancellationCmd) instruction).processInstanceId).execute(commandContext);
        }
      });
      ((ActivityCancellationCmd) instruction).setActivityInstanceTreeToCancel(activityInstanceTree);
    }
  }
}
 
Example 15
Source File: BpmnModelInstanceCache.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected List<ProcessDefinition> getAllDefinitionsForDeployment(final String deploymentId) {
  final CommandContext commandContext = Context.getCommandContext();
  List<ProcessDefinition> allDefinitionsForDeployment = commandContext.runWithoutAuthorization(new Callable<List<ProcessDefinition>>() {
    public List<ProcessDefinition> call() throws Exception {
      return new ProcessDefinitionQueryImpl()
          .deploymentId(deploymentId)
          .list();
    }
  });
  return allDefinitionsForDeployment;
}
 
Example 16
Source File: ResourceDefinitionCache.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public T findDeployedDefinitionByKeyVersionAndTenantId(final String definitionKey, final Integer definitionVersion, final String tenantId) {
  final CommandContext commandContext = Context.getCommandContext();
  T definition = commandContext.runWithoutAuthorization(new Callable<T>() {
    public T call() throws Exception {
      return getManager().findDefinitionByKeyVersionAndTenantId(definitionKey, definitionVersion, tenantId);
    }
  });
  checkInvalidDefinitionByKeyVersionAndTenantId(definitionKey, definitionVersion, tenantId, definition);
  definition = resolveDefinition(definition);
  return definition;
}
 
Example 17
Source File: GetDeployedTaskFormCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected FormData getFormData(final CommandContext commandContext) {
  return commandContext.runWithoutAuthorization(new Callable<FormData>() {

    @Override
    public FormData call() throws Exception {
      return new GetTaskFormCmd(taskId).execute(commandContext);
    }
  });
}
 
Example 18
Source File: DeleteDeploymentCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public Void execute(final CommandContext commandContext) {
  ensureNotNull("deploymentId", deploymentId);

  for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
    checker.checkDeleteDeployment(deploymentId);
  }

  UserOperationLogManager logManager = commandContext.getOperationLogManager();
  List<PropertyChange> propertyChanges = Arrays.asList(new PropertyChange("cascade", null, cascade));
  logManager.logDeploymentOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE, deploymentId, propertyChanges);

  commandContext
    .getDeploymentManager()
    .deleteDeployment(deploymentId, cascade, skipCustomListeners, skipIoMappings);

  ProcessApplicationReference processApplicationReference = Context
    .getProcessEngineConfiguration()
    .getProcessApplicationManager()
    .getProcessApplicationForDeployment(deploymentId);

  DeleteDeploymentFailListener listener = new DeleteDeploymentFailListener(deploymentId, processApplicationReference,
    Context.getProcessEngineConfiguration().getCommandExecutorTxRequiresNew());

  try {
    commandContext.runWithoutAuthorization(new Callable<Void>() {
      public Void call() throws Exception {
        new UnregisterProcessApplicationCmd(deploymentId, false).execute(commandContext);
        new UnregisterDeploymentCmd(Collections.singleton(deploymentId)).execute(commandContext);
        return null;
      }
    });
  } finally {
    try {
      commandContext.getTransactionContext().addTransactionListener(TransactionState.ROLLED_BACK, listener);
    }
    catch (Exception e) {
      TX_LOG.debugTransactionOperation("Could not register transaction synchronization. Probably the TX has already been rolled back by application code.");
      listener.execute(commandContext);
    }
  }


  return null;
}
 
Example 19
Source File: DeleteHistoricProcessInstancesCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
  ensureNotEmpty(BadUserRequestException.class,"processInstanceIds", processInstanceIds);
  ensureNotContainsNull(BadUserRequestException.class, "processInstanceId is null", "processInstanceIds", processInstanceIds);

  // Check if process instance is still running
  List<HistoricProcessInstance> instances = commandContext.runWithoutAuthorization(new Callable<List<HistoricProcessInstance>>() {
    @Override
    public List<HistoricProcessInstance> call() throws Exception {
      return new HistoricProcessInstanceQueryImpl().processInstanceIds(new HashSet<String>(processInstanceIds)).list();
    }
  });

  if (failIfNotExists) {
    if (processInstanceIds.size() == 1) {
      ensureNotEmpty(BadUserRequestException.class, "No historic process instance found with id: " + processInstanceIds.get(0), "historicProcessInstanceIds",
          instances);
    } else {
      ensureNotEmpty(BadUserRequestException.class, "No historic process instances found", "historicProcessInstanceIds", instances);
    }
  }

  List<String> existingIds = new ArrayList<String>();

  for (HistoricProcessInstance historicProcessInstance : instances) {
    existingIds.add(historicProcessInstance.getId());

    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
      checker.checkDeleteHistoricProcessInstance(historicProcessInstance);
    }

    ensureNotNull(BadUserRequestException.class, "Process instance is still running, cannot delete historic process instance: " + historicProcessInstance, "instance.getEndTime()", historicProcessInstance.getEndTime());
  }

  if(failIfNotExists) {
    ArrayList<String> nonExistingIds = new ArrayList<String>(processInstanceIds);
    nonExistingIds.removeAll(existingIds);
    if(nonExistingIds.size() != 0) {
      throw new BadUserRequestException("No historic process instance found with id: " + nonExistingIds);
    }
  }

  if(existingIds.size() > 0) {
    commandContext.getHistoricProcessInstanceManager().deleteHistoricProcessInstanceByIds(existingIds);
  }
  writeUserOperationLog(commandContext, existingIds.size());

  return null;
}
 
Example 20
Source File: AbstractDeleteProcessInstanceCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void deleteProcessInstance(
    final CommandContext commandContext,
    String processInstanceId,
    final String deleteReason,
    final boolean skipCustomListeners,
    final boolean externallyTerminated,
    final boolean skipIoMappings,
    boolean skipSubprocesses) {
  ensureNotNull(BadUserRequestException.class, "processInstanceId is null", "processInstanceId", processInstanceId);

  // fetch process instance
  ExecutionManager executionManager = commandContext.getExecutionManager();
  final ExecutionEntity execution = executionManager.findExecutionById(processInstanceId);

  if(!failIfNotExists && execution == null) {
    return;
  }

  ensureNotNull(BadUserRequestException.class, "No process instance found for id '" + processInstanceId + "'", "processInstance", execution);

  checkDeleteProcessInstance(execution, commandContext);

  // delete process instance
  commandContext
      .getExecutionManager()
      .deleteProcessInstance(processInstanceId, deleteReason, false, skipCustomListeners, externallyTerminated, skipIoMappings, skipSubprocesses);

  if (skipSubprocesses) {
    List<ProcessInstance> superProcesslist = commandContext.getProcessEngineConfiguration().getRuntimeService().createProcessInstanceQuery()
        .superProcessInstanceId(processInstanceId).list();
    triggerHistoryEvent(superProcesslist);
  }

  final ExecutionEntity superExecution = execution.getSuperExecution();
  if (superExecution != null) {
    commandContext.runWithoutAuthorization(new Callable<Void>() {
      public Void call() {
        ProcessInstanceModificationBuilderImpl builder = (ProcessInstanceModificationBuilderImpl) new ProcessInstanceModificationBuilderImpl(commandContext, superExecution.getProcessInstanceId(), deleteReason)
          .cancellationSourceExternal(externallyTerminated).cancelActivityInstance(superExecution.getActivityInstanceId());
        builder.execute(false, skipCustomListeners, skipIoMappings);
        return null;
      }
    });

  }

  // create user operation log
  commandContext.getOperationLogManager()
      .logProcessInstanceOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE, processInstanceId,
          null, null, Collections.singletonList(PropertyChange.EMPTY_CHANGE));
}