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