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);
}
}
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);
}
}
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());
}
}
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);
}
}
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();
}
}
}
Aggregations