Search in sources :

Example 11 with Attribute

use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.

the class JavaScriptRegister method init.

@Override
public void init(ScaleJSRegisterConfig registerConfig) throws ProvisioningException {
    initCompleted = false;
    Context context = Context.newBuilder("js").allowAllAccess(true).build();
    globals = new HashMap<String, Object>();
    context.getBindings("js").putMember("globals", globals);
    try {
        Attribute attr = registerConfig.getCustomSubmissionConfig().get("javaScript");
        if (attr == null) {
            logger.error("javaScript not set");
            return;
        }
        this.javaScript = attr.getValues().get(0);
        globals = new HashMap<String, Object>();
        context.getBindings("js").putMember("globals", globals);
        Value val = context.eval("js", this.javaScript);
        Value init = context.getBindings("js").getMember("init");
        if (init == null || !init.canExecute()) {
            throw new ProvisioningException("init function must be defined with one paramter");
        }
        Value doFilter = context.getBindings("js").getMember("createTremoloUser");
        if (doFilter == null || !doFilter.canExecute()) {
            throw new ProvisioningException("createTremoloUser function must be defined with three paramters");
        }
        doFilter = context.getBindings("js").getMember("setWorkflowParameters");
        if (doFilter == null || !doFilter.canExecute()) {
            throw new ProvisioningException("setWorkflowParameters function must be defined with three paramters");
        }
        init.executeVoid(registerConfig);
        initCompleted = true;
    } catch (Throwable t) {
        logger.error("Could not initialize javascript filter", t);
        return;
    } finally {
        if (context != null) {
            context.close();
        }
    }
}
Also used : Context(org.graalvm.polyglot.Context) Attribute(com.tremolosecurity.saml.Attribute) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Value(org.graalvm.polyglot.Value)

Example 12 with Attribute

use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.

the class ScaleRegister method initFilter.

