Skip to content

Commit

Permalink
improved authentication setting, correct formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nevries committed Mar 8, 2019
1 parent 22e78ca commit d44472a
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,27 @@ public String getType() {
public void execute(ClaimUserTaskJobHandlerConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
String taskId = configuration.getTaskId();
String userId = configuration.getUserId();
// eventually we created a claim job, but before it gets executed the usertask is completed
if (execution.getProcessEngineServices().getTaskService().createTaskQuery().taskId(taskId).list().size() > 0) {
// manually authenticate the user so a user operations log is written
execution.getProcessEngineServices().getIdentityService().setAuthenticatedUserId(userId);
execution.getProcessEngineServices().getTaskService().claim(taskId, userId);
execution.getProcessEngineServices().getIdentityService().clearAuthentication();

// manually authenticate the user so a user operations log is written
execution.getProcessEngineServices().getIdentityService().setAuthenticatedUserId(userId);
try {
execution.getProcessEngineServices().getTaskService().claim(taskId, userId);
} finally {
// make sure to reset authentication
execution.getProcessEngineServices().getIdentityService().clearAuthentication();
}

}

@Override
public ClaimUserTaskJobHandlerConfiguration newConfiguration(String canonicalString) {
String[] configParts = canonicalString.split("\\" + TimerEventJobHandler.JOB_HANDLER_CONFIG_PROPERTY_DELIMITER);
if (configParts.length != 2) {
throw new ProcessEngineException("Illegal simulator claim user task job handler configuration: '" + canonicalString
+ "': expecting two part configuration seperated by '" + TimerEventJobHandler.JOB_HANDLER_CONFIG_PROPERTY_DELIMITER + "'.");
}
return new ClaimUserTaskJobHandlerConfiguration(configParts[0], configParts[1]);
String[] configParts = canonicalString.split("\\" + TimerEventJobHandler.JOB_HANDLER_CONFIG_PROPERTY_DELIMITER);
if (configParts.length != 2) {
throw new ProcessEngineException("Illegal simulator claim user task job handler configuration: '" + canonicalString
+ "': expecting two part configuration seperated by '" + TimerEventJobHandler.JOB_HANDLER_CONFIG_PROPERTY_DELIMITER + "'.");
}

return new ClaimUserTaskJobHandlerConfiguration(configParts[0], configParts[1]);
}

@Override
Expand All @@ -55,9 +58,9 @@ public ClaimUserTaskJobHandlerConfiguration(String taskId, String userId) {
this.taskId = taskId;
this.userId = userId;
}

String getUserId() {
return userId;
return userId;
}

String getTaskId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,44 @@
import com.camunda.consulting.simulator.property.ModelPropertyUtil;

public class AbstractTimerJobCreator {
static final Logger LOG = LoggerFactory.getLogger(AbstractTimerJobCreator.class);

public AbstractTimerJobCreator() {
super();
}

protected Optional<Expression> getCachedNextCompleteExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_COMPLETE);
}

protected Optional<Expression> getCachedNextClaimExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_CLAIM);
}

protected Optional<Expression> getCachedClaimUserExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_CLAIM_USER);
}

protected Optional<Expression> getCachedNextFireExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_FIRE);
}

protected void createTimerJob(ExecutionEntity execution, String jobHandlertype, Date duedate,
JobHandlerConfiguration jobHandlerConfiguration) {
TimerEntity timer = new TimerEntity();
ProcessDefinitionEntity processDefinition = execution.getProcessDefinition();

timer.setExecution(execution);
timer.setDuedate(duedate);
timer.setJobHandlerType(jobHandlertype);
timer.setProcessDefinitionKey(processDefinition.getKey());
timer.setDeploymentId(processDefinition.getDeploymentId());
timer.setJobHandlerConfiguration(jobHandlerConfiguration);

Context.getCommandContext().getJobManager().schedule(timer);
}
static final Logger LOG = LoggerFactory.getLogger(AbstractTimerJobCreator.class);

public AbstractTimerJobCreator() {
super();
}

protected Optional<Expression> getCachedNextCompleteExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_COMPLETE);
}

