Search in sources :

Example 1 with SecurityPolicy

use of io.automatiko.engine.api.auth.SecurityPolicy in project automatiko-engine by automatiko-io.

the class UserTaskTest method testApprovalWithExcludedOwnerViaPhases.

@Test
public void testApprovalWithExcludedOwnerViaPhases() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/approval.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("approvals");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertEquals(io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.status());
    StaticIdentityProvider identity = new StaticIdentityProvider("admin", Collections.singletonList("managers"));
    SecurityPolicy policy = SecurityPolicy.of(identity);
    processInstance.workItems(policy);
    List<WorkItem> workItems = processInstance.workItems(policy);
    assertEquals(1, workItems.size());
    HumanTaskTransition transition = new HumanTaskTransition(Complete.ID, null, identity);
    processInstance.transitionWorkItem(workItems.get(0).getId(), transition);
    // actual owner of the first task is excluded owner on the second task so won't
    // find it
    workItems = processInstance.workItems(policy);
    assertEquals(0, workItems.size());
    identity = new StaticIdentityProvider("john", Collections.singletonList("managers"));
    policy = SecurityPolicy.of(identity);
    workItems = processInstance.workItems(policy);
    assertEquals(1, workItems.size());
    transition = new HumanTaskTransition(Complete.ID, null, identity);
    processInstance.transitionWorkItem(workItems.get(0).getId(), transition);
    assertEquals(io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) HashMap(java.util.HashMap) WorkItem(io.automatiko.engine.api.workflow.WorkItem) HumanTaskTransition(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition) SecurityPolicy(io.automatiko.engine.api.auth.SecurityPolicy) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 2 with SecurityPolicy

use of io.automatiko.engine.api.auth.SecurityPolicy in project automatiko-engine by automatiko-io.

the class UserTaskTest method testApprovalWithExcludedOwner.

@Test
public void testApprovalWithExcludedOwner() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/approval.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("approvals");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertEquals(io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.status());
    StaticIdentityProvider identity = new StaticIdentityProvider("admin", Collections.singletonList("managers"));
    SecurityPolicy policy = SecurityPolicy.of(identity);
    processInstance.workItems(policy);
    List<WorkItem> workItems = processInstance.workItems(policy);
    assertEquals(1, workItems.size());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, policy);
    // actual owner of the first task is excluded owner on the second task so won't
    // find it
    workItems = processInstance.workItems(policy);
    assertEquals(0, workItems.size());
    identity = new StaticIdentityProvider("john", Collections.singletonList("managers"));
    policy = SecurityPolicy.of(identity);
    workItems = processInstance.workItems(policy);
    assertEquals(1, workItems.size());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, policy);
    assertEquals(io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) HashMap(java.util.HashMap) SecurityPolicy(io.automatiko.engine.api.auth.SecurityPolicy) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) WorkItem(io.automatiko.engine.api.workflow.WorkItem) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

Application (io.automatiko.engine.api.Application)2 Model (io.automatiko.engine.api.Model)2 SecurityPolicy (io.automatiko.engine.api.auth.SecurityPolicy)2 WorkItem (io.automatiko.engine.api.workflow.WorkItem)2 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)2 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 HumanTaskTransition (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition)1