Merge "[AAI] Fix doc config files"
[aai/aai-common.git] / aai-aaf-auth / src / main / java / org / onap / aai / aaf / auth / AafRequestWrapper.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.aaf.auth;
22
23 import java.util.*;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletRequestWrapper;
27
28 /**
29  * The AafRequestWrapper sets the user in the principal name
30  */
31 public class AafRequestWrapper extends HttpServletRequestWrapper {
32
33     private final Map<String, String> customHeaders;
34
35     public AafRequestWrapper(HttpServletRequest request) {
36         super(request);
37         this.customHeaders = new HashMap<String, String>();
38     }
39
40     public void putHeader(String name, String value) {
41         this.customHeaders.put(name, value);
42     }
43
44     @Override
45     public String getHeader(String name) {
46         String headerValue = customHeaders.get(name);
47         if (headerValue != null) {
48             return headerValue;
49         }
50         return (((HttpServletRequest) getRequest()).getHeader(name));
51     }
52
53     @Override
54     public Enumeration<String> getHeaderNames() {
55         Set<String> nameSet = new HashSet<String>(customHeaders.keySet());
56
57         Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaderNames();
58         while (e.hasMoreElements()) {
59             String headerName = e.nextElement();
60             nameSet.add(headerName);
61         }
62         return Collections.enumeration(nameSet);
63     }
64
65     @Override
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);
71         }
72         Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaders(name);
73         while (e.hasMoreElements()) {
74             String headerValue = e.nextElement();
75             headerValueSet.add(headerValue);
76         }
77         return Collections.enumeration(headerValueSet);
78     }
79 }