X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2FClampServlet.java;h=6adb76cb3187712f76f7d94c46e5f70e225fe24b;hb=66e68b859d8faa62ca854741f9b8bc579571c9b9;hp=90d0693d1288dec6e88106f30aa0a06552cc1797;hpb=d4976b71508b2a3670167b7f0f412d3bfdd6ce54;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/ClampServlet.java b/src/main/java/org/onap/clamp/clds/ClampServlet.java index 90d0693d..6adb76cb 100644 --- a/src/main/java/org/onap/clamp/clds/ClampServlet.java +++ b/src/main/java/org/onap/clamp/clds/ClampServlet.java @@ -27,8 +27,20 @@ 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; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.apache.camel.component.servlet.CamelHttpTransportServlet; -import org.onap.clamp.clds.service.SecureServicePermission; +import org.onap.clamp.authorization.SecureServicePermission; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatus; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -39,14 +51,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; import org.springframework.web.context.support.WebApplicationContextUtils; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.security.Principal; -import java.util.ArrayList; -import java.util.List; - public class ClampServlet extends CamelHttpTransportServlet { /** @@ -67,16 +71,11 @@ public class ClampServlet extends CamelHttpTransportServlet { private static List 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 getPermissionList() { @@ -100,7 +99,8 @@ public class ClampServlet extends CamelHttpTransportServlet { permissionList.add(SecureServicePermission .create(applicationContext.getEnvironment().getProperty(PERM_TOSCA), cldsPermissionInstance, READ)); permissionList.add(SecureServicePermission - .create(applicationContext.getEnvironment().getProperty(PERM_TOSCA), cldsPermissionInstance, UPDATE)); + .create(applicationContext.getEnvironment().getProperty(PERM_TOSCA), + cldsPermissionInstance, UPDATE)); } return permissionList; } @@ -112,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.getClass().getName()))) { // When AAF is enabled, there is a need to provision the permissions to Spring // system List grantedAuths = new ArrayList<>(); @@ -122,8 +123,8 @@ public class ClampServlet extends CamelHttpTransportServlet { grantedAuths.add(new SimpleGrantedAuthority(permString)); } } - Authentication auth = new UsernamePasswordAuthenticationToken(new User(principal.getName(), "", grantedAuths), "", - grantedAuths); + Authentication auth = new UsernamePasswordAuthenticationToken(new User(principal.getName(), "", + grantedAuths), "", grantedAuths); SecurityContextHolder.getContext().setAuthentication(auth); } try { @@ -137,4 +138,4 @@ public class ClampServlet extends CamelHttpTransportServlet { } } } -} \ No newline at end of file +}