@Override
public void initFilter(HttpFilterConfig config) throws Exception {
    this.scaleConfig = new ScaleJSRegisterConfig();
    scaleConfig.getFrontPage().setTitle(this.loadAttributeValue("frontPage.title", "Front Page Title", config));
    scaleConfig.getFrontPage().setText(this.loadAttributeValue("frontPage.text", "Front Page Text", config));
    scaleConfig.setHomeURL(this.loadAttributeValue("homeURL", "Home URL", config));
    scaleConfig.setLogoutURL(this.loadAttributeValue("logoutURL", "Logout URL", config));
    scaleConfig.setUidAttributeName(this.loadAttributeValue("uidAttributeName", "UID Attribute Name", config));
    scaleConfig.setWorkflowName(this.loadAttributeValue("workflowName", "Workflow Name", config));
    String val = this.loadOptionalAttributeValue("requireReason", "Require Reason", config);
    scaleConfig.setRequireReason(val != null && val.equals("true"));
    val = this.loadOptionalAttributeValue("preSetPassword", "Pre-Set Password", config);
    scaleConfig.setPreSetPassword(val != null && val.equals("true"));
    Attribute attr = config.getAttribute("attributeNames");
    if (attr == null) {
        throw new Exception("Attribute names not found");
    }
    val = this.loadOptionalAttributeValue("requireReCaptcha", "ReCaptcha Required", config);
    if (val == null) {
        val = "false";
    }
    scaleConfig.setRequireReCaptcha(val.equalsIgnoreCase("true"));
    if (scaleConfig.isRequireReCaptcha()) {
        scaleConfig.setRcSiteKey(this.loadAttributeValue("rcSiteKey", "ReCaptcha Site Key", config));
        scaleConfig.setRcSecretKey(this.loadAttributeValue("rcSecret", "ReCaptcha Secret Key", config));
    }
    val = this.loadOptionalAttributeValue("submitButtonText", "submitButtonText", config);
    if (val == null) {
        val = "Submit Registration";
    }
    scaleConfig.setSubmitButtonText(val);
    val = this.loadOptionalAttributeValue("submittedText", "submittedText", config);
    if (val == null) {
        val = "Thank you for registering, your request has been submitted and you will be notified once approved";
    }
    scaleConfig.setSubmittedText(val);
    val = this.loadOptionalAttributeValue("reasonIsList", "reasonIsList", config);
    if (val == null) {
        val = "false";
    }
    scaleConfig.setReasonIsList(val.equalsIgnoreCase("true"));
    if (scaleConfig.isReasonIsList()) {
        Attribute reasons = config.getAttribute("reasons");
        if (reasons != null) {
            scaleConfig.getReasons().addAll(reasons.getValues());
        }
    }
    val = this.loadOptionalAttributeValue("requireTermsAndConditions", "Require Terms and Conditions", config);
    if (val == null) {
        val = "false";
    }
    scaleConfig.setRequireTermsAndConditions(val.equalsIgnoreCase("true"));
    if (scaleConfig.isRequireTermsAndConditions()) {
        scaleConfig.setTermsAndConditionsText(this.loadAttributeValue("termsAndConditionsText", "Terms and Conditions", config));
    }
    for (String attributeName : attr.getValues()) {
        scaleConfig.getAttributeNameList().add(attributeName);
        ScaleAttribute scaleAttr = new ScaleAttribute();
        scaleAttr.setName(attributeName);
        scaleAttr.setDisplayName(this.loadAttributeValue(attributeName + ".displayName", attributeName + " Display Name", config));
        scaleAttr.setReadOnly(false);
        scaleAttr.setRequired(true);
        val = this.loadOptionalAttributeValue(attributeName + ".required", attributeName + " Required", config);
        if (val != null) {
            scaleAttr.setRequired(val.equalsIgnoreCase("true"));
        }
        val = this.loadOptionalAttributeValue(attributeName + ".regEx", attributeName + " Reg Ex", config);
        if (val != null) {
            scaleAttr.setRegEx(val);
        }
        val = this.loadOptionalAttributeValue(attributeName + ".regExFailedMsg", attributeName + " Reg Ex Failed Message", config);
        if (val != null) {
            scaleAttr.setRegExFailedMsg(val);
        }
        val = this.loadOptionalAttributeValue(attributeName + ".minChars", attributeName + " Minimum Characters", config);
        if (val != null) {
            scaleAttr.setMinChars(Integer.parseInt(val));
        }
        val = this.loadOptionalAttributeValue(attributeName + ".maxChars", attributeName + " Maximum Characters", config);
        if (val != null) {
            scaleAttr.setMaxChars(Integer.parseInt(val));
        }
        val = this.loadOptionalAttributeValue(attributeName + ".unique", attributeName + " Attribute Value Must Be Unique", config);
        if (val != null) {
            scaleAttr.setUnique(val.equalsIgnoreCase("true"));
        }
        val = this.loadOptionalAttributeValue(attributeName + ".type", attributeName + " Attribute Type", config);
        if (val != null) {
            scaleAttr.setType(val);
        }
        Attribute attrVals = config.getAttribute(attributeName + ".values");
        if (attrVals != null) {
            for (String attrVal : attrVals.getValues()) {
                String valLabel = attrVal.substring(0, attrVal.indexOf('='));
                String valValue = attrVal.substring(attrVal.indexOf('=') + 1);
                scaleAttr.getValues().add(new NVP(valLabel, valValue));
            }
        }
        if (config.getAttribute(attributeName + ".dynamicValueSource.className") != null && config.getAttribute(attributeName + ".dynamicValueSource.className").getValues() != null && config.getAttribute(attributeName + ".dynamicValueSource.className").getValues().size() != 0 && config.getAttribute(attributeName + ".dynamicValueSource.className").getValues().get(0) != null && !config.getAttribute(attributeName + ".dynamicValueSource.className").getValues().get(0).equalsIgnoreCase("")) {
            String className = config.getAttribute(attributeName + ".dynamicValueSource.className").getValues().get(0);
            scaleAttr.setDynamicSourceClassName(className);
            Attribute cfgOptions = config.getAttribute(attributeName + ".dynamicValueSource.config");
            Map<String, Attribute> dynConfig = new HashMap<String, Attribute>();
            if (cfgOptions != null) {
                for (String attrVal : cfgOptions.getValues()) {
                    String valLabel = attrVal.substring(0, attrVal.indexOf('='));
                    String valValue = attrVal.substring(attrVal.indexOf('=') + 1);
                    Attribute cfgattr = dynConfig.get(valLabel);
                    if (cfgattr == null) {
                        cfgattr = new Attribute(valLabel);
                        dynConfig.put(valLabel, cfgattr);
                    }
                    cfgattr.getValues().add(valValue);
                    Attribute dcfgattr = scaleAttr.getDynamicSourceConfig().get(valLabel);
                    if (dcfgattr == null) {
                        dcfgattr = new Attribute(valLabel);
                        scaleAttr.getDynamicSourceConfig().put(valLabel, dcfgattr);
                    }
                    dcfgattr.getValues().add(valValue);
                }
            }
            scaleAttr.setDynamicSource((SourceList) Class.forName(className).newInstance());
            scaleAttr.getDynamicSource().init(scaleAttr, dynConfig);
        }
        val = this.loadOptionalAttributeValue(attributeName + ".editJavaScriptFunction", "editJavaScriptFunction", config);
        if (val != null) {
            scaleAttr.setEditJavaScriptFunction(val);
        }
        val = this.loadOptionalAttributeValue(attributeName + ".show", "show", config);
        if (val != null) {
            scaleAttr.setShow(val.equalsIgnoreCase("true"));
        } else {
            scaleAttr.setShow(true);
        }
        scaleConfig.getAttributes().put(attributeName, scaleAttr);
    }
    val = loadOptionalAttributeValue("useCallWorkflowClass", "Use Custom Submission", config);
    if (val == null) {
        val = "false";
    }
    scaleConfig.setUseCustomSubmission(val.equalsIgnoreCase("true"));
    val = loadOptionalAttributeValue("submitLoggedInUser", "Submit logged in user as subject", config);
    if (val == null) {
        val = "false";
    }
    scaleConfig.setSubmitLoggedInUser(val.equalsIgnoreCase("true"));
    if (scaleConfig.isUseCustomSubmission()) {
        scaleConfig.setCustomSubmissionClassName(this.loadAttributeValue("callWorkflowClassName", "Custom Submission Class", config));
        Attribute tattr = config.getAttribute("callWorkflowInit");
        scaleConfig.setCustomSubmissionConfig(new HashMap<String, Attribute>());
        if (tattr != null) {
            for (String value : tattr.getValues()) {
                String n = value.substring(0, value.indexOf('='));
                String v = value.substring(value.indexOf('=') + 1);
                Attribute tmpa = scaleConfig.getCustomSubmissionConfig().get(n);
                if (tmpa == null) {
                    tmpa = new Attribute(n);
                    scaleConfig.getCustomSubmissionConfig().put(n, tmpa);
                }
                tmpa.getValues().add(v);
            }
        }
        this.cru = (CreateRegisterUser) Class.forName(scaleConfig.getCustomSubmissionClassName()).newInstance();
        this.cru.init(this.scaleConfig);
    }
}
Also used : ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) Attribute(com.tremolosecurity.saml.Attribute) ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) HashMap(java.util.HashMap) ScaleJSRegisterConfig(com.tremolosecurity.scalejs.register.cfg.ScaleJSRegisterConfig) NVP(com.tremolosecurity.util.NVP) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException)

