Search in sources :

Example 16 with ParamWithValueType

use of com.tremolosecurity.config.xml.ParamWithValueType in project OpenUnison by TremoloSecurity.

the class SendMessageThread method addJob.

private void addJob(JobType jobType, JobKey jk) throws ClassNotFoundException, SchedulerException {
    JobDetail jd;
    JobBuilder jb = JobBuilder.newJob((Class<? extends Job>) Class.forName(jobType.getClassName()));
    for (ParamWithValueType pt : jobType.getParam()) {
        if (pt.getValue() != null && !pt.getValue().isBlank()) {
            jb.usingJobData(pt.getName(), pt.getValue());
        } else {
            jb.usingJobData(pt.getName(), pt.getValueAttribute());
        }
    }
    jb.withIdentity(jk);
    jd = jb.build();
    StringBuffer cron = new StringBuffer();
    cron.append(jobType.getCronSchedule().getSeconds()).append(' ').append(jobType.getCronSchedule().getMinutes()).append(' ').append(jobType.getCronSchedule().getHours()).append(' ').append(jobType.getCronSchedule().getDayOfMonth()).append(' ').append(jobType.getCronSchedule().getMonth()).append(' ').append(jobType.getCronSchedule().getDayOfWeek()).append(' ').append(jobType.getCronSchedule().getYear());
    TriggerBuilder tb = TriggerBuilder.newTrigger().withIdentity("trigger_" + jobType.getName(), jobType.getGroup()).withSchedule(CronScheduleBuilder.cronSchedule(cron.toString()).withMisfireHandlingInstructionFireAndProceed());
    ;
    this.scheduler.scheduleJob(jd, tb.build());
}
Also used : JobDetail(org.quartz.JobDetail) JobBuilder(org.quartz.JobBuilder) ParamWithValueType(com.tremolosecurity.config.xml.ParamWithValueType) TriggerBuilder(org.quartz.TriggerBuilder)

Example 17 with ParamWithValueType

use of com.tremolosecurity.config.xml.ParamWithValueType in project OpenUnison by TremoloSecurity.

the class LoadApplicationsFromK8s method createApplication.

