Search in sources :

Example 6 with EncryptedMessage

use of com.tremolosecurity.provisioning.util.EncryptedMessage in project OpenUnison by TremoloSecurity.

the class SetRandomPassword method doTask.

public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
    String password = new BigInteger(130, random).toString(32);
    try {
        // remove {myvd}
        password = PBKDF2.generateHash(password).substring(7);
    } catch (InvalidKeyException | NoSuchAlgorithmException | UnsupportedEncodingException e) {
        throw new ProvisioningException("Could not generate password", e);
    }
    SecretKey key = this.cfgMgr.getSecretKey(this.encryptionKey);
    if (key == null) {
        throw new ProvisioningException("Encryption key not found");
    }
    EncryptedMessage msg = new EncryptedMessage();
    try {
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        msg.setMsg(cipher.doFinal(password.getBytes("UTF-8")));
        msg.setIv(cipher.getIV());
        Gson gson = new Gson();
        String json = gson.toJson(msg);
        user.setPassword(password);
        user.getAttribs().put(this.attributeName, new Attribute(this.attributeName, json));
    } catch (Throwable t) {
        throw new ProvisioningException("Could not generate random password", t);
    }
    return true;
}
Also used : Attribute(com.tremolosecurity.saml.Attribute) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Gson(com.google.gson.Gson) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) SecretKey(javax.crypto.SecretKey) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) EncryptedMessage(com.tremolosecurity.provisioning.util.EncryptedMessage) BigInteger(java.math.BigInteger) Cipher(javax.crypto.Cipher)

Example 7 with EncryptedMessage

use of com.tremolosecurity.provisioning.util.EncryptedMessage in project OpenUnison by TremoloSecurity.

the class AutoFail method execute.

@Override
public void execute(ConfigManager configManager, JobExecutionContext context) throws ProvisioningException {
    if (configManager == null || configManager.getProvisioningEngine() == null) {
        logger.warn("System not fully initialized");
        return;
    }
    String queueName = context.getJobDetail().getJobDataMap().getString("queueName");
    String approver = context.getJobDetail().getJobDataMap().getString("approver");
    String msg = context.getJobDetail().getJobDataMap().getString("message");
    ApprovalSummaries summaries = ServiceActions.listOpenApprovals(approver, "", configManager);
    try {
        this.createConnections(configManager, queueName);
        Gson gson = new Gson();
        for (ApprovalSummary sum : summaries.getApprovals()) {
            FailApproval fa = new FailApproval();
            fa.setApprovalID(sum.getApproval());
            fa.setApprover(approver);
            fa.setMsg(msg);
            EncryptedMessage em = configManager.getProvisioningEngine().encryptObject(fa);
            synchronized (sessionHolder) {
                TextMessage tmsg = sessionHolder.getSession().createTextMessage(gson.toJson(em));
                tmsg.setStringProperty("JMSXGroupID", "unison-autofail");
                sessionHolder.getMessageProduceer().send(tmsg);
            }
        }
    } catch (Throwable t) {
        throw new ProvisioningException("Could not process open approvals", t);
    }
}
Also used : ApprovalSummaries(com.tremolosecurity.provisioning.service.util.ApprovalSummaries) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) EncryptedMessage(com.tremolosecurity.provisioning.util.EncryptedMessage) Gson(com.google.gson.Gson) FailApproval(com.tremolosecurity.provisioning.scheduler.jobs.util.FailApproval) ApprovalSummary(com.tremolosecurity.provisioning.service.util.ApprovalSummary)

Example 8 with EncryptedMessage

use of com.tremolosecurity.provisioning.util.EncryptedMessage in project OpenUnison by TremoloSecurity.

the class UpdateApprovalAz method execute.

@Override
public void execute(ConfigManager configManager, JobExecutionContext context) throws ProvisioningException {
    String queueName = context.getJobDetail().getJobDataMap().getString("queueName");
    if (configManager == null || configManager.getProvisioningEngine() == null) {
        return;
    }
    org.hibernate.Session hsession = configManager.getProvisioningEngine().getHibernateSessionFactory().openSession();
    try {
        this.createConnections(configManager, queueName);
        HashMap<Integer, String> approvals = new HashMap<Integer, String>();
        // PreparedStatement findOpenApprovals = con.prepareStatement("SELECT id,workflowObj FROM approvals WHERE approved IS NULL");
        Query query = hsession.createQuery("FROM Approvals WHERE approved IS NULL");
        List<com.tremolosecurity.provisioning.objects.Approvals> approvalObjs = query.list();
        for (Approvals aprv : approvalObjs) {
            approvals.put(aprv.getId(), aprv.getWorkflowObj());
        }
        Gson gson = new Gson();
        for (int approvalID : approvals.keySet()) {
            HashMap<Integer, String> wf = new HashMap<Integer, String>();
            wf.put(approvalID, approvals.get(approvalID));
            EncryptedMessage em = configManager.getProvisioningEngine().encryptObject(wf);
            synchronized (session) {
                TextMessage tmsg = session.getSession().createTextMessage(gson.toJson(em));
                tmsg.setStringProperty("JMSXGroupID", "unison-updateaz");
                session.getMessageProduceer().send(tmsg);
            }
        }
    } catch (Throwable t) {
        throw new ProvisioningException("Could not process open approvals", t);
    } finally {
        if (hsession != null) {
            hsession.close();
        }
    }
}
Also used : Query(org.hibernate.Query) HashMap(java.util.HashMap) Approvals(com.tremolosecurity.provisioning.objects.Approvals) Gson(com.google.gson.Gson) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) EncryptedMessage(com.tremolosecurity.provisioning.util.EncryptedMessage)

Example 9 with EncryptedMessage

use of com.tremolosecurity.provisioning.util.EncryptedMessage 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 10 with EncryptedMessage

use of com.tremolosecurity.provisioning.util.EncryptedMessage 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)

Aggregations

EncryptedMessage (com.tremolosecurity.provisioning.util.EncryptedMessage)12 Cipher (javax.crypto.Cipher)7 SecretKey (javax.crypto.SecretKey)7 Gson (com.google.gson.Gson)6 IOException (java.io.IOException)6 Attribute (com.tremolosecurity.saml.Attribute)5 InvalidKeyException (java.security.InvalidKeyException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 BadPaddingException (javax.crypto.BadPaddingException)4 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)4 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)4 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 HashMap (java.util.HashMap)3 IvParameterSpec (javax.crypto.spec.IvParameterSpec)3 TextMessage (javax.jms.TextMessage)3 SecurityKeyData (com.google.u2f.server.data.SecurityKeyData)2 TaskHolder (com.tremolosecurity.provisioning.util.TaskHolder)2 KeyHolder (com.tremolosecurity.unison.google.u2f.KeyHolder)2