1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 2017 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 ******************************************************************************/
22 package org.onap.aaf.auth.common;
24 import java.util.Map.Entry;
26 import org.onap.aaf.cadi.Access;
27 import org.onap.aaf.cadi.CadiException;
28 import org.onap.aaf.cadi.Access.Level;
29 import org.onap.aaf.cadi.config.Config;
32 private static String ROOT_NS = null;
33 private static String ROOT_COMPANY = null;
35 private final static String MSG = ".set(Access access) must be called before use";
36 public static final CharSequence ROOT_NS_TAG = "AAF_NS"; // use for certain Replacements in Location
37 private static final String ROOT_NS_TAG_DOT = ROOT_NS_TAG +".";
39 public static String ROOT_NS() {
41 throw new RuntimeException(Define.class.getName() + MSG);
46 public static String ROOT_COMPANY() {
48 throw new RuntimeException(Define.class.getName() + MSG);
53 public static void set(Access access) throws CadiException {
54 ROOT_NS = access.getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf");
55 ROOT_COMPANY = access.getProperty(Config.AAF_ROOT_COMPANY,null);
56 if(ROOT_COMPANY==null) {
57 int last = ROOT_NS.lastIndexOf('.');
59 ROOT_COMPANY = ROOT_NS.substring(0, last);
61 throw new CadiException(Config.AAF_ROOT_COMPANY + " or " + Config.AAF_ROOT_NS + " property with 3 positions is required.");
65 for( Entry<Object, Object> es : access.getProperties().entrySet()) {
66 if(es.getKey().toString().startsWith(ROOT_NS_TAG_DOT)) {
67 access.getProperties().setProperty(es.getKey().toString(),varReplace(es.getValue().toString()));
71 access.printf(Level.INIT,"AAF Root NS is %s, and AAF Company Root is %s",ROOT_NS,ROOT_COMPANY);
74 public static String varReplace(final String potential) {
75 if(potential.startsWith(ROOT_NS_TAG_DOT)) {
76 return ROOT_NS + potential.substring(6);