Search in sources :

Example 1 with TaskHolder

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;
}
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 2 with TaskHolder

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);
    }
}
Also used : TaskHolder(com.tremolosecurity.provisioning.util.TaskHolder) JMSSessionHolder(com.tremolosecurity.provisioning.jms.JMSSessionHolder) EncryptedMessage(com.tremolosecurity.provisioning.util.EncryptedMessage) TextMessage(javax.jms.TextMessage) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) LDAPException(com.novell.ldap.LDAPException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SocketException(java.net.SocketException) SQLException(java.sql.SQLException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) MessagingException(javax.mail.MessagingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) JMSException(javax.jms.JMSException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) BadPaddingException(javax.crypto.BadPaddingException)

Example 3 with TaskHolder

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);
    }
}
Also used : TaskHolder(com.tremolosecurity.provisioning.util.TaskHolder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EncryptedMessage(com.tremolosecurity.provisioning.util.EncryptedMessage) TextMessage(javax.jms.TextMessage) PrintWriter(java.io.PrintWriter)

Example 4 with TaskHolder

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;
        }
    }
}
Also used : TaskHolder(com.tremolosecurity.provisioning.util.TaskHolder)

Aggregations

TaskHolder (com.tremolosecurity.provisioning.util.TaskHolder)4 LDAPException (com.novell.ldap.LDAPException)2 EncryptedMessage (com.tremolosecurity.provisioning.util.EncryptedMessage)2 SQLException (java.sql.SQLException)2 TextMessage (javax.jms.TextMessage)2 JMSSessionHolder (com.tremolosecurity.provisioning.jms.JMSSessionHolder)1 Users (com.tremolosecurity.provisioning.objects.Users)1 WorkflowParameters (com.tremolosecurity.provisioning.objects.WorkflowParameters)1 Workflows (com.tremolosecurity.provisioning.objects.Workflows)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SocketException (java.net.SocketException)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 BadPaddingException (javax.crypto.BadPaddingException)1