Search in sources :

Example 1 with Workflows

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();
        }
    }
}
Also used : Query(org.hibernate.Query) Workflows(com.tremolosecurity.provisioning.objects.Workflows) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) ArrayList(java.util.ArrayList) Approvals(com.tremolosecurity.provisioning.objects.Approvals) Gson(com.google.gson.Gson) ServletException(javax.servlet.ServletException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) SQLException(java.sql.SQLException) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) Session(org.hibernate.Session)

Example 2 with Workflows

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;
}
Also used : WorkflowParameters(com.tremolosecurity.provisioning.objects.WorkflowParameters) ST(org.stringtemplate.v4.ST) Workflows(com.tremolosecurity.provisioning.objects.Workflows) SQLException(java.sql.SQLException) TaskHolder(com.tremolosecurity.provisioning.util.TaskHolder) Users(com.tremolosecurity.provisioning.objects.Users) LDAPException(com.novell.ldap.LDAPException) Session(org.hibernate.Session)

Example 3 with Workflows

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;
}
Also used : DynamicWorkflows(com.tremolosecurity.provisioning.workflows.DynamicWorkflows) Workflows(com.tremolosecurity.provisioning.objects.Workflows) Connection(java.sql.Connection) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime)

Example 4 with Workflows

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;
    }
}
Also used : Query(org.hibernate.Query) Workflows(com.tremolosecurity.provisioning.objects.Workflows) Session(org.hibernate.Session)

Example 5 with Workflows

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();
        }
    }
}
Also used : Workflows(com.tremolosecurity.provisioning.objects.Workflows) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) Session(org.hibernate.Session)

Aggregations

Workflows (com.tremolosecurity.provisioning.objects.Workflows)5 Session (org.hibernate.Session)4 SQLException (java.sql.SQLException)2 Timestamp (java.sql.Timestamp)2 Query (org.hibernate.Query)2 DateTime (org.joda.time.DateTime)2 Gson (com.google.gson.Gson)1 LDAPException (com.novell.ldap.LDAPException)1 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 Approvals (com.tremolosecurity.provisioning.objects.Approvals)1 Users (com.tremolosecurity.provisioning.objects.Users)1 WorkflowParameters (com.tremolosecurity.provisioning.objects.WorkflowParameters)1 ProvisioningError (com.tremolosecurity.provisioning.service.util.ProvisioningError)1 ProvisioningResult (com.tremolosecurity.provisioning.service.util.ProvisioningResult)1 TaskHolder (com.tremolosecurity.provisioning.util.TaskHolder)1 DynamicWorkflows (com.tremolosecurity.provisioning.workflows.DynamicWorkflows)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 ServletException (javax.servlet.ServletException)1