use of com.tremolosecurity.provisioning.objects.Workflows in project OpenUnison by TremoloSecurity.
the class ExecutedWorkflows method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userKey = req.getParameter("user");
Session session = null;
try {
session = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getHibernateSessionFactory().openSession();
// PreparedStatement ps = con.prepareStatement("select workflows.id,workflows.name from workflows inner join users on users.id=workflows.userid where workflows.completeTS IS NOT NULL AND userKey=?");
Query query = session.createQuery("FROM Workflows WHERE Workflows.completeTS IS NOT NULL AND Workflows.users.userKey = :user_key");
query.setParameter("user_key", userKey);
List<com.tremolosecurity.provisioning.objects.Workflows> workflows = query.list();
ArrayList<String> workflowids = new ArrayList<String>();
for (Workflows wf : workflows) {
if (wf.getApprovals().isEmpty()) {
workflowids.add(wf.getName());
} else {
boolean approved = true;
for (Approvals approval : wf.getApprovals()) {
approved = approved && (approval.getApproved() == 1 && approval.getApprovedTs() != null);
}
}
}
Gson gson = new Gson();
ProvisioningResult resObj = new ProvisioningResult();
resObj.setSuccess(true);
resObj.setWorkflowIds(workflowids);
resp.getOutputStream().println(gson.toJson(resObj));
} catch (Exception e) {
ProvisioningError pe = new ProvisioningError();
pe.setError("Could not load executed workflows : " + e.getMessage());
ProvisioningResult res = new ProvisioningResult();
res.setSuccess(false);
res.setError(pe);
Gson gson = new Gson();
resp.getWriter().write(gson.toJson(res));
} finally {
if (session != null) {
session.close();
}
}
}
use of com.tremolosecurity.provisioning.objects.Workflows 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.objects.Workflows in project OpenUnison by TremoloSecurity.
the class SendMessageThread method getWorkFlow.
/* (non-Javadoc)
* @see com.tremolosecurity.provisioning.core.ProvisioningEngine#getWorkFlow(java.lang.String)
*/
@Override
public Workflow getWorkFlow(String name) throws ProvisioningException {
WorkflowImpl wf = (WorkflowImpl) getWorkflowCopy(name);
if (this.sessionFactory != null) {
Connection con = null;
org.hibernate.Session session = sessionFactory.openSession();
try {
session.beginTransaction();
DateTime now = new DateTime();
Workflows workflow = new Workflows();
workflow.setName(wf.getName());
workflow.setStartTs(new Timestamp(now.getMillis()));
session.save(workflow);
wf.setId(workflow.getId());
wf.setFromDB(workflow);
session.getTransaction().commit();
} finally {
if (session != null) {
session.close();
}
}
}
return wf;
}
use of com.tremolosecurity.provisioning.objects.Workflows in project OpenUnison by TremoloSecurity.
the class ExecuteWorkflow method executeApprovals.
private boolean executeApprovals(WFCall wfcall, Workflow wf, ProvisioningEngine prov, String approvalReason, String approver) throws SQLException, ProvisioningException {
Session session = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getHibernateSessionFactory().openSession();
if (session != null) {
Workflows workflow = wf.getFromDB(session);
int approvalID = -1;
Query query = session.createQuery("FROM Approvals WHERE workflow = :wfid");
query.setParameter("wfid", workflow);
List<com.tremolosecurity.provisioning.objects.Approvals> approvals = query.list();
for (com.tremolosecurity.provisioning.objects.Approvals approval : approvals) {
if (approval.getWorkflowObj() != null) {
approvalID = approval.getId();
}
}
session.close();
if (approvalID == -1) {
return false;
} else {
prov.doApproval(approvalID, approver, true, approvalReason);
return true;
}
} else {
return false;
}
}
use of com.tremolosecurity.provisioning.objects.Workflows in project OpenUnison by TremoloSecurity.
the class WorkflowImpl method completeWorkflow.
/* (non-Javadoc)
* @see com.tremolosecurity.provisioning.core.Workflow#completeWorkflow()
*/
@Override
public void completeWorkflow() throws ProvisioningException {
Session session = null;
try {
if (this.cfgMgr.getProvisioningEngine().getHibernateSessionFactory() != null) {
session = this.cfgMgr.getProvisioningEngine().getHibernateSessionFactory().openSession();
session.beginTransaction();
DateTime now = new DateTime();
Workflows wf = session.load(Workflows.class, this.id);
wf.setCompleteTs(new Timestamp(now.getMillis()));
session.save(wf);
session.getTransaction().commit();
}
} finally {
if (session != null) {
if (session.getTransaction() != null && session.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
session.getTransaction().rollback();
}
session.close();
}
}
}
Aggregations