Search in sources :

Example 1 with IdentityProvider

use of org.kie.internal.identity.IdentityProvider in project jbpm by kiegroup.

the class IdentityProviderAwareProcessListenerTest method testSetUser.

@Test
public void testSetUser() {
    final IdentityProvider identityProvider = mock(IdentityProvider.class);
    final String userId = "userId";
    when(identityProvider.getName()).thenReturn(userId);
    when(environment.get("IdentityProvider")).thenReturn(identityProvider);
    final WorkflowProcessInstance processInstance = mock(WorkflowProcessInstance.class);
    final HashMap<String, Object> metaData = new HashMap<>();
    when(processInstance.getMetaData()).thenReturn(metaData);
    final ProcessStartedEvent event = new ProcessStartedEventImpl(processInstance, mock(KieRuntime.class));
    listener.beforeProcessStarted(event);
    assertEquals(userId, metaData.get("OwnerId"));
    verify(processInstance).setVariable("initiator", userId);
}
Also used : HashMap(java.util.HashMap) KieRuntime(org.kie.api.runtime.KieRuntime) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) IdentityProvider(org.kie.internal.identity.IdentityProvider) ProcessStartedEventImpl(org.drools.core.event.ProcessStartedEventImpl) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Example 2 with IdentityProvider

use of org.kie.internal.identity.IdentityProvider in project jbpm by kiegroup.

the class TaskCommandExecutorImpl method addUserIdToContext.

protected void addUserIdToContext(TaskCommand<?> command, RequestContext context) {
    if (context instanceof org.kie.internal.task.api.TaskContext) {
        org.kie.internal.task.api.TaskContext taskContext = (org.kie.internal.task.api.TaskContext) context;
        IdentityProvider identityProvider = (IdentityProvider) taskContext.get(EnvironmentName.IDENTITY_PROVIDER);
        String userId = command.getUserId();
        if (command instanceof CompositeCommand) {
            userId = ((CompositeCommand<?>) command).getMainCommand().getUserId();
        }
        if (userId == null && identityProvider != null) {
            userId = identityProvider.getName();
            command.setUserId(userId);
        }
        taskContext.setUserId(userId);
    }
}
Also used : IdentityProvider(org.kie.internal.identity.IdentityProvider)

Example 3 with IdentityProvider

use of org.kie.internal.identity.IdentityProvider in project jbpm by kiegroup.

the class BusinessAdminTasksPreprocessor method preprocess.

@SuppressWarnings("rawtypes")
@Override
public void preprocess(DataSetLookup lookup) {
    if (identityProvider == null) {
        return;
    }
    if (ADMIN_USER.equals(identityProvider.getName()) || identityProvider.getRoles().stream().filter(s -> s.equals(ADMIN_GROUP)).findFirst().isPresent()) {
        return;
    }
    final List<Comparable> orgEntities = new ArrayList<Comparable>(identityProvider.getRoles());
    orgEntities.add(identityProvider.getName());
    final ColumnFilter columnFilter = equalsTo(COLUMN_ORGANIZATIONAL_ENTITY, orgEntities);
    LOGGER.debug("Adding column filter: {}", columnFilter);
    if (lookup.getFirstFilterOp() != null) {
        lookup.getFirstFilterOp().addFilterColumn(columnFilter);
    } else {
        DataSetFilter filter = new DataSetFilter();
        filter.addFilterColumn(columnFilter);
        lookup.addOperation(filter);
    }
    super.preprocess(lookup);
}
Also used : FilterFactory.equalsTo(org.dashbuilder.dataset.filter.FilterFactory.equalsTo) IdentityProvider(org.kie.internal.identity.IdentityProvider) COLUMN_ORGANIZATIONAL_ENTITY(org.jbpm.services.api.query.QueryResultMapper.COLUMN_ORGANIZATIONAL_ENTITY) DataSetLookup(org.dashbuilder.dataset.DataSetLookup) List(java.util.List) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) ColumnFilter(org.dashbuilder.dataset.filter.ColumnFilter) DataSetMetadata(org.dashbuilder.dataset.DataSetMetadata) DataSetFilter(org.dashbuilder.dataset.filter.DataSetFilter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) DataSetFilter(org.dashbuilder.dataset.filter.DataSetFilter) ColumnFilter(org.dashbuilder.dataset.filter.ColumnFilter)

Aggregations

IdentityProvider (org.kie.internal.identity.IdentityProvider)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DataSetLookup (org.dashbuilder.dataset.DataSetLookup)1 DataSetMetadata (org.dashbuilder.dataset.DataSetMetadata)1 ColumnFilter (org.dashbuilder.dataset.filter.ColumnFilter)1 DataSetFilter (org.dashbuilder.dataset.filter.DataSetFilter)1 FilterFactory.equalsTo (org.dashbuilder.dataset.filter.FilterFactory.equalsTo)1 ProcessStartedEventImpl (org.drools.core.event.ProcessStartedEventImpl)1 COLUMN_ORGANIZATIONAL_ENTITY (org.jbpm.services.api.query.QueryResultMapper.COLUMN_ORGANIZATIONAL_ENTITY)1 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)1 Test (org.junit.Test)1 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)1 KieRuntime (org.kie.api.runtime.KieRuntime)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1