2 * Copyright © 2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.sdc.workflow.server.filters;
19 import java.io.IOException;
20 import javax.servlet.Filter;
21 import javax.servlet.FilterChain;
22 import javax.servlet.FilterConfig;
23 import javax.servlet.ServletException;
24 import javax.servlet.ServletRequest;
25 import javax.servlet.ServletResponse;
26 import javax.servlet.http.HttpServletRequest;
27 import org.onap.sdc.common.session.SessionContextProvider;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.beans.factory.annotation.Value;
30 import org.springframework.stereotype.Component;
33 public class SessionContextFilter implements Filter {
35 private final SessionContextProvider sessionContextProvider;
36 @Value("${spring.data.cassandra.keyspace-name}")
37 private String tenant;
40 public SessionContextFilter(SessionContextProvider sessionContextProvider) {
41 this.sessionContextProvider = sessionContextProvider;
45 public void init(FilterConfig filterConfig) {
50 public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
51 throws IOException, ServletException {
53 if (servletRequest instanceof HttpServletRequest) {
54 sessionContextProvider.create(getUser(servletRequest), tenant);
57 filterChain.doFilter(servletRequest, servletResponse);
59 sessionContextProvider.close();
64 public void destroy() {
68 private String getUser(ServletRequest servletRequest) {
70 // TODO: 7/11/2018 get user from header when collaboration will be supported
71 //((HttpServletRequest) servletRequest).getHeader(USER_ID_HEADER_PARAM);