X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fcommon%2FDefine.java;h=800a8472c7a949dd253e9753019f088f1d22840d;hb=1338680ef142f9a33ee32a00b07c7d2ae658cb3a;hp=1e7a0530a91253a4a44f7974fc1bcddb32d0bb2e;hpb=dcaa1072621c7e0f586e2965fd8bb952d4b01880;p=aaf%2Fauthz.git diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/common/Define.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/common/Define.java index 1e7a0530..800a8472 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/common/Define.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/common/Define.java @@ -24,59 +24,83 @@ package org.onap.aaf.auth.common; import java.util.Map.Entry; import org.onap.aaf.cadi.Access; -import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.Access.Level; +import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.config.Config; public class Define { - private static String ROOT_NS = null; - private static String ROOT_COMPANY = null; + private static String ROOT_NS = null; + private static String ROOT_COMPANY = null; + private static boolean initialized = false; + + private final static String MSG = ".set(Access access) must be called before use"; + public static final CharSequence ROOT_NS_TAG = "AAF_NS"; // use for certain Replacements in Location + private static final int ROOT_NS_TAG_LEN=ROOT_NS_TAG.length(); + private static final String ROOT_NS_TAG_DOT = ROOT_NS_TAG +"."; + + public static String ROOT_NS() { + if (ROOT_NS==null) { + throw new RuntimeException(Define.class.getName() + MSG); + } + return ROOT_NS; + } + + public static String ROOT_COMPANY() { + if (ROOT_NS==null) { + throw new RuntimeException(Define.class.getName() + MSG); + } + return ROOT_COMPANY; + } + + public static void set(Access access) throws CadiException { + ROOT_NS = access.getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); + ROOT_COMPANY = access.getProperty(Config.AAF_ROOT_COMPANY,null); + if (ROOT_COMPANY==null) { + int last = ROOT_NS.lastIndexOf('.'); + if (last>=0) { + ROOT_COMPANY = ROOT_NS.substring(0, last); + } else { + throw new CadiException(Config.AAF_ROOT_COMPANY + " or " + Config.AAF_ROOT_NS + " property with 3 positions is required."); + } + } + + for ( Entry es : access.getProperties().entrySet()) { + if (es.getKey().toString().startsWith(ROOT_NS_TAG_DOT)) { + access.getProperties().setProperty(es.getKey().toString(),varReplace(es.getValue().toString())); + } + } - private final static String MSG = ".set(Access access) must be called before use"; - public static final CharSequence ROOT_NS_TAG = "AAF_NS"; // use for certain Replacements in Location - private static final String ROOT_NS_TAG_DOT = ROOT_NS_TAG +"."; + initialized = true; + access.printf(Level.INIT,"AAF Root NS is %s, and AAF Company Root is %s",ROOT_NS,ROOT_COMPANY); + } - public static String ROOT_NS() { - if(ROOT_NS==null) { - throw new RuntimeException(Define.class.getName() + MSG); - } - return ROOT_NS; - } - - public static String ROOT_COMPANY() { - if(ROOT_NS==null) { - throw new RuntimeException(Define.class.getName() + MSG); - } - return ROOT_COMPANY; - } - - public static void set(Access access) throws CadiException { - ROOT_NS = access.getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - ROOT_COMPANY = access.getProperty(Config.AAF_ROOT_COMPANY,null); - if(ROOT_COMPANY==null) { - int last = ROOT_NS.lastIndexOf('.'); - if(last>=0) { - ROOT_COMPANY = ROOT_NS.substring(0, last); - } else { - throw new CadiException(Config.AAF_ROOT_COMPANY + " or " + Config.AAF_ROOT_NS + " property with 3 positions is required."); - } - } - - for( Entry es : access.getProperties().entrySet()) { - if(es.getKey().toString().startsWith(ROOT_NS_TAG_DOT)) { - access.getProperties().setProperty(es.getKey().toString(),varReplace(es.getValue().toString())); - } - } - - access.printf(Level.INIT,"AAF Root NS is %s, and AAF Company Root is %s",ROOT_NS,ROOT_COMPANY); - } + public static String varReplace(final String potential) { + int idx = potential.indexOf(ROOT_NS_TAG_DOT); + if(idx<0) { + return potential; + } else if(idx==0) { + return ROOT_NS + potential.substring(ROOT_NS_TAG_LEN); + } else if('.'==potential.charAt(idx)) { + return potential.replace(ROOT_NS_TAG, ROOT_NS); + } else { + return potential; + } + } - public static String varReplace(final String potential) { - if(potential.startsWith(ROOT_NS_TAG_DOT)) { - return ROOT_NS + potential.substring(6); - } else { - return potential; - } - } - + public static boolean isInitialized() { + return initialized; + } + + public static String getCredType(int type) { + switch(type) { + case 0: return "NoCrd"; + case 1: return "U/P"; + case 2: return "U/P2"; + case 10: return "FQI"; + case 200: return "x509"; + default: + return "n/a"; + } + } + }