Search in sources :

Example 1 with OperatorsConfig

use of com.tremolosecurity.scalejs.operators.config.OperatorsConfig 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)

Aggregations

LDAPAttribute (com.novell.ldap.LDAPAttribute)1 LDAPException (com.novell.ldap.LDAPException)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 AttributeConfig (com.tremolosecurity.scalejs.operators.config.AttributeConfig)1 OperatorsConfig (com.tremolosecurity.scalejs.operators.config.OperatorsConfig)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1