Search in sources :

Example 1 with AllowedApprovers

use of com.tremolosecurity.provisioning.objects.AllowedApprovers in project OpenUnison by TremoloSecurity.

the class AzUtils method loadDNApprovers.

public static boolean loadDNApprovers(Approvals approval, String emailTemplate, ConfigManager cfg, Session session, int id2, String constraint, boolean sendNotification) throws ProvisioningException {
    ArrayList<String> attrs = new ArrayList<String>();
    attrs.add(cfg.getProvisioningEngine().getUserIDAttribute());
    LDAPSearchResults res = null;
    LDAPEntry entry = null;
    boolean found = false;
    try {
        res = cfg.getMyVD().search(constraint, 2, equal("objectClass", cfg.getCfg().getUserObjectClass()).toString(), attrs);
        while (res.hasMore()) {
            entry = res.next();
            Approvers approver = getApproverByDN(approval, emailTemplate, cfg, session, entry.getDN(), sendNotification);
            if (approver == null) {
                continue;
            }
            found = true;
            AllowedApprovers allowedApprover = new AllowedApprovers();
            allowedApprover.setApprovals(approval);
            allowedApprover.setApprovers(approver);
            session.save(allowedApprover);
        }
    } catch (Exception e) {
        throw new ProvisioningException("Could not find approvers", e);
    }
    return found;
}
Also used : LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) AllowedApprovers(com.tremolosecurity.provisioning.objects.AllowedApprovers) Approvers(com.tremolosecurity.provisioning.objects.Approvers) AllowedApprovers(com.tremolosecurity.provisioning.objects.AllowedApprovers) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ArrayList(java.util.ArrayList) LDAPException(com.novell.ldap.LDAPException) SQLException(java.sql.SQLException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPReferralException(com.novell.ldap.LDAPReferralException)

Example 2 with AllowedApprovers

use of com.tremolosecurity.provisioning.objects.AllowedApprovers in project OpenUnison by TremoloSecurity.

the class UpdateApprovalAZListener method updateAllowedApprovals.

private void updateAllowedApprovals(ConfigManager cfg, int approvalID, String workflowObj) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, IOException, ClassNotFoundException, ProvisioningException, SQLException, InvalidAlgorithmParameterException {
    SecretKey decryptionKey = cfg.getSecretKey(cfg.getCfg().getProvisioning().getApprovalDB().getEncryptionKey());
    Gson gson = new Gson();
    Token token = gson.fromJson(workflowObj, Token.class);
    byte[] iv = org.bouncycastle.util.encoders.Base64.decode(token.getIv());
    IvParameterSpec spec = new IvParameterSpec(iv);
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    cipher.init(Cipher.DECRYPT_MODE, decryptionKey, spec);
    byte[] encBytes = org.bouncycastle.util.encoders.Base64.decode(token.getEncryptedRequest());
    String json = new String(cipher.doFinal(encBytes));
    Workflow wf = (Workflow) JsonReader.jsonToJava(json);
    Approval approval = (Approval) wf.findCurrentApprovalTask();
    if (approval == null) {
        throw new ProvisioningException("Could not locate approval step");
    }
    Set<Integer> currentApprovers = new HashSet<Integer>();
    Session session = cfg.getProvisioningEngine().getHibernateSessionFactory().openSession();
    try {
        Approvals approvalObj = session.load(Approvals.class, approval.getId());
        for (AllowedApprovers approver : approvalObj.getAllowedApproverses()) {
            currentApprovers.add(approver.getApprovers().getId());
        }
        session.beginTransaction();
        for (AllowedApprovers approver : approvalObj.getAllowedApproverses()) {
            session.delete(approver);
        }
        approvalObj.getAllowedApproverses().clear();
        approval.updateAllowedApprovals(session, cfg, wf.getRequest());
        // need to write the approval back to the db
        json = JsonWriter.objectToJson(wf);
        cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, decryptionKey);
        byte[] encJson = cipher.doFinal(json.getBytes("UTF-8"));
        String base64d = new String(org.bouncycastle.util.encoders.Base64.encode(encJson));
        token = new Token();
        token.setEncryptedRequest(base64d);
        token.setIv(new String(org.bouncycastle.util.encoders.Base64.encode(cipher.getIV())));
        // String base64 = new String(org.bouncycastle.util.encoders.Base64.encode(baos.toByteArray()));
        approvalObj.setWorkflowObj(gson.toJson(token));
        session.save(approvalObj);
        session.getTransaction().commit();
        approvalObj = session.load(Approvals.class, approvalObj.getId());
        for (AllowedApprovers approver : approvalObj.getAllowedApproverses()) {
            if (!currentApprovers.contains(approver.getApprovers().getId())) {
                this.sendNotification(approval.getEmailTemplate(), cfg, session, approver.getApprovers().getUserKey());
            }
        }
    } catch (Throwable t) {
        try {
            if (session != null) {
                session.getTransaction().rollback();
            }
        } catch (Throwable tx) {
        }
        ;
        throw t;
    } finally {
        if (session != null) {
            session.close();
        }
    }
}
Also used : Gson(com.google.gson.Gson) Workflow(com.tremolosecurity.provisioning.core.Workflow) Approvals(com.tremolosecurity.provisioning.objects.Approvals) Token(com.tremolosecurity.json.Token) SecretKey(javax.crypto.SecretKey) AllowedApprovers(com.tremolosecurity.provisioning.objects.AllowedApprovers) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) Approval(com.tremolosecurity.provisioning.tasks.Approval) HashSet(java.util.HashSet) Session(org.hibernate.Session)

