Add flexibility 28/74928/1
authorsebdet <sebastien.determe@intl.att.com>
Wed, 19 Dec 2018 16:33:37 +0000 (17:33 +0100)
committersebdet <sebastien.determe@intl.att.com>
Wed, 19 Dec 2018 16:33:37 +0000 (17:33 +0100)
Add flexibility to the code for the authentication part

Issue-ID: CLAMP-252
Change-Id: Id13275c37b44f6934057000743f40fb531313cca
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
src/main/java/org/onap/clamp/clds/ClampServlet.java
src/main/resources/application.properties
src/test/resources/application.properties

index 516325c..008a9c7 100644 (file)
@@ -36,7 +36,6 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.camel.component.servlet.CamelHttpTransportServlet;
-import org.onap.aaf.cadi.principal.X509Principal;
 import org.onap.clamp.clds.service.SecureServicePermission;
 import org.springframework.context.ApplicationContext;
 import org.springframework.http.HttpStatus;
@@ -62,11 +61,24 @@ public class ClampServlet extends CamelHttpTransportServlet {
     public static final String PERM_VF = "clamp.config.security.permission.type.filter.vf";
     public static final String PERM_MANAGE = "clamp.config.security.permission.type.cl.manage";
     public static final String PERM_TOSCA = "clamp.config.security.permission.type.tosca";
+    public static final String AUTHENTICATION_CLASS = "clamp.config.security.authentication.class";
     private static List<SecureServicePermission> permissionList;
 
+    private synchronized Class loadDynamicAuthenticationClass() {
+        try {
+            String authenticationObject = WebApplicationContextUtils.getWebApplicationContext(getServletContext())
+                .getEnvironment().getProperty(AUTHENTICATION_CLASS);
+            return Class.forName(authenticationObject);
+        } catch (ClassNotFoundException e) {
+            logger.error(
+                "Exception caught when attempting to create associated class of config:" + AUTHENTICATION_CLASS, e);
+            return Object.class;
+        }
+    }
+
     private synchronized List<SecureServicePermission> getPermissionList() {
         if (permissionList == null) {
-            permissionList=new ArrayList<>();
+            permissionList = new ArrayList<>();
             ApplicationContext applicationContext = WebApplicationContextUtils
                 .getWebApplicationContext(getServletContext());
             String cldsPermissionInstance = applicationContext.getEnvironment().getProperty(PERM_INSTANCE);
@@ -97,9 +109,8 @@ public class ClampServlet extends CamelHttpTransportServlet {
     @Override
     protected void doService(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException {
-
         Principal p = request.getUserPrincipal();
-        if (p instanceof X509Principal) {
+        if (loadDynamicAuthenticationClass().isInstance(p)) {
             // When AAF is enabled, there is a need to provision the permissions to Spring
             // system
             List<GrantedAuthority> grantedAuths = new ArrayList<>();
index e44ba75..c492f74 100644 (file)
@@ -232,6 +232,7 @@ clamp.config.security.permission.type.template=org.onap.clamp.clds.template
 clamp.config.security.permission.type.tosca=org.onap.clamp.clds.tosca
 #This one indicates the type of instances (dev|prod|perf...), this must be set accordingly in clds-users.properties
 clamp.config.security.permission.instance=dev
+clamp.config.security.authentication.class=org.onap.aaf.cadi.principal.X509Principal
 
 #AAF related parameters
 clamp.config.cadi.keyFile=classpath:/clds/aaf/org.onap.clamp.keyfile
index 7116940..d75c608 100644 (file)
@@ -191,7 +191,7 @@ clamp.config.sdc.locationArtifactType=DCAE_INVENTORY_JSON
 clamp.config.sdc.InstanceID=X-ECOMP-InstanceID\r
 clamp.config.sdc.header.requestId = X-ECOMP-RequestID\r
 #\r
-clamp.config.sdc.csarFolder = /tmp/sdc-tests\r
+clamp.config.sdc.csarFolder = ${project.build.directory}/sdc-tests\r
 clamp.config.sdc.blueprint.parser.mapping = classpath:/clds/blueprint-parser-mapping.json\r
 #\r
 clamp.config.ui.location.default=classpath:/clds/templates/ui-location-default.json\r
@@ -221,4 +221,5 @@ clamp.config.security.permission.type.filter.vf=permission-type-filter-vf
 clamp.config.security.permission.type.template=permission-type-template\r
 clamp.config.security.permission.type.tosca=permission-type-tosca\r
 #This one indicates the type of instances (dev|prod|perf...), this must be set accordingly in clds-users.properties\r
-clamp.config.security.permission.instance=dev
\ No newline at end of file
+clamp.config.security.permission.instance=dev\r
+clamp.config.security.authentication.class=org.onap.aaf.cadi.principal.X509Principal
\ No newline at end of file