Search in sources :

Example 1 with ReportsList

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

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

OrgType (com.tremolosecurity.config.xml.OrgType)2 ReportType (com.tremolosecurity.config.xml.ReportType)2 ReportsType (com.tremolosecurity.config.xml.ReportsType)2 ReportInformation (com.tremolosecurity.provisioning.service.util.ReportInformation)2 ReportsList (com.tremolosecurity.provisioning.service.util.ReportsList)2 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)2 AzSys (com.tremolosecurity.proxy.auth.AzSys)2 HashSet (java.util.HashSet)2 Gson (com.google.gson.Gson)1 LDAPAttribute (com.novell.ldap.LDAPAttribute)1 LDAPAttributeSet (com.novell.ldap.LDAPAttributeSet)1 LDAPEntry (com.novell.ldap.LDAPEntry)1 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)1 ConfigManager (com.tremolosecurity.config.util.ConfigManager)1 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 ProvisioningError (com.tremolosecurity.provisioning.service.util.ProvisioningError)1 ProvisioningResult (com.tremolosecurity.provisioning.service.util.ProvisioningResult)1 AuthController (com.tremolosecurity.proxy.auth.AuthController)1 Attribute (com.tremolosecurity.saml.Attribute)1 ScaleError (com.tremolosecurity.scalejs.data.ScaleError)1