public ApplicationType createApplication(JSONObject item, String name) throws Exception {
    ApplicationType app = new ApplicationType();
    app.setName(name);
    JSONObject spec = (JSONObject) item.get("spec");
    app.setAzTimeoutMillis(getLongValue(spec.get("azTimeoutMillis"), 3000));
    app.setIsApp(getBoolValue(spec.get("isApp"), true));
    JSONArray urls = (JSONArray) spec.get("urls");
    app.setUrls(new UrlsType());
    for (Object o : urls) {
        JSONObject jsonUrl = (JSONObject) o;
        UrlType url = new UrlType();
        if (!app.isIsApp()) {
            createIdpOnUrl(jsonUrl, url);
        }
        JSONArray hosts = (JSONArray) jsonUrl.get("hosts");
        for (Object x : hosts) {
            url.getHost().add((String) x);
        }
        JSONArray filters = (JSONArray) jsonUrl.get("filterChain");
        url.setFilterChain(new FilterChainType());
        if (filters != null) {
            for (Object x : filters) {
                JSONObject jsonFilter = (JSONObject) x;
                FilterConfigType ft = new FilterConfigType();
                ft.setClazz((String) jsonFilter.get("className"));
                JSONObject params = (JSONObject) jsonFilter.get("params");
                if (params != null) {
                    for (Object y : params.keySet()) {
                        String paramName = (String) y;
                        Object z = params.get(paramName);
                        if (z instanceof String) {
                            ParamWithValueType pt = new ParamWithValueType();
                            pt.setName(paramName);
                            pt.setValue((String) z);
                            ft.getParam().add(pt);
                        } else {
                            JSONArray values = (JSONArray) z;
                            for (Object w : values) {
                                ParamWithValueType pt = new ParamWithValueType();
                                pt.setName(paramName);
                                pt.setValue((String) w);
                                ft.getParam().add(pt);
                            }
                        }
                    }
                }
                JSONArray secretParams = (JSONArray) jsonFilter.get("secretParams");
                if (secretParams != null) {
                    HttpCon nonwatchHttp = this.k8sWatch.getK8s().createClient();
                    String token = this.k8sWatch.getK8s().getAuthToken();
                    try {
                        for (Object ox : secretParams) {
                            JSONObject secretParam = (JSONObject) ox;
                            String paramName = (String) secretParam.get("name");
                            String secretName = (String) secretParam.get("secretName");
                            String secretKey = (String) secretParam.get("secretKey");
                            String secretValue = this.k8sWatch.getSecretValue(secretName, secretKey, token, nonwatchHttp);
                            ParamWithValueType pt = new ParamWithValueType();
                            pt.setName(paramName);
                            pt.setValue(secretValue);
                            pt.setValueAttribute(secretValue);
                            ft.getParam().add(pt);
                        }
                    } finally {
                        nonwatchHttp.getHttp().close();
                        nonwatchHttp.getBcm().close();
                    }
                }
                url.getFilterChain().getFilter().add(ft);
            }
        }
        JSONArray jsonAzRules = (JSONArray) jsonUrl.get("azRules");
        AzRulesType art = new AzRulesType();
        if (jsonAzRules != null) {
            for (Object x : jsonAzRules) {
                JSONObject jsonRule = (JSONObject) x;
                AzRuleType artx = new AzRuleType();
                artx.setScope((String) jsonRule.get("scope"));
                artx.setConstraint((String) jsonRule.get("constraint"));
                art.getRule().add(artx);
            }
        }
        url.setAzRules(art);
        url.setProxyTo((String) jsonUrl.get("proxyTo"));
        url.setUri((String) jsonUrl.get("uri"));
        url.setRegex(getBoolValue(jsonUrl.get("regex"), false));
        url.setAuthChain((String) jsonUrl.get("authChain"));
        url.setOverrideHost(getBoolValue(jsonUrl.get("overrideHost"), false));
        url.setOverrideReferer(getBoolValue(jsonUrl.get("overrideReferer"), false));
        JSONObject jsonResults = (JSONObject) jsonUrl.get("results");
        if (jsonResults != null) {
            ResultRefType rt = new ResultRefType();
            rt.setAuSuccess((String) jsonResults.get("auSuccess"));
            rt.setAzSuccess((String) jsonResults.get("azSuccess"));
            rt.setAuFail((String) jsonResults.get("auFail"));
            rt.setAzFail((String) jsonResults.get("azFail"));
            url.setResults(rt);
        }
        app.getUrls().getUrl().add(url);
    }
    JSONObject jsonCookie = (JSONObject) spec.get("cookieConfig");
    if (jsonCookie != null) {
        CookieConfigType cct = new CookieConfigType();
        cct.setSessionCookieName((String) jsonCookie.get("sessionCookieName"));
        cct.setDomain((String) jsonCookie.get("domain"));
        cct.setScope(getIntValue(jsonCookie.get("scope"), -1));
        cct.setLogoutURI((String) jsonCookie.get("logoutURI"));
        cct.setKeyAlias((String) jsonCookie.get("keyAlias"));
        cct.setTimeout(getIntValue(jsonCookie.get("timeout"), 0).intValue());
        cct.setSecure(getBoolValue(jsonCookie.get("secure"), false));
        cct.setHttpOnly(getBoolValue(jsonCookie.get("httpOnly"), false));
        cct.setSameSite((String) jsonCookie.get("sameSite"));
        cct.setCookiesEnabled(getBoolValue(jsonCookie.get("cookiesEnabled"), true));
        app.setCookieConfig(cct);
    }
    return app;
}
Also used : AzRulesType(com.tremolosecurity.config.xml.AzRulesType) JSONArray(org.json.simple.JSONArray) UrlsType(com.tremolosecurity.config.xml.UrlsType) FilterChainType(com.tremolosecurity.config.xml.FilterChainType) ResultRefType(com.tremolosecurity.config.xml.ResultRefType) ApplicationType(com.tremolosecurity.config.xml.ApplicationType) CustomAzRuleType(com.tremolosecurity.config.xml.CustomAzRuleType) AzRuleType(com.tremolosecurity.config.xml.AzRuleType) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) JSONObject(org.json.simple.JSONObject) FilterConfigType(com.tremolosecurity.config.xml.FilterConfigType) CookieConfigType(com.tremolosecurity.config.xml.CookieConfigType) JSONObject(org.json.simple.JSONObject) ParamWithValueType(com.tremolosecurity.config.xml.ParamWithValueType) UrlType(com.tremolosecurity.config.xml.UrlType)

