Search in sources :

Example 1 with OrgType

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

the class ListOrgs method copyOrg.

private void copyOrg(Organization org, OrgType ot, AzSys az, AuthInfo auinfo) throws MalformedURLException, ProvisioningException {
    ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager();
    if (ot.getAzRules() != null && ot.getAzRules().getRule().size() > 0) {
        ArrayList<AzRule> rules = new ArrayList<AzRule>();
        for (AzRuleType art : ot.getAzRules().getRule()) {
            rules.add(new AzRule(art.getScope(), art.getConstraint(), art.getClassName(), cfgMgr, null));
        }
        if (!az.checkRules(auinfo, cfgMgr, rules, null)) {
            return;
        }
    }
    org.setId(ot.getUuid());
    org.setName(ot.getName());
    org.setDescription(ot.getDescription());
    for (OrgType child : ot.getOrgs()) {
        Organization sub = new Organization();
        org.getSubOrgs().add(sub);
        copyOrg(sub, child, az, auinfo);
    }
}
Also used : AzRuleType(com.tremolosecurity.config.xml.AzRuleType) Organization(com.tremolosecurity.provisioning.service.util.Organization) OrgType(com.tremolosecurity.config.xml.OrgType) ArrayList(java.util.ArrayList) AzRule(com.tremolosecurity.proxy.az.AzRule) ConfigManager(com.tremolosecurity.config.util.ConfigManager)

Example 2 with OrgType

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

the class ListReports method checkOrg.

private void checkOrg(HashSet<String> allowedOrgs, OrgType ot, AzSys az, AuthInfo auinfo) throws MalformedURLException, ProvisioningException {
    ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager();
    if (ot.getAzRules() != null && ot.getAzRules().getRule().size() > 0) {
        ArrayList<AzRule> rules = new ArrayList<AzRule>();
        for (AzRuleType art : ot.getAzRules().getRule()) {
            rules.add(new AzRule(art.getScope(), art.getConstraint(), art.getClassName(), cfgMgr, null));
        }
        if (!az.checkRules(auinfo, cfgMgr, rules, null)) {
            return;
        }
    }
    allowedOrgs.add(ot.getUuid());
    for (OrgType child : ot.getOrgs()) {
        checkOrg(allowedOrgs, child, az, auinfo);
    }
}
Also used : AzRuleType(com.tremolosecurity.config.xml.AzRuleType) OrgType(com.tremolosecurity.config.xml.OrgType) ArrayList(java.util.ArrayList) AzRule(com.tremolosecurity.proxy.az.AzRule) ConfigManager(com.tremolosecurity.config.util.ConfigManager)

Example 3 with OrgType

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

the class OrgTypeHolder method addOrg.

private void addOrg(TremoloType tremolo, Object o) {
    JSONObject trustObj = (JSONObject) o;
    JSONObject metadata = (JSONObject) trustObj.get("metadata");
    JSONObject spec = (JSONObject) trustObj.get("spec");
    logger.info(metadata.get("name"));
    StringBuffer b = new StringBuffer();
    OrgType org = new OrgType();
    String label = (String) spec.get("label");
    if (label == null) {
        org.setName((String) metadata.get("name"));
    } else {
        b.setLength(0);
        OpenUnisonConfigLoader.integrateIncludes(b, label);
        org.setName(b.toString());
    }
    if (spec.get("description") != null) {
        b.setLength(0);
        OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("description"));
        org.setDescription(b.toString());
    }
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("uuid"));
    org.setUuid(b.toString());
    org.setShowInPortal(((Boolean) spec.get("showInPortal")));
    org.setShowInReports(((Boolean) spec.get("showInReports")));
    org.setShowInRequestsAccess(((Boolean) spec.get("showInRequestAccess")));
    org.setAzRules(new AzRulesType());
    String parentId = (String) spec.get("parent");
    JSONArray rules = (JSONArray) spec.get("azRules");
    for (Object orr : rules) {
        JSONObject rule = (JSONObject) orr;
        AzRuleType art = new AzRuleType();
        b.setLength(0);
        OpenUnisonConfigLoader.integrateIncludes(b, (String) rule.get("scope"));
        art.setScope(b.toString());
        b.setLength(0);
        OpenUnisonConfigLoader.integrateIncludes(b, (String) rule.get("constraint"));
        art.setConstraint(b.toString());
        org.getAzRules().getRule().add(art);
    }
    OrgType parent = this.findById(parentId, tremolo.getProvisioning().getOrg());
    if (parent == null) {
        for (String oid : this.orphanes.keySet()) {
            OrgType orphan = this.orphanes.get(oid);
            parent = this.findById(parentId, orphan);
            if (parent != null) {
                break;
            }
        }
    }
    if (parent == null) {
        OrgType oot = new OrgType();
        oot.setUuid(parentId);
        oot.setAzRules(new AzRulesType());
        oot.getOrgs().add(org);
        this.orphanes.put(parentId, oot);
    } else {
        this.deleteOrg(tremolo, org.getUuid());
        parent.getOrgs().add(org);
    }
    if (this.orphanes.containsKey(org.getUuid())) {
        OrgType oot = this.orphanes.remove(org.getUuid());
        org.getOrgs().addAll(oot.getOrgs());
    }
}
Also used : AzRuleType(com.tremolosecurity.config.xml.AzRuleType) JSONObject(org.json.simple.JSONObject) AzRulesType(com.tremolosecurity.config.xml.AzRulesType) OrgType(com.tremolosecurity.config.xml.OrgType) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject)

Example 4 with OrgType

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

the class OrgTypeHolder method deleteOrg.

private void deleteOrg(TremoloType tremolo, String orgId) {
    logger.info("deleting " + orgId);
    OrgTypeHolder oth = new OrgTypeHolder();
    this.findParentByChildId(orgId, tremolo.getProvisioning().getOrg(), oth);
    OrgType parent = oth.parent;
    if (parent == null) {
        for (String oid : this.orphanes.keySet()) {
            OrgType orphan = this.orphanes.get(oid);
            this.findParentByChildId(orgId, orphan, oth);
            if (oth.parent != null) {
                parent = oth.parent;
                break;
            }
        }
    }
    if (parent != null) {
        OrgType ot = this.findById(orgId, parent);
        parent.getOrgs().remove(ot);
        this.orphanes.put(ot.getUuid(), ot);
    }
}
Also used : OrgType(com.tremolosecurity.config.xml.OrgType)

Example 5 with OrgType

use of com.tremolosecurity.config.xml.OrgType 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)

Aggregations

OrgType (com.tremolosecurity.config.xml.OrgType)14 AzRuleType (com.tremolosecurity.config.xml.AzRuleType)7 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)7 AzSys (com.tremolosecurity.proxy.auth.AzSys)7 ArrayList (java.util.ArrayList)7 ConfigManager (com.tremolosecurity.config.util.ConfigManager)6 HashSet (java.util.HashSet)6 AuthController (com.tremolosecurity.proxy.auth.AuthController)5 AzRule (com.tremolosecurity.proxy.az.AzRule)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 LDAPAttribute (com.novell.ldap.LDAPAttribute)4 ReportType (com.tremolosecurity.config.xml.ReportType)4 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)4 Organization (com.tremolosecurity.provisioning.service.util.Organization)4 Attribute (com.tremolosecurity.saml.Attribute)4 ScaleError (com.tremolosecurity.scalejs.data.ScaleError)4 RichTextString (org.apache.poi.ss.usermodel.RichTextString)4 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)4 Gson (com.google.gson.Gson)3