use of com.tremolosecurity.scalejs.operators.data.OpsSearch in project OpenUnison by TremoloSecurity.
the class ScaleJSOperator method runSearch.
private void runSearch(HttpFilterRequest request, HttpFilterResponse response, Gson gson) throws Exception, LDAPException, IOException {
String json = new String((byte[]) request.getAttribute(ProxySys.MSG_BODY));
OpsSearch opsSearch = gson.fromJson(json, OpsSearch.class);
List<AttributeConfig> forSearch = opsSearch.getToSearch();
List<FilterBuilder> filter = new ArrayList<FilterBuilder>();
for (AttributeConfig attr : forSearch) {
if (attr.isPicked()) {
filter.add(equal(attr.getName(), attr.getValue()));
}
}
FilterBuilder[] fb = new FilterBuilder[filter.size()];
filter.toArray(fb);
FilterBuilder baseFilter = (FilterBuilder) request.getAttribute("ops.search.filter");
String filterString;
if (baseFilter != null) {
FilterBuilder localFilter = and(fb);
filterString = and(localFilter, baseFilter).toString();
} else {
filterString = and(fb).toString();
}
String searchBase = this.config.getBaseLabelToDN().get(opsSearch.getBase());
if (searchBase == null) {
throw new Exception("Invalid search base");
}
List<HashMap<String, String>> resList = new ArrayList<HashMap<String, String>>();
LDAPSearchResults res = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(searchBase, 2, filterString, new ArrayList<String>());
while (res.hasMore()) {
HashMap<String, String> ret = new HashMap<String, String>();
resList.add(ret);
LDAPEntry entry = res.next();
ret.put("dn", entry.getDN());
for (AttributeConfig attr : this.config.getResultsAttributes()) {
if (entry.getAttribute(attr.getName()) != null) {
String val = entry.getAttribute(attr.getName()).getStringValue();
ret.put(attr.getName(), val);
} else {
ret.put(attr.getName(), "");
}
}
}
ScaleJSUtils.addCacheHeaders(response);
response.setContentType("application/json");
response.getWriter().println(gson.toJson(resList).trim());
}
Aggregations