Search in sources :

Example 1 with ScaleAttribute

use of com.tremolosecurity.scalejs.cfg.ScaleAttribute 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 2 with ScaleAttribute

use of com.tremolosecurity.scalejs.cfg.ScaleAttribute 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)

Example 3 with ScaleAttribute

use of com.tremolosecurity.scalejs.cfg.ScaleAttribute in project OpenUnison by TremoloSecurity.

the class ScaleRegister method doFilter.

@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception {
    Gson gson = new Gson();
    request.getServletRequest().setAttribute("com.tremolosecurity.unison.proxy.noRedirectOnError", "com.tremolosecurity.unison.proxy.noRedirectOnError");
    if (request.getRequestURI().endsWith("/register/config")) {
        response.setContentType("application/json");
        ScaleJSUtils.addCacheHeaders(response);
        ScaleJSRegisterConfig localCfg = gson.fromJson(gson.toJson(this.scaleConfig), ScaleJSRegisterConfig.class);
        for (String attrName : scaleConfig.getAttributes().keySet()) {
            ScaleAttribute fromMainCfg = scaleConfig.getAttributes().get(attrName);
            if (fromMainCfg.getDynamicSource() != null) {
                ScaleAttribute fromLocalCfg = localCfg.getAttributes().get(attrName);
                fromLocalCfg.setValues(fromMainCfg.getDynamicSource().getSourceList(request));
            }
        }
        response.getWriter().println(gson.toJson(localCfg).trim());
    } else if (request.getRequestURI().endsWith("/register/values")) {
        String attributeName = request.getParameter("name").getValues().get(0);
        List<NVP> values = this.scaleConfig.getAttributes().get(attributeName).getDynamicSource().getSourceList(request);
        response.setContentType("application/json");
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().println(gson.toJson(values).trim());
    } else if (request.getRequestURI().endsWith("/register/submit")) {
        ScaleError errors = new ScaleError();
        String json = new String((byte[]) request.getAttribute(ProxySys.MSG_BODY));
        NewUserRequest newUser = gson.fromJson(json, NewUserRequest.class);
        if (scaleConfig.isRequireReCaptcha()) {
            if (newUser.getReCaptchaCode() == null || newUser.getReCaptchaCode().isEmpty()) {
                errors.getErrors().add("Please verify you are not a robot");
            } else {
                BasicHttpClientConnectionManager bhcm = new BasicHttpClientConnectionManager(GlobalEntries.getGlobalEntries().getConfigManager().getHttpClientSocketRegistry());
                RequestConfig rc = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
                CloseableHttpClient http = HttpClients.custom().setConnectionManager(bhcm).setDefaultRequestConfig(rc).build();
                HttpPost httppost = new HttpPost("https://www.google.com/recaptcha/api/siteverify");
                List<NameValuePair> formparams = new ArrayList<NameValuePair>();
                formparams.add(new BasicNameValuePair("secret", scaleConfig.getRcSecretKey()));
                formparams.add(new BasicNameValuePair("response", newUser.getReCaptchaCode()));
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
                httppost.setEntity(entity);
                CloseableHttpResponse resp = http.execute(httppost);
                ReCaptchaResponse res = gson.fromJson(EntityUtils.toString(resp.getEntity()), ReCaptchaResponse.class);
                if (!res.isSuccess()) {
                    errors.getErrors().add("Human validation failed");
                }
                http.close();
                bhcm.close();
            }
        }
        if (scaleConfig.isRequireTermsAndConditions() && !newUser.isCheckedTermsAndConditions()) {
            errors.getErrors().add("You must accept the terms and conditions to register");
        }
        if (this.scaleConfig.isRequireReason() && (newUser.getReason() == null || newUser.getReason().isEmpty())) {
            errors.getErrors().add("Reason is required");
        }
        if (this.scaleConfig.isPreSetPassword()) {
            if (newUser.getPassword() == null || newUser.getPassword().isEmpty()) {
                errors.getErrors().add("Password is required");
            } else if (!newUser.getPassword().equals(newUser.getPassword2())) {
                errors.getErrors().add("Passwords must match");
            }
        }
        for (String attributeName : this.scaleConfig.getAttributes().keySet()) {
            String value = newUser.getAttributes().get(attributeName);
            if (this.scaleConfig.getAttributes().get(attributeName) == null) {
                errors.getErrors().add("Invalid attribute : '" + attributeName + "'");
            }
            if (this.scaleConfig.getAttributes().get(attributeName).isReadOnly()) {
                errors.getErrors().add("Attribute is read only : '" + this.scaleConfig.getAttributes().get(attributeName).getDisplayName() + "'");
            }
            if (this.scaleConfig.getAttributes().get(attributeName).isRequired() && (value == null || value.length() == 0)) {
                errors.getErrors().add("Attribute is required : '" + this.scaleConfig.getAttributes().get(attributeName).getDisplayName() + "'");
            }
            if (this.scaleConfig.getAttributes().get(attributeName).getMinChars() > 0 && this.scaleConfig.getAttributes().get(attributeName).getMinChars() > value.length()) {
                errors.getErrors().add(this.scaleConfig.getAttributes().get(attributeName).getDisplayName() + " must have at least " + this.scaleConfig.getAttributes().get(attributeName).getMinChars() + " characters");
            }
            if (this.scaleConfig.getAttributes().get(attributeName).getMaxChars() > 0 && this.scaleConfig.getAttributes().get(attributeName).getMaxChars() < value.length()) {
                errors.getErrors().add(this.scaleConfig.getAttributes().get(attributeName).getDisplayName() + " must have at most " + this.scaleConfig.getAttributes().get(attributeName).getMaxChars() + " characters");
            }
            if (this.scaleConfig.getAttributes().get(attributeName).getType().equalsIgnoreCase("list")) {
                if (this.scaleConfig.getAttributes().get(attributeName).getDynamicSource() == null) {
                    boolean found = false;
                    for (NVP nvp : this.scaleConfig.getAttributes().get(attributeName).getValues()) {
                        if (nvp.getValue().equalsIgnoreCase(value)) {
                            found = true;
                        }
                    }
                    if (!found) {
                        errors.getErrors().add(this.scaleConfig.getAttributes().get(attributeName).getDisplayName() + " has an invalid value");
                    }
                }
            }
            if (this.scaleConfig.getAttributes().get(attributeName).getPattern() != null) {
                boolean ok = true;
                try {
                    Matcher m = this.scaleConfig.getAttributes().get(attributeName).getPattern().matcher(value);
                    if (m == null || !m.matches()) {
                        ok = false;
                    }
                } catch (Exception e) {
                    ok = false;
                }
                if (!ok) {
                    errors.getErrors().add("Attribute value not valid : '" + this.scaleConfig.getAttributes().get(attributeName).getDisplayName() + "' - " + this.scaleConfig.getAttributes().get(attributeName).getRegExFailedMsg());
                }
            }
            if (this.scaleConfig.getAttributes().get(attributeName).isUnique()) {
                String filter = equal(attributeName, value).toString();
                LDAPSearchResults res = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, filter, new ArrayList<String>());
                if (res.hasMore()) {
                    errors.getErrors().add(this.scaleConfig.getAttributes().get(attributeName).getDisplayName() + " is not available");
                }
                while (res.hasMore()) res.next();
            }
            if (this.scaleConfig.getAttributes().get(attributeName).getDynamicSource() != null) {
                String error = this.scaleConfig.getAttributes().get(attributeName).getDynamicSource().validate(value, request);
                if (error != null) {
                    errors.getErrors().add(this.scaleConfig.getAttributes().get(attributeName).getDisplayName() + " - " + error);
                }
            }
        }
        WFCall wfcall = null;
        String wfName = this.scaleConfig.getWorkflowName();
        if (errors.getErrors().isEmpty()) {
            if (scaleConfig.isUseCustomSubmission()) {
                AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
                wfName = cru.createTremoloUser(newUser, errors.getErrors(), userData);
            }
        }
        if (errors.getErrors().isEmpty()) {
            TremoloUser user = new TremoloUser();
            AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
            if (this.scaleConfig.isSubmitLoggedInUser()) {
                user.setUid(userData.getAttribs().get(this.scaleConfig.getUidAttributeName()).getValues().get(0));
                user.getAttributes().add(new Attribute(this.scaleConfig.getUidAttributeName(), userData.getAttribs().get(this.scaleConfig.getUidAttributeName()).getValues().get(0)));
            } else {
                user.setUid(newUser.getAttributes().get(this.scaleConfig.getUidAttributeName()));
            }
            for (String attrName : newUser.getAttributes().keySet()) {
                user.getAttributes().add(new Attribute(attrName, newUser.getAttributes().get(attrName)));
            }
            if (this.scaleConfig.isPreSetPassword()) {
                user.setUserPassword(newUser.getPassword());
            }
            wfcall = new WFCall();
            wfcall.setUidAttributeName(this.scaleConfig.getUidAttributeName());
            wfcall.setReason(newUser.getReason());
            wfcall.setName(wfName);
            wfcall.setUser(user);
            HashMap<String, Object> params = new HashMap<String, Object>();
            wfcall.setRequestParams(params);
            if (userData.getAuthLevel() != 0 && !this.scaleConfig.isSubmitLoggedInUser()) {
                wfcall.setRequestor(userData.getAttribs().get(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getApprovalDB().getUserIdAttribute()).getValues().get(0));
                wfcall.getRequestParams().put(Approval.SEND_NOTIFICATION, "false");
                wfcall.getRequestParams().put(Approval.REASON, newUser.getReason());
                wfcall.getRequestParams().put(Approval.IMMEDIATE_ACTION, "true");
            }
            if (scaleConfig.isUseCustomSubmission()) {
                cru.setWorkflowParameters(params, newUser, userData);
            }
            ExecuteWorkflow exec = new ExecuteWorkflow();
            try {
                exec.execute(wfcall, GlobalEntries.getGlobalEntries().getConfigManager());
            } catch (Exception e) {
                throw new ProvisioningException("Could not complete registration", e);
            }
            SubmitResponse res = new SubmitResponse();
            res.setAddNewUsers(userData.getAuthLevel() != 0);
            ScaleJSUtils.addCacheHeaders(response);
            response.getWriter().print(gson.toJson(res));
            response.getWriter().flush();
        } else {
            response.setStatus(500);
            ScaleJSUtils.addCacheHeaders(response);
            response.getWriter().print(gson.toJson(errors).trim());
            response.getWriter().flush();
        }
    } else {
        response.setStatus(500);
        ScaleJSUtils.addCacheHeaders(response);
        ScaleError error = new ScaleError();
        error.getErrors().add("Operation not supported");
        response.getWriter().print(gson.toJson(error).trim());
        response.getWriter().flush();
    }
}
Also used : ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) HttpPost(org.apache.http.client.methods.HttpPost) Matcher(java.util.regex.Matcher) Attribute(com.tremolosecurity.saml.Attribute) ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) HashMap(java.util.HashMap) ScaleJSRegisterConfig(com.tremolosecurity.scalejs.register.cfg.ScaleJSRegisterConfig) SubmitResponse(com.tremolosecurity.scalejs.register.data.SubmitResponse) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) NVP(com.tremolosecurity.util.NVP) ReCaptchaResponse(com.tremolosecurity.scalejs.register.data.ReCaptchaResponse) TremoloUser(com.tremolosecurity.provisioning.service.util.TremoloUser) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ArrayList(java.util.ArrayList) SourceList(com.tremolosecurity.scalejs.sdk.SourceList) List(java.util.List) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) WFCall(com.tremolosecurity.provisioning.service.util.WFCall) AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) ScaleError(com.tremolosecurity.scalejs.data.ScaleError) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) AuthController(com.tremolosecurity.proxy.auth.AuthController) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) ExecuteWorkflow(com.tremolosecurity.provisioning.workflow.ExecuteWorkflow) NewUserRequest(com.tremolosecurity.scalejs.register.data.NewUserRequest)

