Search in sources :

Example 1 with ReportType

use of com.tremolosecurity.config.xml.ReportType in project OpenUnison by TremoloSecurity.

the class GenerateReport method doGet.

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    final Gson gson = new Gson();
    try {
        String name = req.getParameter("name");
        ReportType reportToRunTmp = null;
        boolean foundReport = false;
        for (ReportType report : GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getReports().getReport()) {
            if (report.getName().equalsIgnoreCase(name)) {
                reportToRunTmp = report;
                foundReport = true;
                break;
            }
        }
        if (!foundReport) {
            reportToRunTmp = null;
        }
        final ReportType reportToRun = reportToRunTmp;
        if (reportToRun == null) {
            throw new ProvisioningException("Could not find report");
        } else {
            Connection db = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            try {
                Session session = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getHibernateSessionFactory().openSession();
                session.doWork(new Work() {

                    public void execute(Connection connection) throws SQLException {
                        try {
                            generateReportData(req, resp, gson, reportToRun, connection);
                        } catch (IOException e) {
                            throw new SQLException("Could not run reports", e);
                        }
                    }
                });
            } finally {
            }
        }
    } catch (Exception e) {
        logger.error("Could not run report", e);
        resp.setStatus(500);
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Could not run report;" + e.getMessage());
        ProvisioningResult resObj = new ProvisioningResult();
        resObj.setSuccess(false);
        resObj.setError(pe);
        resp.getOutputStream().print(gson.toJson(resObj));
    }
}
Also used : SQLException(java.sql.SQLException) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) Connection(java.sql.Connection) Gson(com.google.gson.Gson) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ResultSet(java.sql.ResultSet) Work(org.hibernate.jdbc.Work) ReportType(com.tremolosecurity.config.xml.ReportType) Session(org.hibernate.Session)

Example 2 with ReportType

use of com.tremolosecurity.config.xml.ReportType in project OpenUnison by TremoloSecurity.

the class ScaleMain method runReport.

private void runReport(final HttpFilterRequest request, final HttpFilterResponse response, final Gson gson) throws UnsupportedEncodingException, IOException, MalformedURLException, ProvisioningException, SQLException {
    String name = URLDecoder.decode(request.getRequestURI().substring(request.getRequestURI().lastIndexOf('/') + 1), "UTF-8");
    ReportType reportToRun = null;
    for (ReportType report : GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getReports().getReport()) {
        if (report.getName().equalsIgnoreCase(name)) {
            reportToRun = report;
            break;
        }
    }
    if (reportToRun == null) {
        response.setStatus(404);
        ScaleError error = new ScaleError();
        error.getErrors().add("Report not found");
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().print(gson.toJson(error).trim());
        response.getWriter().flush();
    } else {
        HashSet<String> allowedOrgs = new HashSet<String>();
        final AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
        OrgType ot = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getOrg();
        AzSys az = new AzSys();
        this.checkOrg(allowedOrgs, ot, az, userData, request.getSession());
        if (allowedOrgs.contains(reportToRun.getOrgID())) {
            Connection db = null;
            final ReportType reportToRunUse = reportToRun;
            try {
                Session session = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getHibernateSessionFactory().openSession();
                session.doWork(new Work() {

                    public void execute(Connection connection) throws SQLException {
                        try {
                            generateReport(request, response, gson, reportToRunUse, userData, connection);
                        } catch (IOException e) {
                            throw new SQLException("Could not run reports", e);
                        }
                    }
                });
            } finally {
            }
        } else {
            response.setStatus(401);
            ScaleError error = new ScaleError();
            error.getErrors().add("Unauthorized");
            ScaleJSUtils.addCacheHeaders(response);
            response.getWriter().print(gson.toJson(error).trim());
            response.getWriter().flush();
        }
    }
}
Also used : AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ScaleError(com.tremolosecurity.scalejs.data.ScaleError) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) IOException(java.io.IOException) AuthController(com.tremolosecurity.proxy.auth.AuthController) OrgType(com.tremolosecurity.config.xml.OrgType) AzSys(com.tremolosecurity.proxy.auth.AzSys) Work(org.hibernate.jdbc.Work) ReportType(com.tremolosecurity.config.xml.ReportType) HashSet(java.util.HashSet) Session(org.hibernate.Session) HttpSession(javax.servlet.http.HttpSession)

Example 3 with ReportType

use of com.tremolosecurity.config.xml.ReportType in project OpenUnison by TremoloSecurity.

the class ScaleMain method loadReports.

