Java Code Examples for org.camunda.bpm.engine.IdentityService#clearAuthentication()

The following examples show how to use org.camunda.bpm.engine.IdentityService#clearAuthentication() . 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: ApplicationContextPathUtil.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static String getApplicationPathForDeployment(ProcessEngine engine, String deploymentId) {

    // get the name of the process application that made the deployment
    String processApplicationName = null;
    IdentityService identityService = engine.getIdentityService();
    Authentication currentAuthentication = identityService.getCurrentAuthentication();
    try {
      identityService.clearAuthentication();
      processApplicationName = engine.getManagementService().getProcessApplicationForDeployment(deploymentId);
    } finally {
      identityService.setAuthentication(currentAuthentication);
    }

    if (processApplicationName == null) {
      // no a process application deployment
      return null;
    } else {
      ProcessApplicationService processApplicationService = BpmPlatform.getProcessApplicationService();
      ProcessApplicationInfo processApplicationInfo = processApplicationService.getProcessApplicationInfo(processApplicationName);
      return processApplicationInfo.getProperties().get(ProcessApplicationInfo.PROP_SERVLET_CONTEXT_PATH);
    }
  }
 
Example 2
Source File: SuspendProcessDefinitionDeleteScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("createUserOperationLogEntriesForDelete")
public static ScenarioSetup createUserOperationLogEntries() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      String processInstanceBusinessKey = "SuspendProcessDefinitionDeleteScenario";
      ProcessInstance processInstance1 = engine.getRuntimeService().startProcessInstanceByKey("timerBoundaryProcess", processInstanceBusinessKey);
      ProcessInstance processInstance2 = engine.getRuntimeService().startProcessInstanceByKey("timerBoundaryProcess", processInstanceBusinessKey);
      ProcessInstance processInstance3 = engine.getRuntimeService().startProcessInstanceByKey("timerBoundaryProcess", processInstanceBusinessKey);
      
      IdentityService identityService = engine.getIdentityService();
      identityService.setAuthentication("jane01", null);

      engine.getProcessEngineConfiguration().setAuthorizationEnabled(false);
      ClockUtil.setCurrentTime(new Date(1549000000000l));
      engine.getRuntimeService().suspendProcessInstanceById(processInstance1.getId());
      ClockUtil.setCurrentTime(new Date(1549100000000l));
      engine.getRuntimeService().suspendProcessInstanceById(processInstance2.getId());
      ClockUtil.setCurrentTime(new Date(1549200000000l));
      engine.getRuntimeService().suspendProcessInstanceById(processInstance3.getId());

      ClockUtil.reset();
      identityService.clearAuthentication();
    }
  };
}
 
Example 3
Source File: CreateStandaloneTaskScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("createUserOperationLogEntries")
public static ScenarioSetup createUserOperationLogEntries() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      IdentityService identityService = engine.getIdentityService();
      identityService.setAuthentication("jane02", null);

      TaskService taskService = engine.getTaskService();

      String taskId = "myTaskForUserOperationLog";
      Task task = taskService.newTask(taskId);
      taskService.saveTask(task);

      identityService.clearAuthentication();
    }
  };
}
 
Example 4
Source File: SetAssigneeProcessInstanceTaskScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("createUserOperationLogEntries")
public static ScenarioSetup createUserOperationLogEntries() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      IdentityService identityService = engine.getIdentityService();
      String processInstanceBusinessKey = "SetAssigneeProcessInstanceTaskScenario";
      engine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess_userOpLog", processInstanceBusinessKey);

      identityService.setAuthentication("mary02", null);

      TaskService taskService = engine.getTaskService();
      List<Task> list = taskService.createTaskQuery().processInstanceBusinessKey(processInstanceBusinessKey).list();
      Task task = list.get(0);
      taskService.setAssignee(task.getId(), "john");

      identityService.clearAuthentication();
    }
  };
}
 
Example 5
Source File: CreateStandaloneTaskDeleteScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("createUserOperationLogEntriesForDelete")
public static ScenarioSetup createUserOperationLogEntries() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      IdentityService identityService = engine.getIdentityService();
      identityService.setAuthentication("mary01", null);

      TaskService taskService = engine.getTaskService();

      String taskId = "myTaskForUserOperationLogDel";
      Task task = taskService.newTask(taskId);
      taskService.saveTask(task);

      identityService.clearAuthentication();
    }
  };
}
 
