summaryrefslogtreecommitdiffstats
path: root/core/sli/provider
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2021-10-29 15:04:35 -0400
committerDan Timoney <dtimoney@att.com>2021-10-29 15:04:41 -0400
commit1267516ac4ce6402a0d175328563d5557fd59c96 (patch)
tree0ed5d136977ea47f531412fd02941d627e35f03e /core/sli/provider
parent9bdc825f7b9c1689aae71fcb01bf08aa6bcba995 (diff)
Sync local changes to support GRA microservice
Sync changes made downstream to support GRA microservice Issue-ID: CCSDK-3504 Signed-off-by: Dan Timoney <dtimoney@att.com> Change-Id: I854b5437c4a60023bd161e3625e08ff6e0771945
Diffstat (limited to 'core/sli/provider')
-rw-r--r--core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java47
-rw-r--r--core/sli/provider/src/main/resources/classresolver.properties1
2 files changed, 48 insertions, 0 deletions
diff --git a/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java b/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java
index 82670375f..b9e83944d 100644
--- a/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java
+++ b/core/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java
@@ -21,7 +21,13 @@
package org.onap.ccsdk.sli.core.sli.provider;
+import java.nio.file.WatchKey;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;
@@ -37,7 +43,27 @@ import org.slf4j.LoggerFactory;
public class SvcLogicClassResolver implements SvcLogicResolver {
private static final Logger LOG = LoggerFactory.getLogger(SvcLogicClassResolver.class);
+ private static final String CLASS_RESOLVER_PROPERTIES="classresolver.properties";
+ private static final String ALLOWED_PACKAGES = "org.onap.ccsdk.sli.allowed.packages";
private static HashMap<String, SvcLogicAdaptor> adaptorMap = new HashMap<>();
+ List<String> allowedPackages = new ArrayList<String>();
+
+ public SvcLogicClassResolver() {
+ // Initialize list of allowed package names
+ Properties props = new Properties();
+ try {
+ props.load(SvcLogicClassResolver.class.getResourceAsStream(CLASS_RESOLVER_PROPERTIES));
+ String allowedPackagesProp = props.getProperty(ALLOWED_PACKAGES, "org.onap.ccsdk.sli");
+ String[] allowedPackageArray = allowedPackagesProp.split(",");
+ for (int i = 0 ; i < allowedPackageArray.length ; i++) {
+ allowedPackages.add(allowedPackageArray[i]);
+ }
+ } catch (Exception e)
+ {
+ LOG.warn("Caught exception trying to load properties file {}", CLASS_RESOLVER_PROPERTIES, e);
+ allowedPackages.add("org.onap.ccsdk.sli");
+ }
+ }
public void registerAdaptor(SvcLogicAdaptor adaptor) {
String name = adaptor.getClass().getName();
@@ -75,6 +101,11 @@ public class SvcLogicClassResolver implements SvcLogicResolver {
if (bundle == null) {
// Running outside OSGi container (e.g. jUnit). Use Reflection
// to resolve class
+ if (!isAllowedClassName(className)) {
+ LOG.error("Could not resolve class {} - invalid class name", className);
+ return null;
+ }
+
try {
return (Class.forName(className).newInstance());
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
@@ -96,6 +127,22 @@ public class SvcLogicClassResolver implements SvcLogicResolver {
}
}
+ private boolean isAllowedClassName(String className) {
+ if (className == null) {
+ return false;
+ }
+
+ Iterator<String> packageIter = allowedPackages.iterator();
+ while (packageIter.hasNext()) {
+ if (className.startsWith(packageIter.next()+".")) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
@Override
public SvcLogicResource getSvcLogicResource(String resourceName) {
return (SvcLogicResource) resolve(resourceName);
diff --git a/core/sli/provider/src/main/resources/classresolver.properties b/core/sli/provider/src/main/resources/classresolver.properties
new file mode 100644
index 000000000..69337c3d5
--- /dev/null
+++ b/core/sli/provider/src/main/resources/classresolver.properties
@@ -0,0 +1 @@
+org.onap.ccsdk.sli.allowed.packages="org.onap.ccsdk.sli, com.att.sdnctl"; \ No newline at end of file