use of com.tremolosecurity.scalejs.operators.config.AttributeConfig in project OpenUnison by TremoloSecurity.
the class ScaleJSOperator method initFilter.
@Override
public void initFilter(HttpFilterConfig config) throws Exception {
this.config = new OperatorsConfig();
Attribute bases = config.getAttribute("bases");
if (bases == null) {
throw new Exception("bases not set");
}
for (String base : bases.getValues()) {
String desc = base.substring(0, base.indexOf('='));
String ldap = base.substring(base.indexOf('=') + 1);
this.config.getBaseLabelToDN().put(desc, ldap);
this.config.getSearchBases().add(desc);
}
Attribute attr = config.getAttribute("searchableAttributes");
if (attr == null) {
throw new Exception("searchableAttributes not found");
}
for (String searchable : attr.getValues()) {
String name = searchable.substring(0, searchable.indexOf('='));
String label = searchable.substring(searchable.indexOf('=') + 1);
this.config.getSearchableAttributes().add(new AttributeConfig(name, label, ""));
}
attr = config.getAttribute("resultAttributes");
if (attr == null) {
throw new Exception("resultAttributes not found");
}
for (String resultAttr : attr.getValues()) {
String name = resultAttr.substring(0, resultAttr.indexOf('='));
String label = resultAttr.substring(resultAttr.indexOf('=') + 1);
this.config.getResultsAttributes().add(new AttributeConfig(name, label, ""));
}
this.config.setScaleJsMainUri(this.loadAttributeValue("scaleMainURI", "Scale Main URI", config));
this.config.setHomeUrl(this.loadAttributeValue("homeUrl", "Home URL", config));
this.scalejsAppName = this.loadAttributeValue("scaleMainAppName", "Scale Main Application", config);
ApplicationType app = null;
for (ApplicationType at : config.getConfigManager().getCfg().getApplications().getApplication()) {
if (at.getName().equalsIgnoreCase(scalejsAppName)) {
app = at;
}
}
if (app == null) {
throw new Exception(scalejsAppName + " does not exist");
}
for (UrlType url : app.getUrls().getUrl()) {
if (url.getUri().equalsIgnoreCase(this.config.getScaleJsMainUri())) {
this.scaleJsUrl = url;
}
}
if (this.scaleJsUrl == null) {
throw new Exception("Could not find url for ScaleJS Main");
}
this.scaleMainURL = "https://" + this.scaleJsUrl.getHost().get(0) + this.scaleJsUrl.getUri();
HashMap<String, Attribute> decCfg = new HashMap<String, Attribute>();
for (FilterConfigType filter : this.scaleJsUrl.getFilterChain().getFilter()) {
if (filter.getClazz().equalsIgnoreCase("com.tremolosecurity.scalejs.ws.ScaleMain")) {
for (ParamWithValueType pt : filter.getParam()) {
if (pt.getName().equalsIgnoreCase("uiHelperClassName")) {
this.dec = (UiDecisions) Class.forName(pt.getValue()).newInstance();
} else if (pt.getName().equalsIgnoreCase("uihelper.params")) {
String v = pt.getValue();
String name = v.substring(0, v.indexOf('='));
String value = v.substring(v.indexOf('=') + 1);
Attribute param = decCfg.get(name);
if (param == null) {
param = new Attribute(name);
decCfg.put(name, param);
}
param.getValues().add(value);
}
}
}
}
if (this.dec != null) {
this.dec.init(decCfg);
}
}
use of com.tremolosecurity.scalejs.operators.config.AttributeConfig 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