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());
}
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;
}
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);
}
Aggregations