Example 3 with AllowedApprovers

use of com.tremolosecurity.provisioning.objects.AllowedApprovers in project OpenUnison by TremoloSecurity.

the class RemindApprovers 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 msg = context.getJobDetail().getJobDataMap().getString("message");
    int days = Integer.parseInt(context.getJobDetail().getJobDataMap().getString("days"));
    String mailAttribute = context.getJobDetail().getJobDataMap().getString("mailAttributeName");
    Session session = null;
    try {
        session = configManager.getProvisioningEngine().getHibernateSessionFactory().openSession();
        DateTime approvalsAfterDate = new DateTime().minusDays(days + 1);
        Query query = session.createQuery("FROM Approvals WHERE approved IS NULL AND createTS > :check_date");
        query.setParameter("check_date", new java.sql.Date(approvalsAfterDate.getMillis()));
        List<com.tremolosecurity.provisioning.objects.Approvals> approvals = query.list();
        DateTime now = new DateTime();
        for (Approvals apr : approvals) {
            int daysOpen = Days.daysBetween(new DateTime(apr.getCreateTs().getTime()), now).getDays();
            String label = apr.getLabel();
            String mail = null;
            for (AllowedApprovers allowed : apr.getAllowedApproverses()) {
                mail = null;
                for (ApproverAttributes attr : allowed.getApprovers().getApproverAttributeses()) {
                    if (attr.getName().equalsIgnoreCase(mailAttribute)) {
                        mail = attr.getValue();
                    }
                }
                if (mail == null) {
                    logger.warn("No attribute called '" + mailAttribute + "' for user '" + allowed.getApprovers().getUserKey() + "'");
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Notifying " + mail + " for " + label + " after " + daysOpen + " days");
                    }
                    String toSend = msg.replaceAll("[%]L", label).replaceAll("[%]D", Integer.toString(daysOpen));
                    configManager.getProvisioningEngine().sendNotification(mail, toSend, "Open Approval for " + daysOpen + " days", new User(mail));
                }
            }
        }
    } catch (Exception e) {
        throw new ProvisioningException("Error reminding open approvers", e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}
Also used : ApproverAttributes(com.tremolosecurity.provisioning.objects.ApproverAttributes) User(com.tremolosecurity.provisioning.core.User) Query(org.hibernate.Query) Approvals(com.tremolosecurity.provisioning.objects.Approvals) DateTime(org.joda.time.DateTime) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) SQLException(java.sql.SQLException) AllowedApprovers(com.tremolosecurity.provisioning.objects.AllowedApprovers) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Session(org.hibernate.Session)

Example 4 with AllowedApprovers

use of com.tremolosecurity.provisioning.objects.AllowedApprovers in project OpenUnison by TremoloSecurity.

the class AzUtils method loadFilterApprovers.

