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);
}
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);
}
}
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);
}
Aggregations