Search in sources :

Example 1 with StaticIdentityProvider

use of io.automatiko.engine.services.identity.StaticIdentityProvider in project automatiko-engine by automatiko-io.

the class AccessPolicyTest method testAssignInitiatorFromIdentity.

@Test
public void testAssignInitiatorFromIdentity() throws Exception {
    IdentityProvider.set(securityPolicy.value());
    Application app = generateCodeProcessesOnly("access-policy/UserTasksProcessWithAccessPolicy.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.initiator()).hasValue("john");
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // set identity to other user than initiator or any of the assigned human task actors
    IdentityProvider.set(new StaticIdentityProvider("mike"));
    // not initiator so can't
    // update process instance model
    assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.updateVariables(null));
    // abort process instance
    assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.abort());
    // signal process instance
    assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.send(Sig.of("test")));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // set identity to one of the assigned human task actors but other than initiator
    IdentityProvider.set(new StaticIdentityProvider("mary"));
    processInstance.send(Sig.of("test"));
    // set identity to trusted identity to verify system actions can go through
    IdentityProvider.set(new TrustedIdentityProvider("System<test>"));
    processInstance.send(Sig.of("test"));
    // go back to initiator as identity that is allowed to perform operations
    IdentityProvider.set(securityPolicy.value());
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) AccessDeniedException(io.automatiko.engine.api.auth.AccessDeniedException) HashMap(java.util.HashMap) TrustedIdentityProvider(io.automatiko.engine.api.auth.TrustedIdentityProvider) 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 StaticIdentityProvider

use of io.automatiko.engine.services.identity.StaticIdentityProvider in project automatiko-engine by automatiko-io.

the class AccessPolicyTest method testAssignInitiatorFromVariable.

@Test
public void testAssignInitiatorFromVariable() throws Exception {
    Application app = generateCodeProcessesOnly("access-policy/UserTasksProcessWithAccessPolicyVar.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("name", "john");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    IdentityProvider.set(securityPolicy.value());
    assertThat(processInstance.initiator()).hasValue("john");
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // set identity to other user than initiator or any of the assigned human task actors
    IdentityProvider.set(new StaticIdentityProvider("mike"));
    // not initiator so can't
    // update process instance model
    assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.updateVariables(null));
    // abort process instance
    assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.abort());
    // signal process instance
    assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> processInstance.send(Sig.of("test")));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // set identity to one of the assigned human task actors but other than initiator
    IdentityProvider.set(new StaticIdentityProvider("mary"));
    processInstance.send(Sig.of("test"));
    // go back to initiator as identity that is allowed to perform operations
    IdentityProvider.set(securityPolicy.value());
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) AccessDeniedException(io.automatiko.engine.api.auth.AccessDeniedException) HashMap(java.util.HashMap) 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 3 with StaticIdentityProvider

use of io.automatiko.engine.services.identity.StaticIdentityProvider in project automatiko-engine by automatiko-io.

the class SecuredIdentitySupplier method buildIdentityProvider.

public IdentityProvider buildIdentityProvider(String user, List<String> roles) {
    if (IdentityProvider.isSet()) {
        return IdentityProvider.get();
    }
    Principal principal = retrievePrincipal();
    if (securityInstance.isUnsatisfied() || principal == null) {
        StaticIdentityProvider current = new StaticIdentityProvider(adminRoleName.orElse("admin"), user, roles);
        IdentityProvider.set(current);
        return current;
    }
    String principalName = principal.getName();
    if (!authroizedOnly.orElse(true) && user != null) {
        principalName = user;
    }
    StaticIdentityProvider current = new StaticIdentityProvider(adminRoleName.orElse("admin"), principalName, mergeRoles(securityInstance.get(), roles), securityInstance.get().getAttributes());
    IdentityProvider.set(current);
    return current;
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) Principal(java.security.Principal)

Example 4 with StaticIdentityProvider

use of io.automatiko.engine.services.identity.StaticIdentityProvider in project automatiko-engine by automatiko-io.

the class PublishEventTest method testBasicUserTaskProcessWithTags.

@Test
public void testBasicUserTaskProcessWithTags() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcessTags.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("name", "john");
    m.fromMap(parameters);
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getTags()).hasSize(2).contains("important", "john");
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
    List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(3);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Ready", "UserTasksProcess");
    assertUserTaskInstanceEvent(events.get(2), "First Task", null, "1", "Completed", "UserTasksProcess");
    workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
    assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Completed", "UserTasksProcess");
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) WorkItem(io.automatiko.engine.api.workflow.WorkItem) 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 5 with StaticIdentityProvider

use of io.automatiko.engine.services.identity.StaticIdentityProvider in project automatiko-engine by automatiko-io.

the class PublishEventTest method testBasicUserTaskProcessWithSensitiveData.

@Test
public void testBasicUserTaskProcessWithSensitiveData() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcessSensitive.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("name", "john");
    parameters.put("ssn", "123-456");
    m.fromMap(parameters);
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getTags()).hasSize(0);
    assertThat(body.getVariables()).hasSize(1).containsEntry("name", "john");
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
    List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(3);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Ready", "UserTasksProcess");
    assertUserTaskInstanceEvent(events.get(2), "First Task", null, "1", "Completed", "UserTasksProcess");
    workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
    assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Completed", "UserTasksProcess");
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)11 Application (io.automatiko.engine.api.Application)10 Model (io.automatiko.engine.api.Model)9 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)9 HashMap (java.util.HashMap)9 Test (org.junit.jupiter.api.Test)9 WorkItem (io.automatiko.engine.api.workflow.WorkItem)6 AccessDeniedException (io.automatiko.engine.api.auth.AccessDeniedException)3 DataEvent (io.automatiko.engine.api.event.DataEvent)3 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)3 ProcessInstanceDataEvent (io.automatiko.engine.services.event.ProcessInstanceDataEvent)3 UserTaskInstanceDataEvent (io.automatiko.engine.services.event.UserTaskInstanceDataEvent)3 ProcessInstanceEventBody (io.automatiko.engine.services.event.impl.ProcessInstanceEventBody)3 SecurityPolicy (io.automatiko.engine.api.auth.SecurityPolicy)2 HumanTaskTransition (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition)2 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)1 IdentitySupplier (io.automatiko.engine.api.auth.IdentitySupplier)1 TrustedIdentityProvider (io.automatiko.engine.api.auth.TrustedIdentityProvider)1 Process (io.automatiko.engine.api.workflow.Process)1 ProcessErrors (io.automatiko.engine.api.workflow.ProcessErrors)1