Search in sources :

Example 11 with ProvisioningResult

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

the class ListWorkflows method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {
        String uuid = req.getParameter("uuid");
        ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager();
        List<WorkflowType> wfs = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getWorkflows().getWorkflow();
        ArrayList<WFDescription> workflows = new ArrayList<WFDescription>();
        for (WorkflowType wf : wfs) {
            if (wf.isInList() != null && wf.isInList().booleanValue()) {
                if (wf.getOrgid() == null || wf.getOrgid().equalsIgnoreCase(uuid)) {
                    if (wf.getDynamicConfiguration() != null && wf.getDynamicConfiguration().isDynamic()) {
                        HashMap<String, Attribute> params = new HashMap<String, Attribute>();
                        if (wf.getDynamicConfiguration().getParam() != null) {
                            for (ParamType p : wf.getDynamicConfiguration().getParam()) {
                                Attribute attr = params.get(p.getName());
                                if (attr == null) {
                                    attr = new Attribute(p.getName());
                                    params.put(p.getName(), attr);
                                }
                                attr.getValues().add(p.getValue());
                            }
                        }
                        DynamicWorkflow dwf = (DynamicWorkflow) Class.forName(wf.getDynamicConfiguration().getClassName()).newInstance();
                        List<Map<String, String>> wfParams = dwf.generateWorkflows(wf, GlobalEntries.getGlobalEntries().getConfigManager(), params);
                        StringBuffer b = new StringBuffer();
                        b.append('/').append(URLEncoder.encode(wf.getName(), "UTF-8"));
                        String uri = b.toString();
                        for (Map<String, String> wfParamSet : wfParams) {
                            DateTime now = new DateTime();
                            DateTime expires = now.plusHours(1);
                            LastMile lm = new LastMile(uri, now, expires, 0, "");
                            for (String key : wfParamSet.keySet()) {
                                String val = wfParamSet.get(key);
                                Attribute attr = new Attribute(key, val);
                                lm.getAttributes().add(attr);
                            }
                            WFDescription desc = new WFDescription();
                            desc.setUuid(UUID.randomUUID().toString());
                            desc.setName(wf.getName());
                            ST st = new ST(wf.getLabel(), '$', '$');
                            for (String key : wfParamSet.keySet()) {
                                st.add(key.replaceAll("[.]", "_"), wfParamSet.get(key));
                            }
                            desc.setLabel(st.render());
                            st = new ST(wf.getDescription(), '$', '$');
                            for (String key : wfParamSet.keySet()) {
                                st.add(key.replaceAll("[.]", "_"), wfParamSet.get(key));
                            }
                            desc.setDescription(st.render());
                            desc.setEncryptedParams(lm.generateLastMileToken(cfgMgr.getSecretKey(cfgMgr.getCfg().getProvisioning().getApprovalDB().getEncryptionKey())));
                            workflows.add(desc);
                        }
                    } else {
                        WFDescription desc = new WFDescription();
                        desc.setUuid(UUID.randomUUID().toString());
                        desc.setName(wf.getName());
                        desc.setLabel(wf.getLabel());
                        desc.setDescription(wf.getDescription());
                        workflows.add(desc);
                    }
                }
            }
        }
        WFDescriptions descs = new WFDescriptions();
        descs.setWorkflows(workflows);
        Gson gson = new Gson();
        ProvisioningResult pres = new ProvisioningResult();
        pres.setSuccess(true);
        pres.setWfDescriptions(descs);
        resp.getOutputStream().print(gson.toJson(pres));
    } catch (Exception e) {
        logger.error("Could not load workflows", e);
        Gson gson = new Gson();
        ProvisioningResult pres = new ProvisioningResult();
        pres.setSuccess(false);
        pres.setError(new ProvisioningError("Could not load workflows"));
        resp.getOutputStream().print(gson.toJson(pres));
    }
}
Also used : ST(org.stringtemplate.v4.ST) Attribute(com.tremolosecurity.saml.Attribute) HashMap(java.util.HashMap) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) ConfigManager(com.tremolosecurity.config.util.ConfigManager) ParamType(com.tremolosecurity.config.xml.ParamType) DateTime(org.joda.time.DateTime) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) LastMile(com.tremolosecurity.lastmile.LastMile) WFDescription(com.tremolosecurity.provisioning.service.util.WFDescription) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) WorkflowType(com.tremolosecurity.config.xml.WorkflowType) DynamicWorkflow(com.tremolosecurity.provisioning.util.DynamicWorkflow) HashMap(java.util.HashMap) Map(java.util.Map) WFDescriptions(com.tremolosecurity.provisioning.service.util.WFDescriptions)

Example 12 with ProvisioningResult

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

the class Login method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ProvisioningResult res = new ProvisioningResult();
    res.setSuccess(true);
    Gson gson = new Gson();
    resp.setContentType("text/json");
    resp.getWriter().write(gson.toJson(res));
}
Also used : ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) Gson(com.google.gson.Gson)

Example 13 with ProvisioningResult

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