public static boolean loadFilterApprovers(Approvals approval, String emailTemplate, ConfigManager cfg, Session session, int id, String constraint, boolean sendNotification) throws ProvisioningException {
    ArrayList<String> attrs = new ArrayList<String>();
    // attrs.add(cfg.getProvisioningEngine().getUserIDAttribute());
    LDAPSearchResults res = null;
    LDAPEntry entry = null;
    boolean found = false;
    try {
        res = cfg.getMyVD().search(cfg.getCfg().getLdapRoot(), 2, constraint, attrs);
        while (res.hasMore()) {
            entry = res.next();
            LDAPAttribute attr = entry.getAttribute(cfg.getProvisioningEngine().getUserIDAttribute());
            if (attr == null) {
                continue;
            }
            if (sendNotification) {
                if (entry.getAttribute("mail") == null) {
                    StringBuffer b = new StringBuffer();
                    b.append("No email address for ").append(entry.getDN());
                    logger.warn(b.toString());
                } else {
                    String mail = entry.getAttribute("mail").getStringValue();
                    cfg.getProvisioningEngine().sendNotification(mail, emailTemplate, new User(entry));
                }
            }
            String uid = attr.getStringValue();
            Approvers approver = getApprover(approval, emailTemplate, cfg, session, uid, entry);
            if (approver == null) {
                continue;
            }
            found = true;
            AllowedApprovers allowed = new AllowedApprovers();
            allowed.setApprovals(approval);
            allowed.setApprovers(approver);
            session.save(allowed);
        }
    } catch (Exception e) {
        throw new ProvisioningException("Could not find approvers", e);
    }
    return found;
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) User(com.tremolosecurity.provisioning.core.User) ArrayList(java.util.ArrayList) LDAPException(com.novell.ldap.LDAPException) SQLException(java.sql.SQLException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPReferralException(com.novell.ldap.LDAPReferralException) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) AllowedApprovers(com.tremolosecurity.provisioning.objects.AllowedApprovers) Approvers(com.tremolosecurity.provisioning.objects.Approvers) AllowedApprovers(com.tremolosecurity.provisioning.objects.AllowedApprovers) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException)

Example 5 with AllowedApprovers

use of com.tremolosecurity.provisioning.objects.AllowedApprovers in project OpenUnison by TremoloSecurity.

the class AzUtils method loadStaticGroupApprovers.

public static boolean loadStaticGroupApprovers(Approvals approval, String emailTemplate, ConfigManager cfg, Session session, int id, String constraint, boolean sendNotification) throws ProvisioningException {
    ArrayList<String> attrs = new ArrayList<String>();
    attrs.add(cfg.getCfg().getGroupMemberAttribute());
    LDAPSearchResults res = null;
    LDAPEntry entry = null;
    boolean found = false;
    try {
        res = cfg.getMyVD().search(constraint, 0, "(objectClass=*)", attrs);
        if (res.hasMore()) {
            entry = res.next();
        }
    } catch (LDAPException e) {
        throw new ProvisioningException("Could not find group", e);
    }
    if (entry != null) {
        LDAPAttribute members = entry.getAttribute(cfg.getCfg().getGroupMemberAttribute());
        String[] dns = members != null ? members.getStringValueArray() : new String[0];
        if (dns.length == 0) {
            StringBuffer b = new StringBuffer();
            b.append(constraint).append(" does not have any members");
            logger.warn(b.toString());
        }
        try {
            for (String dn : dns) {
                Approvers approver = getApproverByDN(approval, emailTemplate, cfg, session, dn, sendNotification);
                if (approver == null) {
                    continue;
                }
                AllowedApprovers allowed = new AllowedApprovers();
                allowed.setApprovals(approval);
                allowed.setApprovers(approver);
                session.save(allowed);
                found = true;
            }
        } catch (Exception e) {
            throw new ProvisioningException("Could not load approvers", e);
        }
    }
    return found;
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) ArrayList(java.util.ArrayList) LDAPException(com.novell.ldap.LDAPException) SQLException(java.sql.SQLException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPReferralException(com.novell.ldap.LDAPReferralException) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) LDAPException(com.novell.ldap.LDAPException) AllowedApprovers(com.tremolosecurity.provisioning.objects.AllowedApprovers) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Approvers(com.tremolosecurity.provisioning.objects.Approvers) AllowedApprovers(com.tremolosecurity.provisioning.objects.AllowedApprovers)

Aggregations

ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)6 AllowedApprovers (com.tremolosecurity.provisioning.objects.AllowedApprovers)6 SQLException (java.sql.SQLException)5 LDAPException (com.novell.ldap.LDAPException)4 LDAPReferralException (com.novell.ldap.LDAPReferralException)4 Approvers (com.tremolosecurity.provisioning.objects.Approvers)4 LDAPEntry (com.novell.ldap.LDAPEntry)3 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)3 ArrayList (java.util.ArrayList)3 LDAPAttribute (com.novell.ldap.LDAPAttribute)2 User (com.tremolosecurity.provisioning.core.User)2 Approvals (com.tremolosecurity.provisioning.objects.Approvals)2 Session (org.hibernate.Session)2 Gson (com.google.gson.Gson)1 Token (com.tremolosecurity.json.Token)1 Workflow (com.tremolosecurity.provisioning.core.Workflow)1 ApproverAttributes (com.tremolosecurity.provisioning.objects.ApproverAttributes)1 Approval (com.tremolosecurity.provisioning.tasks.Approval)1 HashSet (java.util.HashSet)1 Cipher (javax.crypto.Cipher)1