Search in sources :

Example 6 with ProvisioningResult

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

the class GenerateReport method generateReportData.

private void generateReportData(HttpServletRequest req, HttpServletResponse resp, Gson gson, ReportType reportToRun, Connection db) throws SQLException, IOException {
    PreparedStatement ps;
    ResultSet rs;
    if (logger.isDebugEnabled()) {
        logger.debug("Report SQL : '" + reportToRun.getSql() + "'");
    }
    ps = db.prepareStatement(reportToRun.getSql());
    int i = 1;
    for (String paramType : reportToRun.getParamater()) {
        switch(paramType) {
            case "currentUser":
                if (logger.isDebugEnabled()) {
                    logger.debug("Current User : '" + req.getParameter("currentUser") + "'");
                }
                ps.setString(i, req.getParameter("currentUser"));
                break;
            case "userKey":
                if (logger.isDebugEnabled()) {
                    logger.debug("User Key : '" + req.getParameter("userKey") + "'");
                }
                ps.setString(i, req.getParameter("userKey"));
                break;
            case "beginDate":
                String beginDate = req.getParameter("beginDate");
                if (logger.isDebugEnabled()) {
                    logger.debug("Begin Date : '" + beginDate + "'");
                }
                Date d = new Date(DateTime.parse(beginDate).getMillis());
                ps.setDate(i, d);
                break;
            case "endDate":
                String endDate = req.getParameter("endDate");
                if (logger.isDebugEnabled()) {
                    logger.debug("End Date : '" + endDate + "'");
                }
                Date de = new Date(DateTime.parse(endDate).getMillis());
                ps.setDate(i, de);
                break;
        }
        i++;
    }
    rs = ps.executeQuery();
    String groupingVal = null;
    ReportResults res = new ReportResults();
    res.setName(reportToRun.getName());
    res.setDescription(reportToRun.getDescription());
    res.setDataFields(reportToRun.getDataFields());
    res.setHeaderFields(reportToRun.getHeaderFields());
    res.setGrouping(new ArrayList<ReportGrouping>());
    ReportGrouping grouping = null;
    if (!reportToRun.isGroupings()) {
        grouping = new ReportGrouping();
        grouping.setData(new ArrayList<Map<String, String>>());
        grouping.setHeader(new HashMap<String, String>());
        res.getGrouping().add(grouping);
    }
    logger.debug("Running report");
    while (rs.next()) {
        if (logger.isDebugEnabled()) {
            logger.debug("New row");
        }
        HashMap<String, String> row = new HashMap<String, String>();
        for (String dataField : reportToRun.getDataFields()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Field - " + dataField + "='" + rs.getString(dataField) + "'");
            }
            row.put(dataField, rs.getString(dataField));
        }
        if (reportToRun.isGroupings()) {
            String rowID = rs.getString(reportToRun.getGroupBy());
            if (logger.isDebugEnabled()) {
                logger.debug("Grouping Val : '" + groupingVal + "'");
                logger.debug("Group By : '" + reportToRun.getGroupBy() + "'");
                logger.debug("Value of Group By in row : '" + rowID + "'");
            }
            if (groupingVal == null || !groupingVal.equals(rowID)) {
                grouping = new ReportGrouping();
                grouping.setData(new ArrayList<Map<String, String>>());
                grouping.setHeader(new HashMap<String, String>());
                res.getGrouping().add(grouping);
                for (String headerField : reportToRun.getHeaderFields()) {
                    grouping.getHeader().put(headerField, rs.getString(headerField));
                }
                groupingVal = rowID;
            }
        }
        grouping.getData().add(row);
    }
    ProvisioningResult pres = new ProvisioningResult();
    pres.setSuccess(true);
    pres.setReportResults(res);
    String json = gson.toJson(pres);
    if (logger.isDebugEnabled()) {
        logger.debug("JSON : " + json);
    }
    resp.getOutputStream().print(json);
}
Also used : HashMap(java.util.HashMap) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) PreparedStatement(java.sql.PreparedStatement) ReportGrouping(com.tremolosecurity.provisioning.service.util.ReportGrouping) Date(java.sql.Date) ResultSet(java.sql.ResultSet) ReportResults(com.tremolosecurity.provisioning.service.util.ReportResults) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with ProvisioningResult

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

the class ListApprovals method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String approver = req.getParameter("approver");
    int approvalID = Integer.parseInt(req.getParameter("approvalID"));
    Connection con = null;
    Gson gson = new Gson();
    if (approvalID == 0) {
        // list all approvals
        try {
            ProvisioningResult pres = new ProvisioningResult();
            pres.setSuccess(true);
            pres.setSummaries(ServiceActions.listOpenApprovals(approver, GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getApprovalDB().getUserIdAttribute(), GlobalEntries.getGlobalEntries().getConfigManager()));
            resp.getOutputStream().print(gson.toJson(pres));
        } catch (ProvisioningException e) {
            ProvisioningError pe = new ProvisioningError();
            pe.setError("Could not load executed workflows : " + e.getMessage());
            ProvisioningResult res = new ProvisioningResult();
            res.setSuccess(false);
            res.setError(pe);
            resp.getWriter().write(gson.toJson(res));
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                }
            }
        }
    } else {
        try {
            ProvisioningResult pres = new ProvisioningResult();
            pres.setSuccess(true);
            pres.setApprovalDetail(ServiceActions.loadApprovalDetails(approver, approvalID));
            resp.getOutputStream().print(gson.toJson(pres));
        } catch (Throwable e) {
            logger.error("Could not load approval", e);
            ProvisioningError pe = new ProvisioningError();
            pe.setError("Could not load executed approval : " + e.getMessage());
            ProvisioningResult res = new ProvisioningResult();
            res.setSuccess(false);
            res.setError(pe);
            resp.getWriter().write(gson.toJson(res));
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) SQLException(java.sql.SQLException) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Connection(java.sql.Connection) Gson(com.google.gson.Gson)

Example 8 with ProvisioningResult

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

the class ListOrgs 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();
        b.append("(").append(uidAttr).append("=").append(userID).append(")");
        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();
        OrgType ot = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getOrg();
        Organization org = new Organization();
        copyOrg(org, ot, az, auinfo);
        Gson gson = new Gson();
        ProvisioningResult pres = new ProvisioningResult();
        pres.setSuccess(true);
        pres.setOrg(org);
        resp.getOutputStream().print(gson.toJson(pres));
    } catch (Exception e) {
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Could not load orgs : " + 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 orgs", e);
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) Organization(com.tremolosecurity.provisioning.service.util.Organization) LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) Gson(com.google.gson.Gson) LDAPException(com.novell.ldap.LDAPException) ServletException(javax.servlet.ServletException) MalformedURLException(java.net.MalformedURLException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) OrgType(com.tremolosecurity.config.xml.OrgType) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) AzSys(com.tremolosecurity.proxy.auth.AzSys)

Example 9 with ProvisioningResult

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

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

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