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;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletRequestWrapper;
28 * The AafRequestWrapper sets the user in the principal name
30 public class AafRequestWrapper extends HttpServletRequestWrapper {
32 private final Map<String, String> customHeaders;
34 public AafRequestWrapper(HttpServletRequest request) {
36 this.customHeaders = new HashMap<String, String>();
39 public void putHeader(String name, String value) {
40 this.customHeaders.put(name, value);
44 public String getHeader(String name) {
45 String headerValue = customHeaders.get(name);
46 if (headerValue != null) {
49 return (((HttpServletRequest) getRequest()).getHeader(name));
53 public Enumeration<String> getHeaderNames() {
54 Set<String> nameSet = new HashSet<String>(customHeaders.keySet());
56 Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaderNames();
57 while (e.hasMoreElements()) {
58 String headerName = e.nextElement();
59 nameSet.add(headerName);
61 return Collections.enumeration(nameSet);
65 public Enumeration<String> getHeaders(String name) {
66 String myHeaderValue = customHeaders.get(name);
67 Set<String> headerValueSet = new HashSet<String>();
68 if (myHeaderValue != null) {
69 headerValueSet.add(myHeaderValue);
71 Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaders(name);
72 while (e.hasMoreElements()) {
73 String headerValue = e.nextElement();
74 headerValueSet.add(headerValue);
76 return Collections.enumeration(headerValueSet);