Example 6
Source File: HistoricInstancePermissionsWithoutProcDefKeyScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("createProcInstancesAndOpLogs")
public static ScenarioSetup createProcInstancesAndOpLogs() {
  return (engine, scenarioName) -> {
    IdentityService identityService = engine.getIdentityService();
    for (int i = 0; i < 5; i++) {
      String processInstanceId = engine.getRuntimeService()
          .startProcessInstanceByKey("oneTaskProcess",
              "HistPermsWithoutProcDefKeyScenarioBusinessKey" + i)
          .getId();

      identityService.setAuthentication("mary02", null);

      TaskService taskService = engine.getTaskService();

      String taskId = taskService.createTaskQuery()
          .processInstanceId(processInstanceId)
          .singleResult()
          .getId();

      taskService.setAssignee(taskId, "john");

      identityService.clearAuthentication();
    }
  };
}
 
Example 7
Source File: FetchAndLockHandlerImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected FetchAndLockResult tryFetchAndLock(FetchAndLockRequest request) {

    ProcessEngine processEngine = null;
    IdentityService identityService = null;
    FetchAndLockResult result = null;

    try {
      processEngine = getProcessEngine(request);

      identityService = processEngine.getIdentityService();
      identityService.setAuthentication(request.getAuthentication());

      FetchExternalTasksExtendedDto fetchingDto = request.getDto();
      List<LockedExternalTaskDto> lockedTasks = executeFetchAndLock(fetchingDto, processEngine);
      result = FetchAndLockResult.successful(lockedTasks);
    }
    catch (Exception e) {
      result = FetchAndLockResult.failed(e);
    }
    finally {
      if (identityService != null) {
        identityService.clearAuthentication();
      }
    }

    return result;
  }
 
Example 8
Source File: TaskAttachmentResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private boolean isHistoryEnabled() {
  IdentityService identityService = engine.getIdentityService();
  Authentication currentAuthentication = identityService.getCurrentAuthentication();
  try {
    identityService.clearAuthentication();
    int historyLevel = engine.getManagementService().getHistoryLevel();
    return historyLevel > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE;
  } finally {
    identityService.setAuthentication(currentAuthentication);
  }
}
 
Example 9
Source File: TaskCommentResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private boolean isHistoryEnabled() {
  IdentityService identityService = engine.getIdentityService();
  Authentication currentAuthentication = identityService.getCurrentAuthentication();
  try {
    identityService.clearAuthentication();
    int historyLevel = engine.getManagementService().getHistoryLevel();
    return historyLevel > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE;
  } finally {
    identityService.setAuthentication(currentAuthentication);
  }
}
 
Example 10
Source File: ExecuteJobsCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public Void execute(CommandContext commandContext) {
  ensureNotNull("jobId", jobId);

  final JobEntity job = commandContext.getDbEntityManager().selectById(JobEntity.class, jobId);

  final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
  final IdentityService identityService = processEngineConfiguration.getIdentityService();

  final JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();

  if (job == null) {
    if (jobExecutorContext != null) {
      // CAM-1842
      // Job was acquired but does not exist anymore. This is not a problem.
      // It usually means that the job has been deleted after it was acquired which can happen if the
      // the activity instance corresponding to the job is cancelled.
      LOG.debugAcquiredJobNotFound(jobId);
      return null;

    } else {
      throw LOG.jobNotFoundException(jobId);
    }
  }

  jobFailureCollector.setJob(job);

  if (jobExecutorContext == null) { // if null, then we are not called by the job executor
    for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
      checker.checkUpdateJob(job);
    }
    // write a user operation log since we're not called by the job executor
    commandContext.getOperationLogManager().logJobOperation(UserOperationLogEntry.OPERATION_TYPE_EXECUTE,
        jobId, job.getJobDefinitionId(), job.getProcessInstanceId(), job.getProcessDefinitionId(),
        job.getProcessDefinitionKey(), PropertyChange.EMPTY_CHANGE);
  } else {
    jobExecutorContext.setCurrentJob(job);

    // if the job is called by the job executor then set the tenant id of the job
    // as authenticated tenant to enable tenant checks
    String tenantId = job.getTenantId();
    if (tenantId != null) {
      identityService.setAuthentication(null, null, Collections.singletonList(tenantId));
    }
  }

  try {

    // register as command context close lister to intercept exceptions on flush
    commandContext.registerCommandContextListener(jobFailureCollector);

    commandContext.setCurrentJob(job);

    job.execute(commandContext);

  } catch (Throwable t) {
    jobFailureCollector.setFailedActivityId(Context.getCommandInvocationContext().getProcessDataContext().getLatestPropertyValue(ProcessDataContext.PROPERTY_ACTIVITY_ID));
    throw t;
  } finally {
    if (jobExecutorContext != null) {
      jobExecutorContext.setCurrentJob(null);
      identityService.clearAuthentication();
    }
  }

  return null;
}