private void loadReports(HttpFilterRequest request, HttpFilterResponse response, Gson gson) throws MalformedURLException, ProvisioningException, IOException {
    String orgid = request.getRequestURI().substring(request.getRequestURI().lastIndexOf('/') + 1);
    ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager();
    HashSet<String> allowedOrgs = new HashSet<String>();
    AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
    OrgType ot = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getOrg();
    AzSys az = new AzSys();
    this.checkOrg(allowedOrgs, ot, az, userData, request.getSession());
    if (!allowedOrgs.contains(orgid)) {
        response.setStatus(401);
        response.setContentType("application/json");
        ScaleError error = new ScaleError();
        error.getErrors().add("Unauthorized");
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().print(gson.toJson(error).trim());
        response.getWriter().flush();
    } else {
        ReportsType reports = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getReports();
        ReportsList reportsList = new ReportsList();
        reportsList.setReports(new ArrayList<ReportInformation>());
        if (reports != null && reports.getReport() != null) {
            for (ReportType report : reports.getReport()) {
                if (report.getOrgID().equals(orgid)) {
                    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());
                    ri.getParameters().remove("currentUser");
                    reportsList.getReports().add(ri);
                }
            }
        }
        response.setContentType("application/json");
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().println(gson.toJson(reportsList).trim());
        response.getWriter().flush();
    }
}
Also used : AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) ReportsList(com.tremolosecurity.provisioning.service.util.ReportsList) ScaleError(com.tremolosecurity.scalejs.data.ScaleError) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) AuthController(com.tremolosecurity.proxy.auth.AuthController) ConfigManager(com.tremolosecurity.config.util.ConfigManager) ReportInformation(com.tremolosecurity.provisioning.service.util.ReportInformation) OrgType(com.tremolosecurity.config.xml.OrgType) AzSys(com.tremolosecurity.proxy.auth.AzSys) ReportsType(com.tremolosecurity.config.xml.ReportsType) ReportType(com.tremolosecurity.config.xml.ReportType) HashSet(java.util.HashSet)

Example 4 with ReportType

use of com.tremolosecurity.config.xml.ReportType 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 5 with ReportType

use of com.tremolosecurity.config.xml.ReportType in project OpenUnison by TremoloSecurity.

the class LoadReportsFromK8s method createReport.

private void createReport(JSONObject item, String name) {
    ReportType report = new ReportType();
    JSONObject spec = (JSONObject) item.get("spec");
    StringBuffer b = new StringBuffer();
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("name"));
    report.setName(b.toString());
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("description"));
    report.setDescription(b.toString());
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("orgId"));
    report.setOrgID(b.toString());
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("sql"));
    report.setSql(b.toString());
    if (spec.get("groupings") == null) {
        report.setGroupings(false);
    } else {
        report.setGroupings((Boolean) spec.get("groupings"));
        if (report.isGroupings()) {
            b.setLength(0);
            OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("groupBy"));
            report.setGroupBy(b.toString());
        }
    }
    if (spec.get("parameters") != null) {
        JSONObject parameters = (JSONObject) spec.get("parameters");
        Boolean beginDate = (Boolean) parameters.get("beginDate");
        if (beginDate != null && beginDate) {
            report.getParamater().add("beginDate");
        }
        Boolean endDate = (Boolean) parameters.get("endDate");
        if (endDate != null && endDate) {
            report.getParamater().add("endDate");
        }
        Boolean userKey = (Boolean) parameters.get("userKey");
        if (userKey != null && userKey) {
            report.getParamater().add("userKey");
        }
        Boolean currentUser = (Boolean) parameters.get("currentUser");
        if (currentUser != null && currentUser) {
            report.getParamater().add("currentUser");
        }
    }
    JSONArray headerFields = (JSONArray) spec.get("headerFields");
    if (headerFields != null) {
        for (Object o : headerFields) {
            report.getHeaderFields().add((String) o);
        }
    }
    JSONArray dataFields = (JSONArray) spec.get("dataFields");
    if (dataFields != null) {
        for (Object o : dataFields) {
            report.getDataFields().add((String) o);
        }
    }
    synchronized (this.cfgMgr.getCfg().getProvisioning().getReports()) {
        ReportType existingRep = null;
        for (ReportType rt : this.cfgMgr.getCfg().getProvisioning().getReports().getReport()) {
            if (rt.getName().equals(report.getName())) {
                existingRep = rt;
                break;
            }
        }
        if (existingRep != null) {
            this.cfgMgr.getCfg().getProvisioning().getReports().getReport().remove(existingRep);
        }
        this.cfgMgr.getCfg().getProvisioning().getReports().getReport().add(report);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) ReportType(com.tremolosecurity.config.xml.ReportType)

Aggregations

ReportType (com.tremolosecurity.config.xml.ReportType)6 OrgType (com.tremolosecurity.config.xml.OrgType)3 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)3 AzSys (com.tremolosecurity.proxy.auth.AzSys)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 Gson (com.google.gson.Gson)2 ReportsType (com.tremolosecurity.config.xml.ReportsType)2 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)2 ProvisioningError (com.tremolosecurity.provisioning.service.util.ProvisioningError)2 ProvisioningResult (com.tremolosecurity.provisioning.service.util.ProvisioningResult)2 ReportInformation (com.tremolosecurity.provisioning.service.util.ReportInformation)2 ReportsList (com.tremolosecurity.provisioning.service.util.ReportsList)2 AuthController (com.tremolosecurity.proxy.auth.AuthController)2 ScaleError (com.tremolosecurity.scalejs.data.ScaleError)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 ServletException (javax.servlet.ServletException)2 RichTextString (org.apache.poi.ss.usermodel.RichTextString)2 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)2