From bf8f0ab08a7b2d60e2f6fd8c8f1e2203c3df97ea Mon Sep 17 00:00:00 2001
From: sebdet <sebastien.determe@intl.att.com>
Date: Thu, 15 Oct 2020 11:40:17 +0200
Subject: Fix creds issue with AAF

Fix the permissions not returned by AAF due to wrong code the clamp servlet.

Issue-ID: CLAMP-956
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Change-Id: I06fac82fb04421f154b67b625e910853ade8583f
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
---
 src/main/java/org/onap/clamp/clds/ClampServlet.java | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

(limited to 'src/main/java/org')

diff --git a/src/main/java/org/onap/clamp/clds/ClampServlet.java b/src/main/java/org/onap/clamp/clds/ClampServlet.java
index 5908201f..c1997279 100644
--- a/src/main/java/org/onap/clamp/clds/ClampServlet.java
+++ b/src/main/java/org/onap/clamp/clds/ClampServlet.java
@@ -28,9 +28,11 @@ package org.onap.clamp.clds;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 
+import fj.data.Array;
 import java.io.IOException;
 import java.security.Principal;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import javax.servlet.ServletException;
@@ -69,16 +71,11 @@ public class ClampServlet extends CamelHttpTransportServlet {
 
     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 String[] loadDynamicAuthenticationClasses() {
+        String[] authenticationObjects = WebApplicationContextUtils.getWebApplicationContext(getServletContext())
+                .getEnvironment().getProperty(AUTHENTICATION_CLASS).split(",");
+        Arrays.stream(authenticationObjects).forEach(className -> className.trim());
+        return authenticationObjects;
     }
 
     private synchronized List<SecureServicePermission> getPermissionList() {
@@ -115,7 +112,8 @@ public class ClampServlet extends CamelHttpTransportServlet {
     @Override
     protected void doService(HttpServletRequest request, HttpServletResponse response) {
         Principal principal = request.getUserPrincipal();
-        if (loadDynamicAuthenticationClass().isInstance(principal)) {
+        if (principal != null && Arrays.stream(loadDynamicAuthenticationClasses())
+                .anyMatch(className -> className.equals(principal.getName()))) {
             // When AAF is enabled, there is a need to provision the permissions to Spring
             // system
             List<GrantedAuthority> grantedAuths = new ArrayList<>();
-- 
cgit 1.2.3-korg