protected Optional<Expression> getCachedNextClaimExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_CLAIM);
}

protected Optional<Expression> getCachedClaimUserExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_CLAIM_USER);
}

protected Optional<Expression> getCachedNextFireExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_FIRE);
}

protected void createTimerJob(ExecutionEntity execution, String jobHandlertype, Date duedate,
JobHandlerConfiguration jobHandlerConfiguration) {
TimerEntity timer = new TimerEntity();
ProcessDefinitionEntity processDefinition = execution.getProcessDefinition();

timer.setExecution(execution);
timer.setDuedate(duedate);
timer.setJobHandlerType(jobHandlertype);
timer.setProcessDefinitionKey(processDefinition.getKey());
timer.setDeploymentId(processDefinition.getDeploymentId());
timer.setJobHandlerConfiguration(jobHandlerConfiguration);

Context.getCommandContext().getJobManager().schedule(timer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public void notify(DelegateTask task) {

// backwards compatibility (user task next fire)
if (!nextCompleteExpression.isPresent()) {
nextCompleteExpression = getCachedNextFireExpression(task.getExecution(), task.getTaskDefinitionKey());
nextCompleteExpression = getCachedNextFireExpression(task.getExecution(), task.getTaskDefinitionKey());
}

if (nextCompleteExpression.isPresent()) {
Date dueDate = (Date) nextCompleteExpression.get().getValue(task.getExecution());
createJobForUserTaskCompletion(task, dueDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,134 +17,122 @@

public class ModelPropertyUtil {

public static final String CAMUNDA_PROPERTY_SIM_NEXT_FIRE = "simNextFire";
public static final String CAMUNDA_PROPERTY_SIM_NEXT_COMPLETE = "simNextComplete";
public static final String CAMUNDA_PROPERTY_SIM_NEXT_CLAIM = "simNextClaim";
public static final String CAMUNDA_PROPERTY_SIM_CLAIM_USER = "simClaimUser";
public static final String CAMUNDA_PROPERTY_SIM_GENERATE_PAYLOAD = "simGeneratePayload";
public static final String CAMUNDA_PROPERTY_SIM_INIT_PAYLOAD = "simInitPayload";
public static final String CAMUNDA_PROPERTY_SIM_INIT_BUSINESS_KEY = "simInitBusinessKey";
public static final String CAMUNDA_PROPERTY_SIM_CALL_REAL_IMPLEMENTATION = "simCallRealImplementation";
public static final String CAMUNDA_PROPERTY_SIM_KEEP_LISTENERS = "simKeepListeners";
public static final String[] TRUE = { "true", "True", "yes", "Yes" };

public static Map<BaseElement, Map<String, Work[]>> workByElementAndPropertyCache = new HashMap<>();

public static boolean isTrue(Optional<String> propertyValue) {
return propertyValue.isPresent() && isTrue(propertyValue.get());
public static final String CAMUNDA_PROPERTY_SIM_NEXT_FIRE = "simNextFire";
public static final String CAMUNDA_PROPERTY_SIM_NEXT_COMPLETE = "simNextComplete";
public static final String CAMUNDA_PROPERTY_SIM_NEXT_CLAIM = "simNextClaim";
public static final String CAMUNDA_PROPERTY_SIM_CLAIM_USER = "simClaimUser";
public static final String CAMUNDA_PROPERTY_SIM_GENERATE_PAYLOAD = "simGeneratePayload";
public static final String CAMUNDA_PROPERTY_SIM_INIT_PAYLOAD = "simInitPayload";
public static final String CAMUNDA_PROPERTY_SIM_INIT_BUSINESS_KEY = "simInitBusinessKey";
public static final String CAMUNDA_PROPERTY_SIM_CALL_REAL_IMPLEMENTATION = "simCallRealImplementation";
public static final String CAMUNDA_PROPERTY_SIM_KEEP_LISTENERS = "simKeepListeners";
public static final String[] TRUE = {"true", "True", "yes", "Yes"};

public static Map<BaseElement, Map<String, Work[]>> workByElementAndPropertyCache = new HashMap<>();

public static boolean isTrue(Optional<String> propertyValue) {
return propertyValue.isPresent() && isTrue(propertyValue.get());
}

public static boolean isTrue(String propertyValue) {
return Arrays.asList(TRUE).contains(propertyValue);
}

public static Optional<String> getNextFire(ModelElementInstance elementInstance) {
return readCamundaProperty((BaseElement) elementInstance, CAMUNDA_PROPERTY_SIM_NEXT_FIRE);
}

public static Optional<String> getNextFire(Element xmlElement) {
return readCamundaProperty(xmlElement, CAMUNDA_PROPERTY_SIM_NEXT_FIRE);
}

public static Optional<String> readCamundaProperty(Element xmlElement, String propertyName) {
Element extentionsElement = xmlElement.element("extensionElements");
if (extentionsElement == null) {
return Optional.empty();
}

public static boolean isTrue(String propertyValue) {
return Arrays.asList(TRUE).contains(propertyValue);
}

public static Optional<String> getNextFire(ModelElementInstance elementInstance) {
return readCamundaProperty((BaseElement) elementInstance, CAMUNDA_PROPERTY_SIM_NEXT_FIRE);
Element camundaProperties = extentionsElement.elementNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, "properties");
if (camundaProperties == null) {
return Optional.empty();
}

public static Optional<String> getNextFire(Element xmlElement) {
return readCamundaProperty(xmlElement, CAMUNDA_PROPERTY_SIM_NEXT_FIRE);
List<Element> propertys = camundaProperties.elements("property");
for (Element property : propertys) {
if (propertyName.equals(property.attribute("name"))) {
return Optional.of(property.attribute("value"));
}
}
return Optional.empty();
}

public static Optional<String> getNextComplete(ModelElementInstance elementInstance) {
return readCamundaProperty((BaseElement) elementInstance, CAMUNDA_PROPERTY_SIM_NEXT_COMPLETE);
public static Optional<String> readCamundaProperty(BaseElement modelElementInstance, String propertyName) {
if (modelElementInstance.getExtensionElements() == null) {
return Optional.empty();
}
return queryCamundaPropertyValues(modelElementInstance, propertyName).findFirst();
}

public static Optional<String> getNextClaim(ModelElementInstance elementInstance) {
return readCamundaProperty((BaseElement) elementInstance, CAMUNDA_PROPERTY_SIM_NEXT_CLAIM);
public static Collection<String> readCamundaPropertyMulti(BaseElement modelElementInstance, String propertyName) {
if (modelElementInstance.getExtensionElements() == null) {
return Collections.emptyList();
}

public static Optional<String> getClaimUser(ModelElementInstance elementInstance) {
return readCamundaProperty((BaseElement) elementInstance, CAMUNDA_PROPERTY_SIM_CLAIM_USER);
return queryCamundaPropertyValues(modelElementInstance, propertyName).collect(Collectors.toList());
}

protected static Stream<String> queryCamundaPropertyValues(BaseElement modelElementInstance, String propertyName) {
return modelElementInstance.getExtensionElements().getElementsQuery().filterByType(CamundaProperties.class)
.list().stream() //
.map(CamundaProperties::getCamundaProperties) //
.flatMap(Collection::stream) //
.filter(property -> property.getCamundaName().equals(propertyName)) //
.map(CamundaProperty::getCamundaValue) //
.filter(Objects::nonNull) //
;
}

/*
* Cached read of "simulateSetVariable"-extensions for the given element.
*/
public static Work[] getPayloadValuesOrdered(BaseElement element, String camundaPropertyName) {
Work[] values = null;
Map<String, Work[]> byProperty = workByElementAndPropertyCache.get(element);
if (byProperty == null) {
byProperty = new HashMap<>();
workByElementAndPropertyCache.put(element, byProperty);
}

public static Optional<String> readCamundaProperty(Element xmlElement, String propertyName) {
Element extentionsElement = xmlElement.element("extensionElements");
if (extentionsElement == null) {
return Optional.empty();
}
Element camundaProperties = extentionsElement.elementNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, "properties");
if (camundaProperties == null) {
return Optional.empty();
}

List<Element> propertys = camundaProperties.elements("property");
for (Element property : propertys) {
if (propertyName.equals(property.attribute("name"))) {
return Optional.of(property.attribute("value"));
}
}
return Optional.empty();
}

public static Optional<String> readCamundaProperty(BaseElement modelElementInstance, String propertyName) {
if (modelElementInstance.getExtensionElements() == null) {
return Optional.empty();
}
return queryCamundaPropertyValues(modelElementInstance, propertyName).findFirst();
}

public static Collection<String> readCamundaPropertyMulti(BaseElement modelElementInstance, String propertyName) {
if (modelElementInstance.getExtensionElements() == null) {
return Collections.emptyList();
}
return queryCamundaPropertyValues(modelElementInstance, propertyName).collect(Collectors.toList());
}

protected static Stream<String> queryCamundaPropertyValues(BaseElement modelElementInstance, String propertyName) {
return modelElementInstance.getExtensionElements().getElementsQuery().filterByType(CamundaProperties.class)
.list().stream() //
.map(CamundaProperties::getCamundaProperties) //
.flatMap(Collection::stream) //
.filter(property -> property.getCamundaName().equals(propertyName)) //
.map(CamundaProperty::getCamundaValue) //
.filter(Objects::nonNull) //
;
}

/*
* Cached read of "simulateSetVariable"-extensions for the given element.
*/
public static Work[] getPayloadValuesOrdered(BaseElement element, String camundaPropertyName) {
Work[] values = null;
Map<String, Work[]> byProperty = workByElementAndPropertyCache.get(element);
if (byProperty == null) {
byProperty = new HashMap<>();
workByElementAndPropertyCache.put(element, byProperty);
}
values = byProperty.get(camundaPropertyName);
if (values == null) {
String[] expressions = readCamundaPropertyMulti(element, camundaPropertyName).toArray(new String[] {});
values = new Work[expressions.length];

DirectedAcyclicGraph<Work, Object> graph = new DirectedAcyclicGraph<>(Object.class);
for (int i = 0; i < expressions.length; i++) {
values[i] = new Work(expressions[i]);
graph.addVertex(values[i]);
}
for (Work currentWork : values) {
for (Work otherWork : values) {
if (currentWork.getValueExpression().getExpressionText().matches(
".*\\W" + Pattern.quote(otherWork.getVariableExpression().getExpressionText()) + "\\W.*")) {
try {
graph.addEdge(otherWork, currentWork);
} catch (IllegalArgumentException e) {
PayloadGeneratorListener.LOG.warn(
"Possible cycle in simulateSetVariable-dependencies detected when checking '{}'",
currentWork.getValueExpression());
}
}
}
}

int i = 0;
for (Iterator<Work> iterator = graph.iterator(); iterator.hasNext();) {
Work next = iterator.next();
values[i++] = next;
}
byProperty.put(camundaPropertyName, values);
}
return values;
values = byProperty.get(camundaPropertyName);
if (values == null) {
String[] expressions = readCamundaPropertyMulti(element, camundaPropertyName).toArray(new String[]{});
values = new Work[expressions.length];

DirectedAcyclicGraph<Work, Object> graph = new DirectedAcyclicGraph<>(Object.class);
for (int i = 0; i < expressions.length; i++) {
values[i] = new Work(expressions[i]);
graph.addVertex(values[i]);
}
for (Work currentWork : values) {
for (Work otherWork : values) {
if (currentWork.getValueExpression().getExpressionText().matches(
".*\\W" + Pattern.quote(otherWork.getVariableExpression().getExpressionText()) + "\\W.*")) {
try {
graph.addEdge(otherWork, currentWork);
} catch (IllegalArgumentException e) {
PayloadGeneratorListener.LOG.warn(
"Possible cycle in simulateSetVariable-dependencies detected when checking '{}'",
currentWork.getValueExpression());
}
}
}
}

int i = 0;
for (Iterator<Work> iterator = graph.iterator(); iterator.hasNext(); ) {
Work next = iterator.next();
values[i++] = next;
}
byProperty.put(camundaPropertyName, values);
}
return values;
}

}

0 comments on commit d44472a

Please sign in to comment.