2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.aaf.auth;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletRequestWrapper;
29 * The AafRequestWrapper sets the user in the principal name
31 public class AafRequestWrapper extends HttpServletRequestWrapper {
33 private final Map<String, String> customHeaders;
35 public AafRequestWrapper(HttpServletRequest request) {
37 this.customHeaders = new HashMap<String, String>();
40 public void putHeader(String name, String value) {
41 this.customHeaders.put(name, value);
45 public String getHeader(String name) {
46 String headerValue = customHeaders.get(name);
47 if (headerValue != null) {
50 return (((HttpServletRequest) getRequest()).getHeader(name));
54 public Enumeration<String> getHeaderNames() {
55 Set<String> nameSet = new HashSet<String>(customHeaders.keySet());
57 Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaderNames();
58 while (e.hasMoreElements()) {
59 String headerName = e.nextElement();
60 nameSet.add(headerName);
62 return Collections.enumeration(nameSet);
66 public Enumeration<String> getHeaders(String name) {
67 String myHeaderValue = customHeaders.get(name);
68 Set<String> headerValueSet = new HashSet<String>();
69 if (myHeaderValue != null) {
70 headerValueSet.add(myHeaderValue);
72 Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaders(name);
73 while (e.hasMoreElements()) {
74 String headerValue = e.nextElement();
75 headerValueSet.add(headerValue);
77 return Collections.enumeration(headerValueSet);