Merge "Sonar fix: Perm.java"
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / config / Config.java
index 66fbe84..30508b7 100644 (file)
@@ -157,6 +157,7 @@ public class Config {
     public static final String AAF_LOCATE_URL = "aaf_locate_url"; //URL for AAF locator
     public static final String AAF_LOCATE_URL_TAG = "AAF_LOCATE_URL"; // Name of Above for use in Config Variables.
     public static final String AAF_DEFAULT_API_VERSION = "2.1";
+    public static final String AAF_DEPLOYED_VERSION="aaf_deployed_version";
     public static final String AAF_API_VERSION = "aaf_api_version";
     public static final String AAF_URL = "aaf_url"; //URL for AAF... Use to trigger AAF configuration   
     public static final String AAF_LOCATOR_CLASS = "aaf_locator_class";
@@ -219,14 +220,19 @@ public class Config {
     public static final String AAF_CERT_IDS = "aaf_cert_ids";
     public static final String AAF_DEBUG_IDS = "aaf_debug_ids"; // comma delimited
     public static final String AAF_DATA_DIR = "aaf_data_dir"; // AAF processes and Components only.
-    public static final String AAF_RELEASE = "aaf_release";
 
+    public static final String AAF_URL_OAUTH = "aaf_url_oauth";
     public static final String AAF_URL_GUI="aaf_url_gui";
     public static final String AAF_URL_FS="aaf_url_fs";
     public static final String AAF_URL_CM = "aaf_url_cm";
     public static final String AAF_URL_CM_DEF = "https://AAF_LOCATE_URL/AAF_NS.cm:"+AAF_DEFAULT_API_VERSION;
     public static final String AAF_URL_HELLO = "aaf_url_hello";
     public static final String CM_TRUSTED_CAS = "cm_trusted_cas";
+    // let NS Owners choose with <ns>.certman aaf ignoreIPs" to ignoreIP Check for Configs
+    // Probably only want to allow in a DEV Env.
+    public static final String CM_ALLOW_IGNORE_IPS="cm_allow_ignore_ips";
+    // Docker doesn't have a default DNS. The property turns off IP Checking of DNSs before creating.
+    public static final String CM_ALWAYS_IGNORE_IPS="cm_always_ignore_ips";
 
     public static final String PATHFILTER_URLPATTERN = "pathfilter_urlpattern";
     public static final String PATHFILTER_STACK = "pathfilter_stack";
@@ -564,7 +570,7 @@ public class Config {
             }
             access.log(Level.INIT, sb);
 
-            Locator<URI> locator = loadLocator(si, logProp(rph, Config.getAAFLocateUrl(access), null));
+            Locator<URI> locator = loadLocator(si, aafURL);
             
             taf = new HttpEpiTaf(access,locator, tc, htarray); // ok to pass locator == null
             String level = logProp(access, CADI_LOGLEVEL, null);
@@ -849,6 +855,36 @@ public class Config {
         if (_url==null) {
             access.log(Level.INIT,"No URL passed to 'loadLocator'. Disabled");
         } else {
+               try {
+                       Class<?> aalCls = Class.forName("org.onap.aaf.cadi.aaf.v2_0.AbsAAFLocator");
+                       Method aalMth = aalCls.getMethod("create", String.class,String.class);
+                       int colon = _url.lastIndexOf(':');
+                       if(colon>=0) {
+                               int slash = _url.indexOf('/',colon);
+                               String version;
+                               if(slash<0) {
+                                       version = _url.substring(colon+1);
+                               } else {
+                                       version = _url.substring(colon+1,slash);
+                               }
+                               slash = _url.lastIndexOf('/',colon);
+                               if(slash>=0) {
+                                       Object aal = aalMth.invoke(null/*static*/, _url.substring(slash+1, colon),version);
+                                       return (Locator<URI>)aal;
+                               }
+                       }
+               } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+                       String msg;
+                       char quote;
+                       if(e.getCause()!=null) {
+                               msg=e.getCause().getMessage();
+                               quote='"';
+                       } else {
+                               msg = "-";
+                               quote=' ';
+                       }
+                       access.printf(Level.DEBUG, "Configured AbsAAFLocator not found%c%s%cContinuing Locator creation ",quote,msg,quote);
+               }
 //            String url = _url.replace("/AAF_NS.", "/%C%CID%AAF_NS.");
 //            String root_ns = access.getProperty(Config.AAF_ROOT_NS, null);
                String url;
@@ -877,7 +913,7 @@ public class Config {
                     Method meth = lcls.getMethod("create",Access.class,String.class);
                     locator = (Locator<URI>)meth.invoke(null,access,url);
                 } catch (Exception e) {
-                    access.log(Level.TRACE, "(Not fatal) Cannot load by create(String)", e);
+                    access.log(Level.NONE, "(Not fatal) Cannot load by create(String)", e);
                 }
                 if (locator==null) {
                     URI locatorURI = new URI(url);
@@ -942,6 +978,7 @@ public class Config {
            public static<T> void add(Access access, final String tag, List<Priori<T>> list) {
                    String plugins = access.getProperty(tag, null);
                    if(plugins!=null) {
+                       access.log(Level.INIT, "Adding TAF Plugins: ", plugins);
                        for(String tafs : Split.splitTrim(';', plugins)) {
                                String[] pluginArray = Split.splitTrim(',', tafs);
                                String clssn = null;
@@ -970,7 +1007,12 @@ public class Config {
                                                try {
                                                                        list.add(new Priori<T>(cnst.newInstance(access),priority));
                                                                } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
-                                                                       access.printf(Level.ERROR, "%s cannot be constructed with Access.\n",clssn);
+                                                                       String hostname = access.getProperty(Config.HOSTNAME,null);
+                                                                       if(hostname==null) {
+                                                                               access.printf(Level.ERROR, "%s cannot be constructed on this machine.  Set valid 'hostname' in your properties\n",clssn);       
+                                                                       } else {
+                                                                               access.printf(Level.ERROR, "%s cannot be constructed on %s with Access.\n",clssn, hostname);
+                                                                       }
                                                                }
                                                        } catch (NoSuchMethodException | SecurityException e) {
                                                                access.printf(Level.ERROR, "%s needs a Constructor taking Access as sole param.\n",clssn);