use of com.tremolosecurity.provisioning.service.util.ProvisioningError 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.ProvisioningError 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);
}
}
use of com.tremolosecurity.provisioning.service.util.ProvisioningError 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.ProvisioningError 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.ProvisioningError 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