use of com.tremolosecurity.provisioning.service.util.ProvisioningError in project OpenUnison by TremoloSecurity.
the class ExecuteWorkflow method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Gson gson = new Gson();
String wfcall = req.getParameter("wfcall");
if (wfcall == null) {
logger.error("Could not get workflow call");
resp.setStatus(500);
ProvisioningError pe = new ProvisioningError();
ProvisioningResult pres = new ProvisioningResult();
pres.setSuccess(false);
pres.setError(pe);
pe.setError("Could not get workflow call");
gson = new Gson();
resp.getOutputStream().print(gson.toJson(pres));
return;
}
String line;
StringBuffer json = new StringBuffer();
BufferedReader in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(wfcall.getBytes("UTF-8"))));
while ((line = in.readLine()) != null) {
json.append(line).append('\n');
}
WFCall wfCall = gson.fromJson(json.toString(), WFCall.class);
if (wfCall == null) {
logger.error("Could not get workflow call");
resp.setStatus(500);
ProvisioningError pe = new ProvisioningError();
pe.setError("Could not get workflow call");
ProvisioningResult pres = new ProvisioningResult();
pres.setSuccess(false);
pres.setError(pe);
gson = new Gson();
resp.getOutputStream().print(gson.toJson(pres));
return;
}
List<ApprovalData> autoApprovals = null;
try {
// TremoloContext.getContext().getConfigManager("proxy").getProvisioningEngine().getWorkFlow(wfCall.getName()).executeWorkflow(wfCall);
com.tremolosecurity.provisioning.workflow.ExecuteWorkflow exec = new com.tremolosecurity.provisioning.workflow.ExecuteWorkflow();
exec.execute(wfCall, GlobalEntries.getGlobalEntries().getConfigManager());
ProvisioningResult res = new ProvisioningResult();
res.setSuccess(true);
resp.getOutputStream().print(gson.toJson(res));
} catch (Throwable t) {
logger.error("Error executing workflow", t);
resp.setStatus(500);
ProvisioningError pe = new ProvisioningError();
pe.setError("Error executing workflow");
ProvisioningResult pres = new ProvisioningResult();
pres.setSuccess(false);
pres.setError(pe);
gson = new Gson();
resp.getOutputStream().print(gson.toJson(pres));
}
}
use of com.tremolosecurity.provisioning.service.util.ProvisioningError in project OpenUnison by TremoloSecurity.
the class ExecutedWorkflows method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userKey = req.getParameter("user");
Session session = null;
try {
session = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getHibernateSessionFactory().openSession();
// PreparedStatement ps = con.prepareStatement("select workflows.id,workflows.name from workflows inner join users on users.id=workflows.userid where workflows.completeTS IS NOT NULL AND userKey=?");
Query query = session.createQuery("FROM Workflows WHERE Workflows.completeTS IS NOT NULL AND Workflows.users.userKey = :user_key");
query.setParameter("user_key", userKey);
List<com.tremolosecurity.provisioning.objects.Workflows> workflows = query.list();
ArrayList<String> workflowids = new ArrayList<String>();
for (Workflows wf : workflows) {
if (wf.getApprovals().isEmpty()) {
workflowids.add(wf.getName());
} else {
boolean approved = true;
for (Approvals approval : wf.getApprovals()) {
approved = approved && (approval.getApproved() == 1 && approval.getApprovedTs() != null);
}
}
}
Gson gson = new Gson();
ProvisioningResult resObj = new ProvisioningResult();
resObj.setSuccess(true);
resObj.setWorkflowIds(workflowids);
resp.getOutputStream().println(gson.toJson(resObj));
} catch (Exception e) {
ProvisioningError pe = new ProvisioningError();
pe.setError("Could not load executed workflows : " + e.getMessage());
ProvisioningResult res = new ProvisioningResult();
res.setSuccess(false);
res.setError(pe);
Gson gson = new Gson();
resp.getWriter().write(gson.toJson(res));
} finally {
if (session != null) {
session.close();
}
}
}
use of com.tremolosecurity.provisioning.service.util.ProvisioningError 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));
}
}
use of com.tremolosecurity.provisioning.service.util.ProvisioningError 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.ProvisioningError 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);
}
}
Aggregations