Public and Private Locate entries
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / filter / FCGet.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 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
22 package org.onap.aaf.cadi.filter;
23
24 import javax.servlet.FilterConfig;
25 import javax.servlet.ServletContext;
26
27 import org.onap.aaf.cadi.Access;
28 import org.onap.aaf.cadi.Access.Level;
29 import org.onap.aaf.cadi.config.Get;
30
31 /*
32  * A private method to query the Filter config and if not exists, return the default.  This
33  * cleans up the initialization code.
34  */
35 public class FCGet implements Get {
36     /**
37      * 
38      */
39     private final Access access;
40     private FilterConfig filterConfig;
41     private ServletContext context;
42
43     public FCGet(Access access, ServletContext context, FilterConfig filterConfig) {
44         this.access = access;
45         this.context = context;
46         this.filterConfig = filterConfig;
47     }
48
49     public String get(String name, String def, boolean print) {
50         String str = null;
51         // Try Server Context First
52         if (context!=null) {
53             str = context.getInitParameter(name);
54         }
55         
56         // Try Filter Context next
57         if (str==null && filterConfig != null) {
58             str = filterConfig.getInitParameter(name);
59         }
60         
61         if (str==null) {
62             str = access.getProperty(name, def);
63         }
64         // Take def if nothing else
65         if (str==null) {
66             str = def;
67             // don't log defaults
68         } else {
69             str = str.trim(); // this is vital in Property File based values, as spaces can hide easily
70             if (print) {
71                 access.log(Level.INFO,"Setting", name, "to", str);
72             }
73         }
74         return str;
75     }
76 }