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