Search in sources :

Example 1 with SecurityPolicy

use of org.kie.kogito.auth.SecurityPolicy in project kogito-runtimes by kiegroup.

the class KafkaProcessInstancesIT method testBasicFlow.

@Test
void testBasicFlow() {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    listener.setKafkaStreams(createStreams(process));
    process.setProcessInstancesFactory(factory);
    process.configure();
    listener.getKafkaStreams().start();
    ProcessInstances<BpmnVariables> instances = process.instances();
    assertThat(instances.size()).isZero();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(singletonMap("test", "test")));
    processInstance.start();
    assertEquals(STATE_ACTIVE, processInstance.status());
    await().until(() -> instances.values().size() == 1);
    SecurityPolicy asJohn = SecurityPolicy.of(IdentityProviders.of("john"));
    assertThat(instances.values().iterator().next().workItems(asJohn)).hasSize(1);
    List<WorkItem> workItems = processInstance.workItems(asJohn);
    assertThat(workItems).hasSize(1);
    WorkItem workItem = workItems.get(0);
    assertEquals("john", workItem.getParameters().get("ActorId"));
    processInstance.completeWorkItem(workItem.getId(), null, asJohn);
    assertEquals(STATE_COMPLETED, processInstance.status());
    assertThat(instances.size()).isZero();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) WorkItem(org.kie.kogito.process.WorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 2 with SecurityPolicy

use of org.kie.kogito.auth.SecurityPolicy in project kogito-runtimes by kiegroup.

the class HumanTaskServiceImpl method get.

@Override
public ExtendedDataContext get(LocalId id, MetaDataContext meta) {
    TaskMetaDataContext metaCtx = meta.as(TaskMetaDataContext.class);
    SecurityPolicy securityPolicy = convertPolicyObject(metaCtx.policy());
    try {
        // /tasks
        TaskIds taskIds = ProcessIdParser.select(id, TaskIds.class);
        ProcessInstanceId instanceId = taskIds.processInstanceId();
        Process<MappableToModel<Model>> process = parseProcess(instanceId.processId());
        String processInstanceIdString = instanceId.processInstanceId();
        List<String> tasks = svc.getTasks(process, processInstanceIdString, securityPolicy).orElseThrow().stream().map(wi -> taskIds.get(wi.getName()).instances().get(wi.getId()).asLocalUri().path()).collect(Collectors.toList());
        MapDataContext mdc = MapDataContext.create();
        mdc.set("tasks", tasks);
        return ExtendedDataContext.of(mdc, EmptyDataContext.Instance);
    } catch (IllegalArgumentException e) {
        // /tasks/id
        TaskInstanceId taskInstanceId = ProcessIdParser.select(id, TaskInstanceId.class);
        ProcessInstanceId instanceId = taskInstanceId.taskId().processInstanceId();
        Process<MappableToModel<Model>> process = parseProcess(instanceId.processId());
        String taskInstanceIdString = taskInstanceId.taskInstanceId();
        String processInstanceIdString = instanceId.processInstanceId();
        WorkItem workItem = svc.getTask(process, processInstanceIdString, taskInstanceIdString, securityPolicy, Function.identity()).orElseThrow(() -> new IllegalArgumentException("Cannot find ID " + id.asLocalUri().path()));
        return ExtendedDataContext.ofData(MapDataContext.of(workItem.getResults()));
    }
}
Also used : org.kie.kogito.process(org.kie.kogito.process) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) Collection(java.util.Collection) Policy(org.kie.kogito.incubation.processes.services.contexts.Policy) MappableToModel(org.kie.kogito.MappableToModel) HumanTaskHelper(org.jbpm.process.instance.impl.humantask.HumanTaskHelper) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) HumanTaskService(org.kie.kogito.incubation.processes.services.humantask.HumanTaskService) UnitOfWorkExecutor(org.kie.kogito.services.uow.UnitOfWorkExecutor) Application(org.kie.kogito.Application) KogitoNode(org.kie.kogito.internal.process.runtime.KogitoNode) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) org.kie.kogito.incubation.processes(org.kie.kogito.incubation.processes) List(java.util.List) Model(org.kie.kogito.Model) org.kie.kogito.incubation.common(org.kie.kogito.incubation.common) IdentityProviders(org.kie.kogito.auth.IdentityProviders) Map(java.util.Map) Process(org.kie.kogito.process.Process) TaskMetaDataContext(org.kie.kogito.incubation.processes.services.contexts.TaskMetaDataContext) TaskMetaDataContext(org.kie.kogito.incubation.processes.services.contexts.TaskMetaDataContext) Process(org.kie.kogito.process.Process) MappableToModel(org.kie.kogito.MappableToModel) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) MappableToModel(org.kie.kogito.MappableToModel) Model(org.kie.kogito.Model)

Example 3 with SecurityPolicy

use of org.kie.kogito.auth.SecurityPolicy in project kogito-runtimes by kiegroup.

the class HumanTaskServiceImpl method transition.

