summaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml10
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/filters/SessionContextFilter.java47
2 files changed, 57 insertions, 0 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml
index da8147f287..a82298b4c1 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/pom.xml
@@ -45,6 +45,16 @@
<version>${swagger.version}</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-session-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${javax.servlet.version}</version>
+ </dependency>
</dependencies>
</project> \ No newline at end of file
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/filters/SessionContextFilter.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/filters/SessionContextFilter.java
new file mode 100644
index 0000000000..f81cc4b586
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/filters/SessionContextFilter.java
@@ -0,0 +1,47 @@
+package org.openecomp.sdcrests.filters;
+
+import org.openecomp.sdc.common.session.SessionContextProvider;
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+
+import java.io.IOException;
+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;
+
+public abstract 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) {
+
+ contextProvider.create(getUser(servletRequest),getTenant(servletRequest));
+ }
+
+ filterChain.doFilter(servletRequest, servletResponse);
+ } finally {
+ contextProvider.close();
+ }
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+
+ public abstract String getUser(ServletRequest servletRequest);
+
+ public abstract String getTenant(ServletRequest servletRequest);
+}