summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-02-23 16:35:10 +0100
committerMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-02-23 16:35:23 +0100
commit878eedccba50ecf0a63bdad2e1a7924f280bed0c (patch)
treeca4fd147db0b12f7959e282dd5dcdf3bb3a89e83
parentc4f83edf0e0fc63b35e6f412eeb64fe911b23390 (diff)
fixed login method for odlux
add config switch for oauth flag Issue-ID: CCSDK-3182 Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com> Change-Id: I58ab6d5fa3c86e567c7fe40483bf4c1069238de9
-rw-r--r--sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java36
1 files changed, 35 insertions, 1 deletions
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<String> bundlesNamesList) {
+ private String loadFileContent(URL url, List<String> 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<String, String> env = System.getenv();
+ for (String envName : env.keySet()) {
+ if (envName != null && envName.equals(v))
+ return env.get(envName);
+ }
+ return defaultValue;
+ }
}
#fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ ============LICENSE_START=======================================================
  ~ ONAP : ccsdk features
  ~ ================================================================================
  ~ Copyright (C) 2021-2022 Wipro Limited.
  ~ ================================================================================
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  ~ ============LICENSE_END=======================================================
  ~
  -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.onap.ccsdk.parent</groupId>
        <artifactId>binding-parent</artifactId>
        <version>2.6.1</version>
        <relativePath/>
    </parent>

    <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId>
    <artifactId>addCMHandle-model</artifactId>
    <version>1.6.0</version>
    <packaging>bundle</packaging>

    <name>ccsdk-features :: sdnr-northbound :: ${project.artifactId}</name>

    <dependencies>
        <dependency>
            <groupId>org.opendaylight.netconf</groupId>
            <artifactId>sal-netconf-connector</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.opendaylight.mdsal</groupId>
            <artifactId>mdsal-binding-dom-codec-api</artifactId>
            <scope>provided</scope>
        </dependency>
   </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/gen/**</exclude>
                        <exclude>**/generated-sources/**</exclude>
                        <exclude>**/yang-gen-sal/**</exclude>
                        <exclude>**/pax/**</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>