Example 13 with Attribute

use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.

the class ScaleRegister method loadOptionalAttributeValue.

private String loadOptionalAttributeValue(String name, String label, HttpFilterConfig config) throws Exception {
    Attribute attr = config.getAttribute(name);
    if (attr == null) {
        logger.warn(label + " not found");
        return null;
    }
    String val = attr.getValues().get(0);
    logger.info(label + ": '" + val + "'");
    return val;
}
Also used : Attribute(com.tremolosecurity.saml.Attribute) ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute)

Example 14 with Attribute

use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.

the class ScaleRegister method loadAttributeValue.

private String loadAttributeValue(String name, String label, HttpFilterConfig config) throws Exception {
    Attribute attr = config.getAttribute(name);
    if (attr == null) {
        throw new Exception(label + " not found");
    }
    String val = attr.getValues().get(0);
    logger.info(label + ": '" + val + "'");
    return val;
}
Also used : Attribute(com.tremolosecurity.saml.Attribute) ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException)

Example 15 with Attribute

use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.

the class ScaleSingleRequest method loadAttributeValue.

private String loadAttributeValue(String name, String label, HttpFilterConfig config) throws Exception {
    Attribute attr = config.getAttribute(name);
    if (attr == null) {
        throw new Exception(label + " not found");
    }
    String val = attr.getValues().get(0);
    logger.info(label + ": '" + val + "'");
    return val;
}
Also used : Attribute(com.tremolosecurity.saml.Attribute)

Aggregations

Attribute (com.tremolosecurity.saml.Attribute)268 LDAPAttribute (com.novell.ldap.LDAPAttribute)90 HashMap (java.util.HashMap)89 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)87 IOException (java.io.IOException)69 ArrayList (java.util.ArrayList)53 LDAPException (com.novell.ldap.LDAPException)51 ServletException (javax.servlet.ServletException)48 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)46 AuthController (com.tremolosecurity.proxy.auth.AuthController)45 LDAPEntry (com.novell.ldap.LDAPEntry)43 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)43 HttpSession (javax.servlet.http.HttpSession)40 Gson (com.google.gson.Gson)35 User (com.tremolosecurity.provisioning.core.User)33 HttpServletRequest (javax.servlet.http.HttpServletRequest)33 UrlHolder (com.tremolosecurity.config.util.UrlHolder)31 UnsupportedEncodingException (java.io.UnsupportedEncodingException)30 AuthChainType (com.tremolosecurity.config.xml.AuthChainType)28 HashSet (java.util.HashSet)26