Search in sources :

Example 1 with UiDecisions

use of com.tremolosecurity.scalejs.sdk.UiDecisions in project OpenUnison by TremoloSecurity.

the class ScaleMain method initFilter.

@Override
public void initFilter(HttpFilterConfig config) throws Exception {
    this.scaleConfig = new ScaleConfig();
    scaleConfig.setDisplayNameAttribute(this.loadAttributeValue("displayNameAttribute", "Display Name Attribute Name", config));
    scaleConfig.getFrontPage().setTitle(this.loadAttributeValue("frontPage.title", "Front Page Title", config));
    scaleConfig.getFrontPage().setText(this.loadAttributeValue("frontPage.text", "Front Page Text", config));
    scaleConfig.setCanEditUser(this.loadAttributeValue("canEditUser", "User Fields Editable", config).equalsIgnoreCase("true"));
    scaleConfig.setWorkflowName(this.loadAttributeValue("workflowName", "Save User Workflow", config));
    scaleConfig.setUidAttributeName(this.loadAttributeValue("uidAttributeName", "User ID Attribute Name", config));
    scaleConfig.setShowPortalOrgs(this.loadAttributeValue("showPortalOrgs", "Show Portal Orgs", config).equalsIgnoreCase("true"));
    scaleConfig.setLogoutURL(this.loadAttributeValue("logoutURL", "Logout URL", config));
    scaleConfig.setWarnMinutesLeft(Integer.parseInt(this.loadAttributeValue("warnMinutesLeft", "Warn when number of minutes left in the user's session", config)));
    String val = this.loadOptionalAttributeValue("canDelegate", "canDelegate", config);
    if (val == null) {
        val = "NO";
    }
    scaleConfig.setCanDelegate(PreCheckAllowed.valueOf(val.toUpperCase()));
    val = this.loadOptionalAttributeValue("canPreApprove", "canPreApprove", config);
    if (val == null) {
        val = "NO";
    }
    scaleConfig.setCanPreApprove(PreCheckAllowed.valueOf(val.toUpperCase()));
    val = this.loadOptionalAttributeValue("enableApprovals", "enableApprovals", config);
    if (val == null) {
        scaleConfig.setEnableApprovals(true);
    } else {
        scaleConfig.setEnableApprovals(val.equalsIgnoreCase("true"));
    }
    val = this.loadOptionalAttributeValue("roleAttribute", "Role Attribute Name", config);
    this.appType = new ApplicationType();
    this.appType.setAzTimeoutMillis((long) 3000);
    if (val != null) {
        scaleConfig.setRoleAttribute(val);
    }
    Attribute attr = config.getAttribute("attributeNames");
    if (attr == null) {
        throw new Exception("Attribute names not found");
    }
    for (String attributeName : attr.getValues()) {
        ScaleAttribute scaleAttr = new ScaleAttribute();
        scaleAttr.setName(attributeName);
        scaleAttr.setDisplayName(this.loadAttributeValue(attributeName + ".displayName", attributeName + " Display Name", config));
        scaleAttr.setReadOnly(this.loadAttributeValue(attributeName + ".readOnly", attributeName + " Read Only", config).equalsIgnoreCase("true"));
        val = this.loadOptionalAttributeValue(attributeName + ".required", attributeName + " Required", config);
        scaleAttr.setRequired(val != null && 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 + ".mxnChars", attributeName + " Maximum Characters", config);
        if (val != null) {
            scaleAttr.setMaxChars(Integer.parseInt(val));
        }
        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));
            }
        }
        scaleConfig.getAttributes().put(attributeName, scaleAttr);
        scaleConfig.getUserAttributeList().add(attributeName);
    }
    if (scaleConfig.isEnableApprovals()) {
        attr = config.getAttribute("approvalAttributeNames");
        if (attr == null) {
            throw new Exception("Approval attribute names not found");
        }
        for (String attributeName : attr.getValues()) {
            ScaleAttribute scaleAttr = new ScaleAttribute();
            scaleAttr.setName(attributeName);
            scaleAttr.setDisplayName(this.loadAttributeValue("approvals." + attributeName, "Approvals attribute " + attributeName + " Display Name", config));
            scaleConfig.getApprovalAttributes().put(attributeName, scaleAttr);
        }
        val = this.loadOptionalAttributeValue("uiHelperClassName", "UI Helper Class Name", config);
        if (val != null && !val.isEmpty()) {
            UiDecisions dec = (UiDecisions) Class.forName(val).newInstance();
            attr = config.getAttribute("uihelper.params");
            HashMap<String, Attribute> decCfg = new HashMap<String, Attribute>();
            if (attr != null) {
                for (String v : attr.getValues()) {
                    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);
                }
            }
            dec.init(decCfg);
            scaleConfig.setUiDecisions(dec);
        }
        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());
            }
        }
    }
}
Also used : ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) ApplicationType(com.tremolosecurity.config.xml.ApplicationType) Attribute(com.tremolosecurity.saml.Attribute) LDAPAttribute(com.novell.ldap.LDAPAttribute) ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) HashMap(java.util.HashMap) NVP(com.tremolosecurity.util.NVP) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) UiDecisions(com.tremolosecurity.scalejs.sdk.UiDecisions) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPException(com.novell.ldap.LDAPException) SQLException(java.sql.SQLException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) ScaleConfig(com.tremolosecurity.scalejs.cfg.ScaleConfig)

Aggregations

LDAPAttribute (com.novell.ldap.LDAPAttribute)1 LDAPException (com.novell.ldap.LDAPException)1 ApplicationType (com.tremolosecurity.config.xml.ApplicationType)1 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 Attribute (com.tremolosecurity.saml.Attribute)1 ScaleAttribute (com.tremolosecurity.scalejs.cfg.ScaleAttribute)1 ScaleConfig (com.tremolosecurity.scalejs.cfg.ScaleConfig)1 UiDecisions (com.tremolosecurity.scalejs.sdk.UiDecisions)1 NVP (com.tremolosecurity.util.NVP)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 RichTextString (org.apache.poi.ss.usermodel.RichTextString)1 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)1