Search in sources :

Example 1 with AttributeConfig

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);
    }
}
Also used : ApplicationType(com.tremolosecurity.config.xml.ApplicationType) LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) HashMap(java.util.HashMap) FilterConfigType(com.tremolosecurity.config.xml.FilterConfigType) OperatorsConfig(com.tremolosecurity.scalejs.operators.config.OperatorsConfig) ParamWithValueType(com.tremolosecurity.config.xml.ParamWithValueType) AttributeConfig(com.tremolosecurity.scalejs.operators.config.AttributeConfig) UrlType(com.tremolosecurity.config.xml.UrlType) LDAPException(com.novell.ldap.LDAPException) IOException(java.io.IOException)

Example 2 with AttributeConfig

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LDAPException(com.novell.ldap.LDAPException) IOException(java.io.IOException) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) FilterBuilder(org.apache.directory.ldap.client.api.search.FilterBuilder) OpsSearch(com.tremolosecurity.scalejs.operators.data.OpsSearch) AttributeConfig(com.tremolosecurity.scalejs.operators.config.AttributeConfig)

Aggregations

LDAPException (com.novell.ldap.LDAPException)2 AttributeConfig (com.tremolosecurity.scalejs.operators.config.AttributeConfig)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LDAPAttribute (com.novell.ldap.LDAPAttribute)1 LDAPEntry (com.novell.ldap.LDAPEntry)1 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)1 ApplicationType (com.tremolosecurity.config.xml.ApplicationType)1 FilterConfigType (com.tremolosecurity.config.xml.FilterConfigType)1 ParamWithValueType (com.tremolosecurity.config.xml.ParamWithValueType)1 UrlType (com.tremolosecurity.config.xml.UrlType)1 Attribute (com.tremolosecurity.saml.Attribute)1 OperatorsConfig (com.tremolosecurity.scalejs.operators.config.OperatorsConfig)1 OpsSearch (com.tremolosecurity.scalejs.operators.data.OpsSearch)1 ArrayList (java.util.ArrayList)1 FilterBuilder (org.apache.directory.ldap.client.api.search.FilterBuilder)1