Example 18 with ParamWithValueType

use of com.tremolosecurity.config.xml.ParamWithValueType in project OpenUnison by TremoloSecurity.

the class ParseWorkflow method createCustomTask.

private void createCustomTask(JSONObject node, String path, List<WorkflowTaskType> parent, ParsedWorkflow pw) {
    CustomTaskType task = new CustomTaskType();
    OptionType[] options = new OptionType[] { new OptionType("className", true, OptionType.OptionValueType.STRING) };
    for (OptionType ot : options) {
        setAttribute(node, ot, task, CustomTaskType.class, pw, path);
        if (pw.getError() != null) {
            return;
        }
    }
    Object op = node.get("params");
    if (op != null) {
        if (!(op instanceof JSONObject)) {
            pw.setError("params must be an object");
            pw.setErrorPath(path + ".params");
            return;
        }
        int ii = 0;
        JSONObject params = (JSONObject) op;
        for (Object key : params.keySet()) {
            if (!(key instanceof String)) {
                pw.setError("parameter key must be a string");
                pw.setErrorPath(path + ".params[" + ii + "]");
                return;
            }
            String paramName = (String) key;
            Object vals = params.get(paramName);
            if (vals instanceof String) {
                ParamWithValueType pt = new ParamWithValueType();
                pt.setName(paramName);
                pt.setValue((String) vals);
                task.getParam().add(pt);
            } else if (vals instanceof JSONArray) {
                JSONArray jsonVals = (JSONArray) vals;
                int ll = 0;
                for (Object v : jsonVals) {
                    if (!(v instanceof String)) {
                        pw.setError("all values of a parameter must be a string");
                        pw.setErrorPath(path + ".params[" + ii + "][" + ll + "]");
                        return;
                    }
                    ParamWithValueType pt = new ParamWithValueType();
                    pt.setName(paramName);
                    pt.setValue((String) v);
                    task.getParam().add(pt);
                    ll++;
                }
            } else {
                pw.setError("parameter value must be a string or a list of strings");
                pw.setErrorPath(path + ".params[" + ii + "]");
                return;
            }
            ii++;
        }
        node.remove("params");
    }
    if (!node.isEmpty()) {
        pw.setError("Extra JSON keys : " + node.toString());
        pw.setErrorPath(path);
        return;
    }
    parent.add(task);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) ParamWithValueType(com.tremolosecurity.config.xml.ParamWithValueType) CustomTaskType(com.tremolosecurity.config.xml.CustomTaskType)

Aggregations

ParamWithValueType (com.tremolosecurity.config.xml.ParamWithValueType)18 AuthChainType (com.tremolosecurity.config.xml.AuthChainType)8 AuthMechType (com.tremolosecurity.config.xml.AuthMechType)8 IOException (java.io.IOException)5 Attribute (com.tremolosecurity.saml.Attribute)4 ArrayList (java.util.ArrayList)4 ServletException (javax.servlet.ServletException)4 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 LDAPException (com.novell.ldap.LDAPException)3 ApplicationType (com.tremolosecurity.config.xml.ApplicationType)3 MechanismType (com.tremolosecurity.config.xml.MechanismType)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 CertificateException (java.security.cert.CertificateException)3 X509Certificate (java.security.cert.X509Certificate)3 HashMap (java.util.HashMap)3 LDAPAttribute (com.novell.ldap.LDAPAttribute)2 AuthMechParamType (com.tremolosecurity.config.xml.AuthMechParamType)2 CustomTaskType (com.tremolosecurity.config.xml.CustomTaskType)2