@Override
public ExtendedDataContext transition(LocalId id, DataContext dataContext) {
    ExtendedDataContext edc = dataContext.as(ExtendedDataContext.class);
    TaskMetaDataContext mdc = edc.meta().as(TaskMetaDataContext.class);
    SecurityPolicy securityPolicy = convertPolicyObject(mdc.policy());
    String phase = mdc.phase();
    Objects.requireNonNull(phase, "Phase must be specified");
    TaskInstanceId taskInstanceId = ProcessIdParser.select(id, TaskInstanceId.class);
    // must validate the task id
    TaskId taskId = taskInstanceId.taskId();
    ProcessInstanceId instanceId = taskId.processInstanceId();
    Process<MappableToModel<Model>> process = parseProcess(instanceId.processId());
    Collection<KogitoNode> tasks = process.findNodes(n -> n instanceof HumanTaskNode && ((HumanTaskNode) n).getWork().getParameter("TaskName").equals(taskId.taskId()));
    if (tasks.isEmpty()) {
        throw new IllegalArgumentException("No such taskId " + taskId.taskId());
    }
    String taskInstanceIdString = taskInstanceId.taskInstanceId();
    String processInstanceIdString = instanceId.processInstanceId();
    Map<String, Object> map = dataContext.as(MapDataContext.class).toMap();
    MappableToModel<Model> model = process.createModel();
    model.fromMap(map);
    Model result = svc.taskTransition(process, processInstanceIdString, taskInstanceIdString, phase, securityPolicy, model).orElseThrow();
    return ExtendedDataContext.ofData(MapDataContext.of(result.toMap()));
}
Also used : TaskMetaDataContext(org.kie.kogito.incubation.processes.services.contexts.TaskMetaDataContext) KogitoNode(org.kie.kogito.internal.process.runtime.KogitoNode) MappableToModel(org.kie.kogito.MappableToModel) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) MappableToModel(org.kie.kogito.MappableToModel) Model(org.kie.kogito.Model) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode)

Example 4 with SecurityPolicy

use of org.kie.kogito.auth.SecurityPolicy in project kogito-runtimes by kiegroup.

the class HumanTaskServiceImpl method update.

@Override
public ExtendedDataContext update(LocalId id, DataContext dataContext) {
    ExtendedDataContext edc = dataContext.as(ExtendedDataContext.class);
    TaskMetaDataContext mdc = edc.meta().as(TaskMetaDataContext.class);
    SecurityPolicy securityPolicy = convertPolicyObject(mdc.policy());
    TaskInstanceId taskInstanceId = ProcessIdParser.select(id, TaskInstanceId.class);
    ProcessInstanceId instanceId = taskInstanceId.taskId().processInstanceId();
    Process<MappableToModel<Model>> process = parseProcess(instanceId.processId());
    String taskInstanceIdString = taskInstanceId.taskInstanceId();
    String processInstanceIdString = instanceId.processInstanceId();
    Map<String, Object> map = dataContext.as(MapDataContext.class).toMap();
    Map<String, Object> result = UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(processInstanceIdString).map(pi -> {
        pi.updateWorkItem(taskInstanceIdString, wi -> HumanTaskHelper.updateContent(wi, map), securityPolicy);
        return pi.variables().toModel();
    })).orElseThrow().toMap();
    return ExtendedDataContext.ofData(MapDataContext.of(result));
}
Also used : org.kie.kogito.process(org.kie.kogito.process) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) Collection(java.util.Collection) Policy(org.kie.kogito.incubation.processes.services.contexts.Policy) MappableToModel(org.kie.kogito.MappableToModel) HumanTaskHelper(org.jbpm.process.instance.impl.humantask.HumanTaskHelper) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) HumanTaskService(org.kie.kogito.incubation.processes.services.humantask.HumanTaskService) UnitOfWorkExecutor(org.kie.kogito.services.uow.UnitOfWorkExecutor) Application(org.kie.kogito.Application) KogitoNode(org.kie.kogito.internal.process.runtime.KogitoNode) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) org.kie.kogito.incubation.processes(org.kie.kogito.incubation.processes) List(java.util.List) Model(org.kie.kogito.Model) org.kie.kogito.incubation.common(org.kie.kogito.incubation.common) IdentityProviders(org.kie.kogito.auth.IdentityProviders) Map(java.util.Map) Process(org.kie.kogito.process.Process) TaskMetaDataContext(org.kie.kogito.incubation.processes.services.contexts.TaskMetaDataContext) TaskMetaDataContext(org.kie.kogito.incubation.processes.services.contexts.TaskMetaDataContext) MappableToModel(org.kie.kogito.MappableToModel) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy)

Example 5 with SecurityPolicy

use of org.kie.kogito.auth.SecurityPolicy in project kogito-runtimes by kiegroup.

the class CacheProcessInstancesIT method testBasicFlow.

@Test
void testBasicFlow() {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(new CacheProcessInstancesFactory(cacheManager));
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    assertEquals(STATE_ACTIVE, processInstance.status());
    assertThat(process.instances().size()).isOne();
    SecurityPolicy asJohn = SecurityPolicy.of(new StaticIdentityProvider("john"));
    assertThat(process.instances().values().iterator().next().workItems(asJohn)).hasSize(1);
    List<WorkItem> workItems = processInstance.workItems(asJohn);
    assertThat(workItems).hasSize(1);
    WorkItem workItem = workItems.get(0);
    assertEquals("john", workItem.getParameters().get("ActorId"));
    processInstance.completeWorkItem(workItem.getId(), null, asJohn);
    assertEquals(STATE_COMPLETED, processInstance.status());
    assertThat(process.instances().size()).isZero();
}
Also used : StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) WorkItem(org.kie.kogito.process.WorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Aggregations

SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)7 Model (org.kie.kogito.Model)5 Test (org.junit.jupiter.api.Test)4 Application (org.kie.kogito.Application)4 WorkItem (org.kie.kogito.process.WorkItem)4 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)3 MappableToModel (org.kie.kogito.MappableToModel)3 TaskMetaDataContext (org.kie.kogito.incubation.processes.services.contexts.TaskMetaDataContext)3 KogitoNode (org.kie.kogito.internal.process.runtime.KogitoNode)3 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 HumanTaskHelper (org.jbpm.process.instance.impl.humantask.HumanTaskHelper)2 IdentityProviders (org.kie.kogito.auth.IdentityProviders)2