use of com.tremolosecurity.provisioning.service.util.ProvisioningResult in project OpenUnison by TremoloSecurity.
the class ListWorkflows method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
String uuid = req.getParameter("uuid");
ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager();
List<WorkflowType> wfs = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getWorkflows().getWorkflow();
ArrayList<WFDescription> workflows = new ArrayList<WFDescription>();
for (WorkflowType wf : wfs) {
if (wf.isInList() != null && wf.isInList().booleanValue()) {
if (wf.getOrgid() == null || wf.getOrgid().equalsIgnoreCase(uuid)) {
if (wf.getDynamicConfiguration() != null && wf.getDynamicConfiguration().isDynamic()) {
HashMap<String, Attribute> params = new HashMap<String, Attribute>();
if (wf.getDynamicConfiguration().getParam() != null) {
for (ParamType p : wf.getDynamicConfiguration().getParam()) {
Attribute attr = params.get(p.getName());
if (attr == null) {
attr = new Attribute(p.getName());
params.put(p.getName(), attr);
}
attr.getValues().add(p.getValue());
}
}
DynamicWorkflow dwf = (DynamicWorkflow) Class.forName(wf.getDynamicConfiguration().getClassName()).newInstance();
List<Map<String, String>> wfParams = dwf.generateWorkflows(wf, GlobalEntries.getGlobalEntries().getConfigManager(), params);
StringBuffer b = new StringBuffer();
b.append('/').append(URLEncoder.encode(wf.getName(), "UTF-8"));
String uri = b.toString();
for (Map<String, String> wfParamSet : wfParams) {
DateTime now = new DateTime();
DateTime expires = now.plusHours(1);
LastMile lm = new LastMile(uri, now, expires, 0, "");
for (String key : wfParamSet.keySet()) {
String val = wfParamSet.get(key);
Attribute attr = new Attribute(key, val);
lm.getAttributes().add(attr);
}
WFDescription desc = new WFDescription();
desc.setUuid(UUID.randomUUID().toString());
desc.setName(wf.getName());
ST st = new ST(wf.getLabel(), '$', '$');
for (String key : wfParamSet.keySet()) {
st.add(key.replaceAll("[.]", "_"), wfParamSet.get(key));
}
desc.setLabel(st.render());
st = new ST(wf.getDescription(), '$', '$');
for (String key : wfParamSet.keySet()) {
st.add(key.replaceAll("[.]", "_"), wfParamSet.get(key));
}
desc.setDescription(st.render());
desc.setEncryptedParams(lm.generateLastMileToken(cfgMgr.getSecretKey(cfgMgr.getCfg().getProvisioning().getApprovalDB().getEncryptionKey())));
workflows.add(desc);
}
} else {
WFDescription desc = new WFDescription();
desc.setUuid(UUID.randomUUID().toString());
desc.setName(wf.getName());
desc.setLabel(wf.getLabel());
desc.setDescription(wf.getDescription());
workflows.add(desc);
}
}
}
}
WFDescriptions descs = new WFDescriptions();
descs.setWorkflows(workflows);
Gson gson = new Gson();
ProvisioningResult pres = new ProvisioningResult();
pres.setSuccess(true);
pres.setWfDescriptions(descs);
resp.getOutputStream().print(gson.toJson(pres));
} catch (Exception e) {
logger.error("Could not load workflows", e);
Gson gson = new Gson();
ProvisioningResult pres = new ProvisioningResult();
pres.setSuccess(false);
pres.setError(new ProvisioningError("Could not load workflows"));
resp.getOutputStream().print(gson.toJson(pres));
}
}
use of com.tremolosecurity.provisioning.service.util.ProvisioningResult in project OpenUnison by TremoloSecurity.
the class Login method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
ProvisioningResult res = new ProvisioningResult();
res.setSuccess(true);
Gson gson = new Gson();
resp.setContentType("text/json");
resp.getWriter().write(gson.toJson(res));
}
use of com.tremolosecurity.provisioning.service.util.ProvisioningResult in project OpenUnison by TremoloSecurity.
the class SearchService method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/json");
try {
String filter = "";
String base = "";
int scope = 0;
if (req.getParameter("uid") != null) {
StringBuffer sfilter = new StringBuffer();
sfilter.append("(uid=").append(req.getParameter("uid")).append(')');
if (logger.isDebugEnabled()) {
logger.debug("UID Filter : '" + sfilter.toString() + "'");
}
filter = sfilter.toString();
base = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot();
scope = 2;
} else if (req.getParameter("dn") != null) {
filter = "(objectClass=*)";
base = req.getParameter("dn");
if (logger.isDebugEnabled()) {
logger.debug("Base DN : '" + base + "'");
}
scope = 0;
} else if (req.getParameter("filter") != null) {
filter = req.getParameter("filter");
if (logger.isDebugEnabled()) {
logger.debug("Filter : '" + filter + "'");
}
base = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot();
scope = 2;
}
ArrayList<String> attrs = new ArrayList<String>();
String[] attrNames = req.getParameterValues("attr");
boolean uidFound = false;
if (attrNames != null) {
for (String attrName : attrNames) {
if (attrName.equalsIgnoreCase("uid")) {
uidFound = true;
}
attrs.add(attrName);
}
if (!uidFound) {
attrs.add("uid");
}
}
MyVDConnection con = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD();
LDAPSearchResults res = con.search(base, scope, filter, attrs);
if (!res.hasMore()) {
ProvisioningException ex = new ProvisioningException("User not found");
ex.setPrintStackTrace(false);
throw ex;
}
LDAPEntry entry = res.next();
TremoloUser user = new TremoloUser();
user.setDn(entry.getDN());
int lq = entry.getDN().lastIndexOf(',');
int fq = entry.getDN().lastIndexOf('=', lq - 1) + 1;
user.setDirectory(entry.getDN().substring(fq, lq));
for (Object attr : entry.getAttributeSet()) {
LDAPAttribute attribute = (LDAPAttribute) attr;
Attribute usrAttr = new Attribute(attribute.getName());
if (attribute.getName().equalsIgnoreCase("uid")) {
user.setUid(attribute.getStringValue());
if (!uidFound && attrs.size() > 1) {
continue;
}
}
for (String val : attribute.getStringValueArray()) {
usrAttr.getValues().add(val);
}
user.getAttributes().add(usrAttr);
}
while (res.hasMore()) res.next();
ArrayList<String> reqAttrs = new ArrayList<String>();
reqAttrs.add("cn");
StringBuffer b = new StringBuffer();
b.append("(").append(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute()).append(")=").append(user.getDn()).append(")");
res = con.search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(), user.getDn()).toString(), reqAttrs);
while (res.hasMore()) {
entry = res.next();
LDAPAttribute groups = entry.getAttribute("cn");
for (String val : groups.getStringValueArray()) {
user.getGroups().add(val);
}
}
ProvisioningResult resObj = new ProvisioningResult();
resObj.setSuccess(true);
resObj.setUser(user);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
// System.out.println(gson.toJson(user));
resp.getWriter().print(gson.toJson(resObj));
} catch (ProvisioningException pe) {
if (pe.isPrintStackTrace()) {
logger.error("Error searching for a user", pe);
} else {
logger.warn(pe.toString());
}
resp.setStatus(500);
ProvisioningError pre = new ProvisioningError();
pre.setError(pe.toString());
ProvisioningResult resObj = new ProvisioningResult();
resObj.setSuccess(false);
resObj.setError(pre);
Gson gson = new Gson();
resp.getOutputStream().print(gson.toJson(resObj));
} catch (Throwable t) {
logger.error("Error searching", t);
resp.setStatus(500);
ProvisioningError pe = new ProvisioningError();
pe.setError(t.toString());
ProvisioningResult resObj = new ProvisioningResult();
resObj.setSuccess(false);
resObj.setError(pe);
Gson gson = new Gson();
resp.getOutputStream().print(gson.toJson(resObj));
}
}
use of com.tremolosecurity.provisioning.service.util.ProvisioningResult in project OpenUnison by TremoloSecurity.
the class ExecuteApproval method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
int approvalID = Integer.parseInt(req.getParameter("approvalID"));
String approver = req.getParameter("approver");
boolean approved = Boolean.parseBoolean(req.getParameter("approved"));
String reason = req.getParameter("reason");
Gson gson = new Gson();
try {
GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().doApproval(approvalID, approver, approved, reason);
ProvisioningResult res = new ProvisioningResult();
res.setSuccess(true);
resp.getOutputStream().print(gson.toJson(res));
} catch (ProvisioningException e) {
logger.error("Could not execute approval", e);
resp.setStatus(500);
ProvisioningError pe = new ProvisioningError();
pe.setError("Could not execute approval;" + e.getMessage());
ProvisioningResult resObj = new ProvisioningResult();
resObj.setSuccess(false);
resObj.setError(pe);
gson = new Gson();
resp.getOutputStream().print(gson.toJson(resObj));
}
}
Aggregations