From 2d2e0b503f915a81ae9a02dfa3afac3de369efde Mon Sep 17 00:00:00 2001 From: sheetalm Date: Thu, 8 Feb 2018 09:30:02 +0530 Subject: Onboarding foundation changes 1. Adding OnboardingSessionContextFilter which sets tenant(kespace) for onboarding application 2. Different services can extend SessionContextFilter to set their own keyspace 3. These changes in onboarding are done to support services like ActivitySpec Change-Id: Ia62557354ab05235d027250af94a2835d741b7fa Issue-ID: SDC-1005 Signed-off-by: sheetalm --- .../filters/OnboardingSessionContextFilter.java | 21 ++++++++++ .../server/filters/SessionContextFilter.java | 45 ---------------------- .../listeners/OnboardingAppStartupListener.java | 3 ++ .../src/main/webapp/WEB-INF/web.xml | 2 +- 4 files changed, 25 insertions(+), 46 deletions(-) create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/OnboardingSessionContextFilter.java delete mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/SessionContextFilter.java (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war') diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/OnboardingSessionContextFilter.java b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/OnboardingSessionContextFilter.java new file mode 100644 index 0000000000..7166f627e4 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/OnboardingSessionContextFilter.java @@ -0,0 +1,21 @@ +package org.openecomp.server.filters; + +import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM; + +import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.sdcrests.filters.SessionContextFilter; + +public class OnboardingSessionContextFilter extends SessionContextFilter { + + @Override + public String getUser(ServletRequest servletRequest) { + return ((HttpServletRequest) servletRequest).getHeader(USER_ID_HEADER_PARAM); + } + + @Override + public String getTenant(ServletRequest servletRequest) { + return "dox"; + } +} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/SessionContextFilter.java b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/SessionContextFilter.java deleted file mode 100644 index b317fa6bf5..0000000000 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/filters/SessionContextFilter.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.openecomp.server.filters; - -import org.openecomp.sdc.common.session.SessionContextProvider; -import org.openecomp.sdc.common.session.SessionContextProviderFactory; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; - -import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM; - -public class SessionContextFilter implements Filter { - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, - FilterChain filterChain) throws IOException, ServletException { - SessionContextProvider contextProvider = - SessionContextProviderFactory.getInstance().createInterface(); - - try { - if (servletRequest instanceof HttpServletRequest) { - String userName = ((HttpServletRequest) servletRequest).getHeader(USER_ID_HEADER_PARAM); - contextProvider.create(userName); - } - - filterChain.doFilter(servletRequest, servletResponse); - } finally { - contextProvider.close(); - } - } - - @Override - public void destroy() { - - } -} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/listeners/OnboardingAppStartupListener.java b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/listeners/OnboardingAppStartupListener.java index 2ea0ee2f66..b1c818cabb 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/listeners/OnboardingAppStartupListener.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/java/org/openecomp/server/listeners/OnboardingAppStartupListener.java @@ -21,6 +21,7 @@ package org.openecomp.server.listeners; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; import org.springframework.web.context.ContextLoaderListener; import javax.servlet.ServletContextEvent; @@ -32,6 +33,8 @@ public class OnboardingAppStartupListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent servletContextEvent) { + SessionContextProviderFactory.getInstance().createInterface().create("onboarding", + "dox"); springListener = new ContextLoaderListener(); springListener.initWebApplicationContext(servletContextEvent.getServletContext()); } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/web.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/web.xml index de88197a8a..64be5ab20c 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/web.xml +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/onboarding-rest-war/src/main/webapp/WEB-INF/web.xml @@ -83,7 +83,7 @@ SessionContextFilter - org.openecomp.server.filters.SessionContextFilter + org.openecomp.server.filters.OnboardingSessionContextFilter SessionContextFilter -- cgit 1.2.3-korg