Example 4 with ScaleAttribute

use of com.tremolosecurity.scalejs.cfg.ScaleAttribute in project OpenUnison by TremoloSecurity.

the class JavaScriptSource method init.

@Override
public void init(ScaleAttribute attribute, Map<String, Attribute> config) {
    initCompleted = false;
    Context context = Context.newBuilder("js").allowAllAccess(true).build();
    globals = new HashMap<String, Object>();
    context.getBindings("js").putMember("globals", globals);
    try {
        Attribute attr = config.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("initFilter function must be defined with two paramters");
        }
        Value getSourceList = context.getBindings("js").getMember("getSourceList");
        if (getSourceList == null || !getSourceList.canExecute()) {
            throw new ProvisioningException("getSourceList function must be defined with one paramter");
        }
        Value validate = context.getBindings("js").getMember("validate");
        if (validate == null || !validate.canExecute()) {
            throw new ProvisioningException("validate function must be defined with two paramters");
        }
        init.executeVoid(attribute, config);
        context.close();
        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) ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Value(org.graalvm.polyglot.Value)

Aggregations

ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)4 Attribute (com.tremolosecurity.saml.Attribute)4 ScaleAttribute (com.tremolosecurity.scalejs.cfg.ScaleAttribute)4 NVP (com.tremolosecurity.util.NVP)3 HashMap (java.util.HashMap)3 ScaleJSRegisterConfig (com.tremolosecurity.scalejs.register.cfg.ScaleJSRegisterConfig)2 Gson (com.google.gson.Gson)1 LDAPAttribute (com.novell.ldap.LDAPAttribute)1 LDAPException (com.novell.ldap.LDAPException)1 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)1 ApplicationType (com.tremolosecurity.config.xml.ApplicationType)1 TremoloUser (com.tremolosecurity.provisioning.service.util.TremoloUser)1 WFCall (com.tremolosecurity.provisioning.service.util.WFCall)1 ExecuteWorkflow (com.tremolosecurity.provisioning.workflow.ExecuteWorkflow)1 AuthController (com.tremolosecurity.proxy.auth.AuthController)1 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)1 ScaleConfig (com.tremolosecurity.scalejs.cfg.ScaleConfig)1 ScaleError (com.tremolosecurity.scalejs.data.ScaleError)1 NewUserRequest (com.tremolosecurity.scalejs.register.data.NewUserRequest)1 ReCaptchaResponse (com.tremolosecurity.scalejs.register.data.ReCaptchaResponse)1