From 878eedccba50ecf0a63bdad2e1a7924f280bed0c Mon Sep 17 00:00:00 2001 From: Michael DÜrre Date: Tue, 23 Feb 2021 16:35:10 +0100 Subject: fixed login method for odlux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add config switch for oauth flag Issue-ID: CCSDK-3182 Signed-off-by: Michael DÜrre Change-Id: I58ab6d5fa3c86e567c7fe40483bf4c1069238de9 --- .../features/sdnr/wt/odlux/IndexOdluxBundle.java | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'sdnr/wt/odlux/core/provider/src') diff --git a/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java b/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java index 1ea27d71f..c1cf875fc 100644 --- a/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java +++ b/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundle; @@ -38,12 +39,24 @@ public class IndexOdluxBundle extends OdluxBundle implements OdluxBundleResource private static final String regexRequire = "require\\(\\[(\"" + BUNDLENAME_APP + "\")\\]"; private static final String regexFunction = "function[\\ ]*\\((" + BUNDLENAME_APP + ")\\)[\\ ]*\\{"; private static final String regexFunctionBody = "(" + BUNDLENAME_APP + "\\.runApplication\\(\\);)"; + private static final String regexConfigure = BUNDLENAME_APP+"\\.configureApplication\\(([^\\)]+)\\)"; private static final Pattern patternRequire = Pattern.compile(regexRequire); private static final Pattern patternFunction = Pattern.compile(regexFunction); private static final Pattern patternFunctionBody = Pattern.compile(regexFunctionBody); + private static final Pattern patternConfigure = Pattern.compile(regexConfigure); + private static final String ENV_ENABLE_OAUTH = "ENABLE_OAUTH"; + private static final String ENABLE_OAUTH_DEFAULT = "false"; + private static final String ENV_ENABLE_ODLUX_RBAC = "ENABLE_ODLUX_RBAC"; + private static final String ENABLE_ODLUX_RBAC_DEFAULT = "false"; + + private final boolean oauthEnabled; + private final boolean policyEnabled; public IndexOdluxBundle() { super(null, BUNDLENAME_APP); + this.oauthEnabled = "true".equals(getEnvVar(ENV_ENABLE_OAUTH, ENABLE_OAUTH_DEFAULT)); + this.policyEnabled = "true".equals(getEnvVar(ENV_ENABLE_ODLUX_RBAC, ENABLE_ODLUX_RBAC_DEFAULT)); + LOG.info("instantiating index with oauthEnabled={} and policyEnabled={}",this.oauthEnabled, this.policyEnabled); } @@ -57,7 +70,7 @@ public class IndexOdluxBundle extends OdluxBundle implements OdluxBundleResource return loadFileContent(this.getResource(fn), bundleNames); } - private static String loadFileContent(URL url, List bundlesNamesList) { + private String loadFileContent(URL url, List bundlesNamesList) { if (url == null) { return null; } @@ -92,10 +105,18 @@ public class IndexOdluxBundle extends OdluxBundle implements OdluxBundleResource inputLine = inputLine.substring(0, matcher.start(1)) + hlp + inputLine.substring(matcher.start(1)); } + } sb.append(inputLine + LR); } + if (url.getFile().endsWith("index.html")) { + matcher = patternConfigure.matcher(sb); + if(matcher.find() && matcher.groupCount()>0) { + sb.replace(matcher.start(1),matcher.end(1), this.generateConfigureJson()); + } + } + } catch (IOException e) { LOG.warn("could not load resfile {} : {}", url, e.getMessage()); return null; @@ -112,4 +133,17 @@ public class IndexOdluxBundle extends OdluxBundle implements OdluxBundleResource return sb.toString(); } + private String generateConfigureJson() { + return String.format("{\"authentication\":\"%s\",\"enablePolicy\":%s}", this.oauthEnabled ? "oauth" : "basic", + String.valueOf(this.policyEnabled)); + } + + private static String getEnvVar(String v, String defaultValue) { + Map env = System.getenv(); + for (String envName : env.keySet()) { + if (envName != null && envName.equals(v)) + return env.get(envName); + } + return defaultValue; + } } -- cgit 1.2.3-korg