use of com.tremolosecurity.provisioning.util.TaskHolder in project OpenUnison by TremoloSecurity.
the class WorkflowImpl method executeWorkflow.
/* (non-Javadoc)
* @see com.tremolosecurity.provisioning.core.Workflow#executeWorkflow(com.tremolosecurity.provisioning.core.User, java.util.Map)
*/
@Override
public Map<String, Object> executeWorkflow(User user, Map<String, Object> params, String requesterUID) throws ProvisioningException {
request = new HashMap<String, Object>();
if (params != null) {
request.putAll(params);
// request = (HashMap<String, Object>) params;
}
this.user = user;
Session session = null;
try {
if (this.cfgMgr.getProvisioningEngine().getHibernateSessionFactory() != null) {
session = this.cfgMgr.getProvisioningEngine().getHibernateSessionFactory().openSession();
this.userNum = getUserNum(user, session, this.cfgMgr);
if (requesterUID == null) {
this.requester = this.user;
this.requesterNum = this.userNum;
} else {
this.requester = getRequester(requesterUID, session, cfgMgr);
this.requesterNum = getUserNum(requester, session, this.cfgMgr);
}
Workflows workflow = session.load(Workflows.class, this.getId());
workflow.setUsers(session.load(Users.class, this.userNum));
workflow.setRequester(session.load(Users.class, this.requesterNum));
workflow.setRequestReason(user.getRequestReason());
ST st = new ST(this.description, '$', '$');
for (String key : request.keySet()) {
st.add(key.replaceAll("[.]", "_"), request.get(key));
}
workflow.setDescription(st.render());
if (this.label != null) {
st = new ST(this.label, '$', '$');
for (String key : request.keySet()) {
st.add(key.replaceAll("[.]", "_"), request.get(key));
}
workflow.setLabel(st.render());
} else {
workflow.setLabel("");
}
session.beginTransaction();
session.save(workflow);
for (String paramName : params.keySet()) {
WorkflowParameters param = new WorkflowParameters();
param.setName(paramName);
Object o = params.get(paramName);
if (o != null) {
param.setValue(o.toString());
} else {
param.setValue("");
}
param.setWorkflows(workflow);
session.save(param);
}
session.getTransaction().commit();
}
} catch (SQLException e) {
throw new ProvisioningException("Could not set workflow user key", e);
} catch (LDAPException e) {
throw new ProvisioningException("Could not set workflow user key", e);
} finally {
if (session != null) {
if (session.getTransaction() != null && session.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
session.getTransaction().rollback();
}
session.close();
}
}
if (request.get(ProvisioningParams.UNISON_EXEC_TYPE) != null && request.get(ProvisioningParams.UNISON_EXEC_TYPE).equals(ProvisioningParams.UNISON_EXEC_SYNC)) {
Iterator<WorkflowTask> it = this.tasks.iterator();
while (it.hasNext()) {
boolean doContinue = it.next().doTask(user, request);
if (!doContinue) {
return request;
}
}
this.completeWorkflow();
} else {
WorkflowHolder wfHolder = new WorkflowHolder(this, user, request);
TaskHolder root = new TaskHolder();
root.setParent(this.tasks);
root.setPosition(0);
wfHolder.getWfStack().push(root);
((ProvisioningEngineImpl) this.cfgMgr.getProvisioningEngine()).enqueue(wfHolder);
}
return request;
}
use of com.tremolosecurity.provisioning.util.TaskHolder in project OpenUnison by TremoloSecurity.
the class SendMessageThread method enqueue.
public void enqueue(WorkflowHolder wfHolder) throws ProvisioningException {
TextMessage bm;
try {
JMSSessionHolder session;
String originalQueue;
session = this.getTaskMessageProducer();
bm = session.getSession().createTextMessage();
originalQueue = session.getQueueName();
synchronized (session) {
bm.setStringProperty("OriginalQueue", originalQueue);
bm.setStringProperty("WorkflowName", wfHolder.getWorkflow().getName());
bm.setStringProperty("WorkflowSubject", wfHolder.getUser().getUserID());
bm.setStringProperty("JMSXGroupID", "unison");
bm.setStringProperty("nonce", UUID.randomUUID().toString());
TaskHolder holder = wfHolder.getWfStack().peek();
WorkflowTask task = holder.getParent().get(holder.getPosition());
bm.setStringProperty("WorkflowCurrentTask", task.getLabel());
EncryptedMessage encMsg = this.encryptObject(wfHolder);
String json = JsonWriter.objectToJson(encMsg);
bm.setText(json);
session.getMessageProduceer().send(bm);
}
} catch (Exception e) {
throw new ProvisioningException("Could not enqueue message", e);
}
}
use of com.tremolosecurity.provisioning.util.TaskHolder in project OpenUnison by TremoloSecurity.
the class TaskConsumer method onMessage.
@Override
public void onMessage(Message msg) {
try {
TextMessage bmsg = (TextMessage) msg;
if (bmsg.getBooleanProperty("unisonignore")) {
if (logger.isDebugEnabled()) {
logger.debug("ignoring message");
}
bmsg.acknowledge();
return;
}
EncryptedMessage encMsg = (EncryptedMessage) JsonReader.jsonToJava(bmsg.getText());
WorkflowHolder wfHolder = (WorkflowHolder) this.prov.decryptObject(encMsg);
// Re-initialize the workflow
wfHolder.getWorkflow().reInit(cfgMgr);
TaskHolder th = wfHolder.getWfStack().peek();
WorkflowTask task = th.getParent().get(th.getPosition());
th.setPosition(th.getPosition() + 1);
User user = th.getCurrentUser();
if (user == null) {
user = wfHolder.getUser();
}
if (task.doTask(user, wfHolder.getRequest())) {
if (isDone(wfHolder, null)) {
wfHolder.getWorkflow().completeWorkflow();
} else {
((ProvisioningEngineImpl) this.prov).enqueue(wfHolder);
}
} else {
if (isDone(wfHolder, task)) {
wfHolder.getWorkflow().completeWorkflow();
} else {
// do nothing
}
}
msg.acknowledge();
} catch (Throwable t) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter baout = new PrintWriter(baos);
t.printStackTrace(baout);
baout.flush();
baout.close();
StringBuffer b = new StringBuffer();
b.append("Could not execute task\n").append(new String(baos.toByteArray()));
throw new RuntimeException(b.toString(), t);
}
}
use of com.tremolosecurity.provisioning.util.TaskHolder in project OpenUnison by TremoloSecurity.
the class WorkflowTaskImpl method runSubTasks.
protected final boolean runSubTasks(ArrayList<WorkflowTask> subs, User user, Map<String, Object> request) throws ProvisioningException {
if (request.get(ProvisioningParams.UNISON_EXEC_TYPE) != null && request.get(ProvisioningParams.UNISON_EXEC_TYPE).equals(ProvisioningParams.UNISON_EXEC_SYNC)) {
for (WorkflowTask wft : subs) {
boolean doContinue = wft.doTask(user, request);
if (!doContinue) {
return false;
}
}
return true;
} else {
if (subs.isEmpty()) {
return true;
} else {
WorkflowHolder holder = (WorkflowHolder) request.get(WorkflowHolder.WF_HOLDER_REQUEST);
TaskHolder th = new TaskHolder();
th.setPosition(0);
th.setParent(subs);
th.setCurrentUser(user);
holder.getWfStack().push(th);
((ProvisioningEngineImpl) this.cfgMgr.getProvisioningEngine()).enqueue(holder);
return false;
}
}
}
Aggregations