Search in sources :

Example 6 with ProvisioningError

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

the class ListPortalURLs method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String userID = req.getParameter("uid");
    String uidAttr = req.getParameter("uidAttr");
    ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager();
    try {
        StringBuffer b = new StringBuffer();
        LDAPSearchResults res = cfgMgr.getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(uidAttr, userID).toString(), new ArrayList<String>());
        if (!res.hasMore()) {
            throw new ProvisioningException("Could not locate user '" + userID + "'");
        }
        LDAPEntry entry = res.next();
        AuthInfo auinfo = new AuthInfo();
        auinfo.setUserDN(entry.getDN());
        LDAPAttributeSet attrs = entry.getAttributeSet();
        for (Object obj : attrs) {
            LDAPAttribute attr = (LDAPAttribute) obj;
            Attribute attrib = new Attribute(attr.getName());
            String[] vals = attr.getStringValueArray();
            for (String val : vals) {
                attrib.getValues().add(val);
            }
            auinfo.getAttribs().put(attrib.getName(), attrib);
        }
        AzSys az = new AzSys();
        PortalUrlsType pt = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getPortal();
        PortalURLs urls = new PortalURLs();
        for (PortalUrlType url : pt.getUrls()) {
            if (url.getAzRules() != null && url.getAzRules().getRule().size() > 0) {
                ArrayList<AzRule> rules = new ArrayList<AzRule>();
                for (AzRuleType art : url.getAzRules().getRule()) {
                    rules.add(new AzRule(art.getScope(), art.getConstraint(), art.getClassName(), cfgMgr, null));
                }
                if (!az.checkRules(auinfo, GlobalEntries.getGlobalEntries().getConfigManager(), rules, null)) {
                    continue;
                }
            }
            PortalURL purl = new PortalURL();
            purl.setName(url.getName());
            purl.setLabel(url.getLabel());
            purl.setOrg(url.getOrg());
            purl.setUrl(url.getUrl());
            purl.setIcon(url.getIcon());
            urls.getUrls().add(purl);
        }
        Gson gson = new Gson();
        ProvisioningResult pres = new ProvisioningResult();
        pres.setSuccess(true);
        pres.setPortalURLs(urls);
        resp.getOutputStream().print(gson.toJson(pres));
    } catch (Exception e) {
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Could not load urls : " + e.getMessage());
        ProvisioningResult res = new ProvisioningResult();
        res.setSuccess(false);
        res.setError(pe);
        Gson gson = new Gson();
        resp.getWriter().write(gson.toJson(res));
        logger.error("Could not load urls", e);
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) PortalUrlType(com.tremolosecurity.config.xml.PortalUrlType) PortalURL(com.tremolosecurity.provisioning.service.util.PortalURL) PortalURLs(com.tremolosecurity.provisioning.service.util.PortalURLs) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) PortalUrlsType(com.tremolosecurity.config.xml.PortalUrlsType) AzRuleType(com.tremolosecurity.config.xml.AzRuleType) LDAPEntry(com.novell.ldap.LDAPEntry) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPAttribute(com.novell.ldap.LDAPAttribute) AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) ConfigManager(com.tremolosecurity.config.util.ConfigManager) ServletException(javax.servlet.ServletException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) AzSys(com.tremolosecurity.proxy.auth.AzSys) AzRule(com.tremolosecurity.proxy.az.AzRule)

Example 7 with ProvisioningError

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

the class ListReports method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String userID = req.getParameter("uid");
    String uidAttr = req.getParameter("uidAttr");
    try {
        StringBuffer b = new StringBuffer();
        LDAPSearchResults res = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(uidAttr, userID).toString(), new ArrayList<String>());
        if (!res.hasMore()) {
            throw new ProvisioningException("Could not locate user '" + userID + "'");
        }
        LDAPEntry entry = res.next();
        AuthInfo auinfo = new AuthInfo();
        auinfo.setUserDN(entry.getDN());
        LDAPAttributeSet attrs = entry.getAttributeSet();
        for (Object obj : attrs) {
            LDAPAttribute attr = (LDAPAttribute) obj;
            Attribute attrib = new Attribute(attr.getName());
            String[] vals = attr.getStringValueArray();
            for (String val : vals) {
                attrib.getValues().add(val);
            }
            auinfo.getAttribs().put(attrib.getName(), attrib);
        }
        AzSys az = new AzSys();
        HashSet<String> allowedOrgs = new HashSet<String>();
        OrgType root = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getOrg();
        this.checkOrg(allowedOrgs, root, az, auinfo);
        ReportsType reports = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getReports();
        ReportsList reportsList = new ReportsList();
        reportsList.setReports(new ArrayList<ReportInformation>());
        for (ReportType report : reports.getReport()) {
            if (allowedOrgs.contains(report.getOrgID())) {
                ReportInformation ri = new ReportInformation();
                ri.setName(report.getName());
                ri.setDescription(report.getDescription());
                ri.setOrgID(report.getOrgID());
                ri.setParameters(new ArrayList<String>());
                ri.getParameters().addAll(report.getParamater());
                reportsList.getReports().add(ri);
            }
        }
        Gson gson = new Gson();
        ProvisioningResult pres = new ProvisioningResult();
        pres.setSuccess(true);
        pres.setReportsList(reportsList);
        resp.getOutputStream().print(gson.toJson(pres));
    } catch (Exception e) {
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Could not load urls : " + e.getMessage());
        ProvisioningResult res = new ProvisioningResult();
        res.setSuccess(false);
        res.setError(pe);
        Gson gson = new Gson();
        resp.getWriter().write(gson.toJson(res));
        logger.error("Could not load urls", e);
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) Gson(com.google.gson.Gson) ReportInformation(com.tremolosecurity.provisioning.service.util.ReportInformation) LDAPEntry(com.novell.ldap.LDAPEntry) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ReportType(com.tremolosecurity.config.xml.ReportType) HashSet(java.util.HashSet) LDAPAttribute(com.novell.ldap.LDAPAttribute) AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) ReportsList(com.tremolosecurity.provisioning.service.util.ReportsList) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) ServletException(javax.servlet.ServletException) MalformedURLException(java.net.MalformedURLException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) OrgType(com.tremolosecurity.config.xml.OrgType) AzSys(com.tremolosecurity.proxy.auth.AzSys) ReportsType(com.tremolosecurity.config.xml.ReportsType)

Example 8 with ProvisioningError

use of com.tremolosecurity.provisioning.service.util.ProvisioningError 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 9 with ProvisioningError

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

use of com.tremolosecurity.provisioning.service.util.ProvisioningError 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

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