the class SearchService method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/json");
    try {
        String filter = "";
        String base = "";
        int scope = 0;
        if (req.getParameter("uid") != null) {
            StringBuffer sfilter = new StringBuffer();
            sfilter.append("(uid=").append(req.getParameter("uid")).append(')');
            if (logger.isDebugEnabled()) {
                logger.debug("UID Filter : '" + sfilter.toString() + "'");
            }
            filter = sfilter.toString();
            base = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot();
            scope = 2;
        } else if (req.getParameter("dn") != null) {
            filter = "(objectClass=*)";
            base = req.getParameter("dn");
            if (logger.isDebugEnabled()) {
                logger.debug("Base DN : '" + base + "'");
            }
            scope = 0;
        } else if (req.getParameter("filter") != null) {
            filter = req.getParameter("filter");
            if (logger.isDebugEnabled()) {
                logger.debug("Filter : '" + filter + "'");
            }
            base = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot();
            scope = 2;
        }
        ArrayList<String> attrs = new ArrayList<String>();
        String[] attrNames = req.getParameterValues("attr");
        boolean uidFound = false;
        if (attrNames != null) {
            for (String attrName : attrNames) {
                if (attrName.equalsIgnoreCase("uid")) {
                    uidFound = true;
                }
                attrs.add(attrName);
            }
            if (!uidFound) {
                attrs.add("uid");
            }
        }
        MyVDConnection con = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD();
        LDAPSearchResults res = con.search(base, scope, filter, attrs);
        if (!res.hasMore()) {
            ProvisioningException ex = new ProvisioningException("User not found");
            ex.setPrintStackTrace(false);
            throw ex;
        }
        LDAPEntry entry = res.next();
        TremoloUser user = new TremoloUser();
        user.setDn(entry.getDN());
        int lq = entry.getDN().lastIndexOf(',');
        int fq = entry.getDN().lastIndexOf('=', lq - 1) + 1;
        user.setDirectory(entry.getDN().substring(fq, lq));
        for (Object attr : entry.getAttributeSet()) {
            LDAPAttribute attribute = (LDAPAttribute) attr;
            Attribute usrAttr = new Attribute(attribute.getName());
            if (attribute.getName().equalsIgnoreCase("uid")) {
                user.setUid(attribute.getStringValue());
                if (!uidFound && attrs.size() > 1) {
                    continue;
                }
            }
            for (String val : attribute.getStringValueArray()) {
                usrAttr.getValues().add(val);
            }
            user.getAttributes().add(usrAttr);
        }
        while (res.hasMore()) res.next();
        ArrayList<String> reqAttrs = new ArrayList<String>();
        reqAttrs.add("cn");
        StringBuffer b = new StringBuffer();
        b.append("(").append(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute()).append(")=").append(user.getDn()).append(")");
        res = con.search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(), user.getDn()).toString(), reqAttrs);
        while (res.hasMore()) {
            entry = res.next();
            LDAPAttribute groups = entry.getAttribute("cn");
            for (String val : groups.getStringValueArray()) {
                user.getGroups().add(val);
            }
        }
        ProvisioningResult resObj = new ProvisioningResult();
        resObj.setSuccess(true);
        resObj.setUser(user);
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        // System.out.println(gson.toJson(user));
        resp.getWriter().print(gson.toJson(resObj));
    } catch (ProvisioningException pe) {
        if (pe.isPrintStackTrace()) {
            logger.error("Error searching for a user", pe);
        } else {
            logger.warn(pe.toString());
        }
        resp.setStatus(500);
        ProvisioningError pre = new ProvisioningError();
        pre.setError(pe.toString());
        ProvisioningResult resObj = new ProvisioningResult();
        resObj.setSuccess(false);
        resObj.setError(pre);
        Gson gson = new Gson();
        resp.getOutputStream().print(gson.toJson(resObj));
    } catch (Throwable t) {
        logger.error("Error searching", t);
        resp.setStatus(500);
        ProvisioningError pe = new ProvisioningError();
        pe.setError(t.toString());
        ProvisioningResult resObj = new ProvisioningResult();
        resObj.setSuccess(false);
        resObj.setError(pe);
        Gson gson = new Gson();
        resp.getOutputStream().print(gson.toJson(resObj));
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) LDAPAttribute(com.novell.ldap.LDAPAttribute) GsonBuilder(com.google.gson.GsonBuilder) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) TremoloUser(com.tremolosecurity.provisioning.service.util.TremoloUser) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) MyVDConnection(com.tremolosecurity.proxy.myvd.MyVDConnection)

Example 14 with ProvisioningResult

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

the class ExecuteApproval method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    int approvalID = Integer.parseInt(req.getParameter("approvalID"));
    String approver = req.getParameter("approver");
    boolean approved = Boolean.parseBoolean(req.getParameter("approved"));
    String reason = req.getParameter("reason");
    Gson gson = new Gson();
    try {
        GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().doApproval(approvalID, approver, approved, reason);
        ProvisioningResult res = new ProvisioningResult();
        res.setSuccess(true);
        resp.getOutputStream().print(gson.toJson(res));
    } catch (ProvisioningException e) {
        logger.error("Could not execute approval", e);
        resp.setStatus(500);
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Could not execute approval;" + e.getMessage());
        ProvisioningResult resObj = new ProvisioningResult();
        resObj.setSuccess(false);
        resObj.setError(pe);
        gson = new Gson();
        resp.getOutputStream().print(gson.toJson(resObj));
    }
}
Also used : ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Gson(com.google.gson.Gson)

Aggregations

ProvisioningResult (com.tremolosecurity.provisioning.service.util.ProvisioningResult)14 Gson (com.google.gson.Gson)12 ProvisioningError (com.tremolosecurity.provisioning.service.util.ProvisioningError)10 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)9 IOException (java.io.IOException)7 Attribute (com.tremolosecurity.saml.Attribute)6 ServletException (javax.servlet.ServletException)6 ArrayList (java.util.ArrayList)5 LDAPAttribute (com.novell.ldap.LDAPAttribute)4 LDAPEntry (com.novell.ldap.LDAPEntry)4 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)4 LDAPAttributeSet (com.novell.ldap.LDAPAttributeSet)3 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)3 AzSys (com.tremolosecurity.proxy.auth.AzSys)3 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConfigManager (com.tremolosecurity.config.util.ConfigManager)2 OrgType (com.tremolosecurity.config.xml.OrgType)2 ReportType (com.tremolosecurity.config.xml.ReportType)2