changed to unmaintained
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / config / Config.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.config;
23
24 import java.io.IOException;
25 import java.lang.reflect.Constructor;
26 import java.lang.reflect.Field;
27 import java.lang.reflect.InvocationTargetException;
28 import java.lang.reflect.Method;
29 import java.net.HttpURLConnection;
30 import java.net.InetAddress;
31 import java.net.URI;
32 import java.net.UnknownHostException;
33 import java.security.NoSuchAlgorithmException;
34 import java.security.cert.CertificateException;
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.List;
38
39 import org.onap.aaf.cadi.AbsUserCache;
40 import org.onap.aaf.cadi.Access;
41 import org.onap.aaf.cadi.Access.Level;
42 import org.onap.aaf.cadi.CachingLur;
43 import org.onap.aaf.cadi.CadiException;
44 import org.onap.aaf.cadi.Connector;
45 import org.onap.aaf.cadi.CredVal;
46 import org.onap.aaf.cadi.CredValDomain;
47 import org.onap.aaf.cadi.Locator;
48 import org.onap.aaf.cadi.LocatorException;
49 import org.onap.aaf.cadi.Lur;
50 import org.onap.aaf.cadi.PropAccess;
51 import org.onap.aaf.cadi.Symm;
52 import org.onap.aaf.cadi.TrustChecker;
53 import org.onap.aaf.cadi.lur.EpiLur;
54 import org.onap.aaf.cadi.lur.LocalLur;
55 import org.onap.aaf.cadi.lur.NullLur;
56 import org.onap.aaf.cadi.taf.HttpEpiTaf;
57 import org.onap.aaf.cadi.taf.HttpTaf;
58 import org.onap.aaf.cadi.taf.basic.BasicHttpTaf;
59 import org.onap.aaf.cadi.taf.cert.X509Taf;
60 import org.onap.aaf.cadi.taf.dos.DenialOfServiceTaf;
61 import org.onap.aaf.cadi.util.FixURIinfo;
62 import org.onap.aaf.cadi.util.Split;
63
64 /**
65  * Create a Consistent Configuration mechanism, even when configuration styles
66  * are as vastly different as Properties vs JavaBeans vs FilterConfigs...
67  *
68  * @author Jonathan
69  *
70  */
71 public class Config {
72
73     private static final String AAF_V2_0 = "org.onap.aaf.cadi.aaf.v2_0";
74     private static final String AAF_V2_0_AAFCON = AAF_V2_0 + ".AAFCon";
75     private static final String AAF_V2_0_AAF_LUR_PERM = AAF_V2_0 + ".AAFLurPerm";
76     public static final String AAF_V2_0_AAF_CON_HTTP = AAF_V2_0 + ".AAFConHttp";
77
78     private static final String OAUTH = "org.onap.auth.oauth";
79     private static final String OAUTH_TOKEN_MGR = OAUTH + ".TokenMgr";
80     private static final String OAUTH_HTTP_TAF = OAUTH + ".OAuth2HttpTaf";
81     private static final String OAUTH_DIRECT_TAF = OAUTH + ".OAuthDirectTAF";
82     public static final String UTF_8 = "UTF-8";
83
84     // Property Names associated with configurations.
85     // As of 1.0.2, these have had the dots removed so as to be compatible with
86     // JavaBean style
87     // configurations as well as property list style.
88     public static final String HOSTNAME = "hostname";
89     public static final String CADI_PROP_FILES = "cadi_prop_files"; // Additional Properties files (separate with ;)
90     public static final String CADI_LOGLEVEL = "cadi_loglevel";
91     public static final String CADI_LOGDIR = "cadi_log_dir";
92     public static final String CADI_ETCDIR = "cadi_etc_dir";
93     public static final String CADI_LOGNAME = "cadi_logname";
94     // public static final String CADI_LOGFMT="cad_logging_format";
95     // public static final String CADI_LOGFMT_UTC="UTC";
96     // public static final String CADI_LOGFMT_ISO8601="ISO-8601";
97     public static final String CADI_KEYFILE = "cadi_keyfile";
98     public static final String CADI_KEYSTORE = "cadi_keystore";
99     public static final String CADI_KEYSTORE_PASSWORD = "cadi_keystore_password";
100     public static final String CADI_ALIAS = "cadi_alias";
101     public static final String CADI_CLIENT_ALIAS = "cadi_client_alias";
102     public static final String CADI_LOGINPAGE_URL = "cadi_loginpage_url";
103     public static final String CADI_LATITUDE = "cadi_latitude";
104     public static final String CADI_LONGITUDE = "cadi_longitude";
105
106     public static final String CADI_KEY_PASSWORD = "cadi_key_password";
107     public static final String CADI_TRUSTSTORE = "cadi_truststore";
108     public static final String CADI_TRUSTSTORE_PASSWORD = "cadi_truststore_password";
109     public static final String CADI_X509_ISSUERS = "cadi_x509_issuers";
110     public static final String CADI_TRUST_MASKS = "cadi_trust_masks";
111     public static final String CADI_TRUST_PERM = "cadi_trust_perm"; // IDs with this perm can utilize the "AS " user
112                                                                     // concept
113     public static final String CADI_PROTOCOLS = "cadi_protocols";
114     public static final String CADI_NOAUTHN = "cadi_noauthn";
115     public static final String CADI_LOC_LIST = "cadi_loc_list";
116
117     // Special Behaviors
118     public static final String CADI_BATH_CONVERT = "cadi_bath_convert";
119     public static final String CADI_API_ENFORCEMENT = "cadi_api_enforcement";
120     public static final String CADI_ADD_TAFS = "cadi_add_tafs";
121     public static final String CADI_ADD_LURS = "cadi_add_lurs";
122
123     public static final String CADI_USER_CHAIN_TAG = "cadi_user_chain";
124     public static final String CADI_USER_CHAIN = "USER_CHAIN";
125
126     public static final String CADI_OAUTH2_URL = "cadi_oauth2_url";
127     public static final String CADI_TOKEN_DIR = "cadi_token_dir";
128
129     public static final String HTTPS_PROTOCOLS = "https.protocols";
130     public static final String HTTPS_CLIENT_PROTOCOLS = "jdk.tls.client.protocols";
131     public static final String HTTPS_PROTOCOLS_DEFAULT = "TLSv1.1,TLSv1.2";
132     public static final String HTTPS_CIPHER_SUITES = "https.cipherSuites";
133     public static final String HTTPS_CIPHER_SUITES_DEFAULT = "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,"
134             + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,"
135             + "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,"
136             + "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA,TLS_ECDH_ECDSA_WITH_RC4_128_SHA,"
137             + "TLS_ECDH_RSA_WITH_RC4_128_SHA,TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA,TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,"
138             + "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA,TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA,TLS_EMPTY_RENEGOTIATION_INFO_SCSV";
139
140     public static final String LOCALHOST_ALLOW = "localhost_allow";
141     public static final String LOCALHOST_DENY = "localhost_deny";
142
143     public static final String BASIC_REALM = "basic_realm"; // what is sent to the client
144     public static final String BASIC_WARN = "basic_warn"; // Warning of insecure channel
145     public static final String USERS = "local_users";
146     public static final String GROUPS = "local_groups";
147     public static final String WRITE_TO = "local_writeto"; // dump RBAC to local file in Tomcat Style (some apps use)
148
149     public static final String OAUTH_CLIENT_ID = "client_id";
150     public static final String OAUTH_CLIENT_SECRET = "client_secret";
151
152     public static final String AAF_ENV = "aaf_env";
153     public static final String AAF_ROOT_NS = "aaf_root_ns";
154     public static final String AAF_ROOT_NS_DEF = "org.osaaf.aaf";
155     public static final String AAF_ROOT_COMPANY = "aaf_root_company";
156     /**
157      * Use Config.getAAFLocateUrl(access) to get correct property in/out of
158      * container
159      */
160     public static final String AAF_LOCATE_URL = "aaf_locate_url"; // URL for AAF locator
161     public static final String AAF_LOCATE_URL_TAG = "AAF_LOCATE_URL"; // Name of Above for use in Config Variables.
162     public static final String AAF_DEFAULT_API_VERSION = "2.1";
163     public static final String AAF_DEPLOYED_VERSION = "aaf_deployed_version";
164     public static final String AAF_API_VERSION = "aaf_api_version";
165     public static final String AAF_URL = "aaf_url"; // URL for AAF... Use to trigger AAF configuration
166     public static final String AAF_LOCATOR_CLASS = "aaf_locator_class";
167     // AAF Locator Entries are ADDITIONAL entries, which also gives the Property
168     // ability
169     // to set these entries manually
170     // example: adding a K8S name like "oom"
171     // this will allow Registrations to pick up
172     // locator_ns.oom for onap's "OOM" based k8s entries, etc.
173     public static final String AAF_LOCATOR_CONTAINER = "aaf_locator_container";
174     // An ID for another Container, to be used to avoid picking up the wrong
175     // internal info
176     // for another container.
177     public static final String AAF_LOCATOR_CONTAINER_ID = "aaf_locator_container_id";
178     public static final String AAF_LOCATOR_CONTAINER_NS = "aaf_locator_container_ns";
179     public static final String AAF_LOCATOR_VERSION = "aaf_locator_version";
180     public static final String AAF_LOCATOR_PROTOCOL = "aaf_locator_protocol";
181     public static final String AAF_LOCATOR_SUBPROTOCOL = "aaf_locator_subprotocol";
182     public static final String AAF_LOCATOR_APP_NS = "aaf_locator_app_ns";
183     public static final String AAF_LOCATOR_ENTRIES = "aaf_locator_entries";
184     public static final String AAF_LOCATOR_FQDN = "aaf_locator_fqdn";
185     public static final String AAF_LOCATOR_NAME = "aaf_locator_name";
186     public static final String AAF_LOCATOR_PUBLIC_PORT = "aaf_locator_public_port";
187     public static final String AAF_LOCATOR_PUBLIC_FQDN = "aaf_locator_public_fqdn";
188     public static final String AAF_LOCATOR_PUBLIC_NAME = "aaf_locator_public_name";
189
190     // AAF Service will write to the Audit Log if a past due AAF stored Password
191     // is being used within # of days specified.
192     public static final String AAF_CRED_WARN_DAYS = "aaf_cred_warn_days";
193     public static final String AAF_CRED_WARN_DAYS_DFT = "7";
194
195     public static final String AAF_APPID = "aaf_id";
196     public static final String AAF_APPPASS = "aaf_password";
197     public static final String AAF_LUR_CLASS = "aaf_lur_class";
198     public static final String AAF_TAF_CLASS = "aaf_taf_class";
199     public static final String AAF_CONNECTOR_CLASS = "aaf_connector_class";
200     public static final String AAF_CONN_TIMEOUT = "aaf_conn_timeout";
201     public static final String AAF_CONN_TIMEOUT_DEF = "3000";
202     public static final String AAF_CONN_IDLE_TIMEOUT = "aaf_conn_idle_timeout"; // only for Direct Jetty Access.
203     public static final String AAF_CONN_IDLE_TIMEOUT_DEF = "10000"; // only for Direct Jetty Access.
204
205     // Default Classes: These are for Class loading to avoid direct compile links
206     public static final String AAF_TAF_CLASS_DEF = "org.onap.aaf.cadi.aaf.v2_0.AAFTaf";
207     public static final String AAF_LOCATOR_CLASS_DEF = "org.onap.aaf.cadi.aaf.v2_0.AAFLocator";
208     public static final String AAF_LOCATOR_CLASS_SINGLE = "org.onap.aaf.cadi.locator.SingleEndpointLocator";
209
210     public static final String CADI_OLUR_CLASS_DEF = "org.onap.aaf.cadi.olur.OLur";
211     public static final String CADI_OBASIC_HTTP_TAF_DEF = "org.onap.aaf.cadi.obasic.OBasicHttpTaf";
212     public static final String CADI_AAF_CON_DEF = "org.onap.aaf.cadi.aaf.v2_0.AAFCon";
213
214     public static final String AAF_CALL_TIMEOUT = "aaf_timeout";
215     public static final String AAF_CALL_TIMEOUT_DEF = "5000";
216     public static final String AAF_USER_EXPIRES = "aaf_user_expires";
217     public static final String AAF_USER_EXPIRES_DEF = "600000"; // Default is 10 mins
218     public static final String AAF_CLEAN_INTERVAL = "aaf_clean_interval";
219     public static final String AAF_CLEAN_INTERVAL_DEF = "30000"; // Default is 30 seconds
220     public static final String AAF_REFRESH_TRIGGER_COUNT = "aaf_refresh_trigger_count";
221     public static final String AAF_REFRESH_TRIGGER_COUNT_DEF = "3"; // Default is 10 mins
222
223     public static final String AAF_HIGH_COUNT = "aaf_high_count";
224     public static final String AAF_HIGH_COUNT_DEF = "1000"; // Default is 1000 entries
225     public static final String AAF_PERM_MAP = "aaf_perm_map";
226     // public static final String AAF_COMPONENT = "aaf_component";
227     public static final String AAF_CERT_IDS = "aaf_cert_ids";
228     public static final String AAF_DEBUG_IDS = "aaf_debug_ids"; // comma delimited
229     public static final String AAF_DATA_DIR = "aaf_data_dir"; // AAF processes and Components only.
230
231     public static final String AAF_URL_OAUTH = "aaf_url_oauth";
232     public static final String AAF_URL_GUI = "aaf_url_gui";
233     public static final String AAF_URL_FS = "aaf_url_fs";
234     public static final String AAF_URL_CM = "aaf_url_cm";
235     public static final String AAF_URL_CM_DEF = "https://AAF_LOCATE_URL/AAF_NS.cm:" + AAF_DEFAULT_API_VERSION;
236     public static final String AAF_URL_HELLO = "aaf_url_hello";
237     public static final String CM_TRUSTED_CAS = "cm_trusted_cas";
238     // let NS Owners choose with <ns>.certman aaf ignoreIPs" to ignoreIP Check for
239     // Configs
240     // Probably only want to allow in a DEV Env.
241     public static final String CM_ALLOW_IGNORE_IPS = "cm_allow_ignore_ips";
242     // Docker doesn't have a default DNS. The property turns off IP Checking of DNSs
243     // before creating.
244     public static final String CM_ALWAYS_IGNORE_IPS = "cm_always_ignore_ips";
245
246     public static final String PATHFILTER_URLPATTERN = "pathfilter_urlpattern";
247     public static final String PATHFILTER_STACK = "pathfilter_stack";
248     public static final String PATHFILTER_NS = "pathfilter_ns";
249     public static final String PATHFILTER_NOT_AUTHORIZED_MSG = "pathfilter_not_authorized_msg";
250
251     // This one should go unpublic
252     public static final String AAF_DEFAULT_REALM = "aaf_default_realm";
253     private static String defaultRealm = "people.osaaf.org";
254
255     public static final String AAF_DOMAIN_SUPPORT = "aaf_domain_support";
256     public static final String AAF_DOMAIN_SUPPORT_DEF = ".com:.org";
257
258     // OAUTH2
259     public static final String AAF_OAUTH2_TOKEN_URL = "aaf_oauth2_token_url";
260     public static final String AAF_OAUTH2_INTROSPECT_URL = "aaf_oauth2_introspect_url";
261     public static final String AAF_ALT_OAUTH2_TOKEN_URL = "aaf_alt_oauth2_token_url";
262     public static final String AAF_ALT_OAUTH2_INTROSPECT_URL = "aaf_alt_oauth2_introspect_url";
263     public static final String AAF_ALT_OAUTH2_DOMAIN = "aaf_alt_oauth2_domain";
264     public static final String AAF_ALT_CLIENT_ID = "aaf_alt_oauth2_client_id";
265     public static final String AAF_ALT_CLIENT_SECRET = "aaf_alt_oauth2_client_secret";
266     public static final String AAF_OAUTH2_HELLO_URL = "aaf_oauth2_hello_url";
267     
268     public static void setDefaultRealm(Access access) {
269         try {
270             defaultRealm = logProp(access, Config.AAF_DEFAULT_REALM, logProp(access, Config.BASIC_REALM,
271                     logProp(access, HOSTNAME, InetAddress.getLocalHost().getHostName())));
272         } catch (UnknownHostException e) {
273             access.log(Level.INIT, "Unable to determine Hostname", e);
274         }
275     }
276
277     public static HttpTaf configHttpTaf(Connector con, SecurityInfoC<HttpURLConnection> si, TrustChecker tc, CredVal up,
278             Lur lur, Object... additionalTafLurs) throws CadiException, LocatorException {
279         Access access = si.access;
280         RegistrationPropHolder rph;
281         try {
282             rph = new RegistrationPropHolder(access, 0);
283         } catch (UnknownHostException e2) {
284             throw new CadiException(e2);
285         }
286         /////////////////////////////////////////////////////
287         // Setup AAFCon for any following
288         /////////////////////////////////////////////////////
289         Class<?> aafConClass = loadClass(access, CADI_AAF_CON_DEF);
290         Object aafcon = null;
291         if (con != null && aafConClass != null && aafConClass.isAssignableFrom(con.getClass())) {
292             aafcon = con;
293         } else if (lur != null) {
294             Field f;
295             try {
296                 f = lur.getClass().getField("aaf");
297                 aafcon = f.get(lur);
298             } catch (Exception e) {
299                 access.log(Level.INIT, e);
300             }
301         }
302
303         boolean hasDirectAAF = hasDirect("DirectAAFLur", additionalTafLurs);
304         // IMPORTANT! Don't attempt to load AAF Connector if there is no AAF URL
305         String aafURL = logProp(rph, AAF_URL, null);
306         if (!hasDirectAAF && aafcon == null && aafURL != null) {
307             aafcon = loadAAFConnector(si, aafURL);
308         }
309
310         HttpTaf taf;
311         // Setup Host, in case Network reports an unusable Hostname (i.e. VTiers, VPNs,
312         // etc)
313         String hostname = logProp(access, HOSTNAME, null);
314         if (hostname == null) {
315             try {
316                 hostname = InetAddress.getLocalHost().getHostName();
317             } catch (UnknownHostException e1) {
318                 throw new CadiException("Unable to determine Hostname", e1);
319             }
320         }
321
322         access.log(Level.INIT, "Hostname set to", hostname);
323         // Get appropriate TAFs
324         ArrayList<Priori<HttpTaf>> htlist = new ArrayList<>();
325
326         /////////////////////////////////////////////////////
327         // Add a Denial of Service TAF
328         // Note: how IPs and IDs are added are up to service type.
329         // They call "DenialOfServiceTaf.denyIP(String) or denyID(String)
330         /////////////////////////////////////////////////////
331         htlist.add(new Priori<HttpTaf>(new DenialOfServiceTaf(access), 0));
332
333         /////////////////////////////////////////////////////
334         // Configure Client Cert TAF
335         /////////////////////////////////////////////////////
336         X509Taf x509TAF = null;
337         String truststore = logProp(access, CADI_TRUSTSTORE, null);
338         if (truststore != null) {
339             String truststorePwd = access.getProperty(CADI_TRUSTSTORE_PASSWORD, null);
340             if (truststorePwd != null) {
341                 if (truststorePwd.startsWith(Symm.ENC)) {
342                     try {
343                         access.decrypt(truststorePwd, false);
344                     } catch (IOException e) {
345                         throw new CadiException(CADI_TRUSTSTORE_PASSWORD + " cannot be decrypted", e);
346                     }
347                 }
348                 try {
349                     x509TAF = new X509Taf(access, lur);
350                     htlist.add(new Priori<HttpTaf>(x509TAF, 10));
351                     access.log(Level.INIT, "Certificate Authorization enabled");
352                 } catch (SecurityException | IllegalArgumentException e) {
353                     access.log(Level.INIT,
354                             "AAFListedCertIdentity cannot be instantiated. Certificate Authorization is now disabled",
355                             e);
356                 } catch (CertificateException e) {
357                     access.log(Level.INIT, "Certificate Authorization failed, it is disabled", e);
358                 } catch (NoSuchAlgorithmException e) {
359                     access.log(Level.INIT, "Certificate Authorization failed, wrong Security Algorithm", e);
360                 }
361             }
362         } else {
363             access.log(Level.INIT, "Certificate Authorization not enabled");
364         }
365
366         /////////////////////////////////////////////////////
367         // Configure Basic Auth (local content)
368         /////////////////////////////////////////////////////
369         boolean hasOAuthDirectTAF = hasDirect("DirectOAuthTAF", additionalTafLurs);
370         String basicRealm = logProp(access, BASIC_REALM, null);
371         String aafCleanup = logProp(access, AAF_USER_EXPIRES, AAF_USER_EXPIRES_DEF); // Default is 10 mins
372         long userExp = Long.parseLong(aafCleanup);
373         boolean basicWarn = "TRUE".equals(access.getProperty(BASIC_WARN, "FALSE"));
374
375         if (!hasDirectAAF) {
376             HttpTaf aaftaf = null;
377             if (!hasOAuthDirectTAF) {
378                 if (basicRealm != null) {
379                     @SuppressWarnings("unchecked")
380                     Class<HttpTaf> obasicCls = (Class<HttpTaf>) loadClass(access, CADI_OBASIC_HTTP_TAF_DEF);
381                     if (obasicCls != null) {
382                         try {
383                             String tokenurl = logProp(rph, Config.AAF_OAUTH2_TOKEN_URL, null);
384                             String introspecturl = logProp(rph, Config.AAF_OAUTH2_INTROSPECT_URL, null);
385                             if (tokenurl == null || introspecturl == null) {
386                                 access.log(Level.INIT,
387                                         "Both tokenurl and introspecturl are required. Oauth Authorization is disabled.");
388                             } else {
389                                 // try to construct the TAF instance.  Try without the CredVal first (original code), change
390                                 // to try with a CredVal paramater if it fails as the newer ONAP code contains this in the OBasicHttpTaf constructor
391                                 System.out.println("TokenURL="+ tokenurl + "; IntrospectURL="+introspecturl);
392                                 Constructor<HttpTaf> obasicConst = null;
393                                 try {
394                                     obasicConst = obasicCls.getConstructor(PropAccess.class, String.class,
395                                         String.class, String.class);
396                                     htlist.add(new Priori<HttpTaf>(
397                                             obasicConst.newInstance(access, basicRealm, tokenurl, introspecturl), 20));
398                                 } catch (Exception e) {
399                                     obasicConst = obasicCls.getConstructor(PropAccess.class, CredVal.class, String.class, String.class, String.class);
400                                     htlist.add(new Priori<HttpTaf>(
401                                         obasicConst.newInstance(access, up, basicRealm, tokenurl, introspecturl), 20));
402                                 }
403
404                                 access.log(Level.INIT, "Oauth supported Basic Authorization is enabled");
405                             }
406                         } catch (NoSuchMethodException | SecurityException | InstantiationException
407                                 | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
408                             access.log(Level.INIT, e);
409                         }
410                     } else if (up != null) {
411                         access.log(Level.INIT, "Basic Authorization is enabled using realm", basicRealm);
412                         // Allow warning about insecure channel to be turned off
413                         if (!basicWarn) {
414                             access.log(Level.INIT, "WARNING! The basicWarn property has been set to false.",
415                                     " There will be no additional warning if Basic Auth is used on an insecure channel");
416                         }
417                         BasicHttpTaf bht = new BasicHttpTaf(access, up, basicRealm, userExp, basicWarn);
418                         for (Object o : additionalTafLurs) {
419                             if (o instanceof CredValDomain) {
420                                 bht.add((CredValDomain) o);
421                             }
422                         }
423                         if (x509TAF != null) {
424                             x509TAF.add(bht);
425                         }
426                         htlist.add(new Priori<HttpTaf>(bht, 20));
427                         access.log(Level.INIT, "Basic Authorization is enabled");
428                     }
429                 } else {
430                     access.log(Level.INIT,
431                             "Local Basic Authorization is disabled.  Enable by setting basicRealm=<appropriate realm, i.e. my.att.com>");
432                 }
433
434                 /////////////////////////////////////////////////////
435                 // Configure AAF Driven Basic Auth
436                 /////////////////////////////////////////////////////
437                 if (aafcon == null) {
438                     access.log(Level.INIT, "AAF Connection (AAFcon) is null.  Cannot create an AAF TAF");
439                 } else if (aafURL == null) {
440                     access.log(Level.INIT, "No AAF URL in properties, Cannot create an AAF TAF");
441                 } else {// There's an AAF_URL... try to configure an AAF
442                     String aafTafClassName = logProp(access, AAF_TAF_CLASS, AAF_TAF_CLASS_DEF);
443                     // Only 2.0 available at this time
444                     if (AAF_TAF_CLASS_DEF.equals(aafTafClassName)) {
445                         try {
446                             Class<?> aafTafClass = loadClass(access, aafTafClassName);
447                             if (aafTafClass != null) {
448                                 Constructor<?> cstr = aafTafClass.getConstructor(Connector.class, boolean.class,
449                                         AbsUserCache.class);
450                                 if (cstr != null) {
451                                     if (lur instanceof AbsUserCache) {
452                                         aaftaf = (HttpTaf) cstr.newInstance(aafcon, basicWarn, lur);
453                                     } else {
454                                         cstr = aafTafClass.getConstructor(Connector.class, boolean.class);
455                                         if (cstr != null) {
456                                             aaftaf = (HttpTaf) cstr.newInstance(aafcon, basicWarn);
457                                         }
458                                     }
459                                     if (aaftaf == null) {
460                                         access.log(Level.INIT, "ERROR! AAF TAF Failed construction.  NOT Configured");
461                                     } else {
462                                         access.log(Level.INIT, "AAF TAF Configured to ", aafURL);
463                                         // Note: will add later, after all others configured
464                                     }
465                                 }
466                             } else {
467                                 access.log(Level.INIT,
468                                         "There is no AAF TAF class available: %s. AAF TAF not configured.",
469                                         aafTafClassName);
470                             }
471                         } catch (Exception e) {
472                             access.log(Level.INIT, "ERROR! AAF TAF Failed construction.  NOT Configured", e);
473                         }
474                     }
475                 }
476             }
477
478             /////////////////////////////////////////////////////
479             // Configure OAuth TAF
480             /////////////////////////////////////////////////////
481             if (!hasOAuthDirectTAF) {
482                 String oauthTokenUrl = logProp(rph, Config.AAF_OAUTH2_TOKEN_URL, null);
483                 Class<?> oadtClss;
484                 try {
485                     oadtClss = Class.forName(OAUTH_DIRECT_TAF);
486                 } catch (ClassNotFoundException e1) {
487                     oadtClss = null;
488                     access.log(Level.DEBUG, e1);
489                 }
490                 if (additionalTafLurs != null && additionalTafLurs.length > 0
491                         && (oadtClss != null && additionalTafLurs[0].getClass().isAssignableFrom(oadtClss))) {
492                     htlist.add(new Priori<HttpTaf>((HttpTaf) additionalTafLurs[0], 30));
493                     String[] array = new String[additionalTafLurs.length - 1];
494                     if (array.length > 0) {
495                         System.arraycopy(htlist, 1, array, 0, array.length);
496                     }
497                     additionalTafLurs = array;
498                     access.log(Level.INIT, "OAuth2 Direct is enabled");
499                 } else if (oauthTokenUrl != null) {
500                     String oauthIntrospectUrl = logProp(rph, Config.AAF_OAUTH2_INTROSPECT_URL, null);
501                     @SuppressWarnings("unchecked")
502                     Class<HttpTaf> oaTCls = (Class<HttpTaf>) loadClass(access, OAUTH_HTTP_TAF);
503                     if (oaTCls != null) {
504                         Class<?> oaTTmgrCls = loadClass(access, OAUTH_TOKEN_MGR);
505                         if (oaTTmgrCls != null) {
506                             try {
507                                 Method oaTTmgrGI = oaTTmgrCls.getMethod("getInstance", PropAccess.class, String.class,
508                                         String.class);
509                                 Object oaTTmgr = oaTTmgrGI.invoke(null /* this is static method */, access,
510                                         oauthTokenUrl, oauthIntrospectUrl);
511                                 Constructor<HttpTaf> oaTConst = oaTCls.getConstructor(Access.class, oaTTmgrCls);
512                                 htlist.add(new Priori<HttpTaf>(oaTConst.newInstance(access, oaTTmgr), 30));
513                                 access.log(Level.INIT, "OAuth2 TAF is enabled");
514                             } catch (NoSuchMethodException | SecurityException | IllegalAccessException
515                                     | IllegalArgumentException | InvocationTargetException | InstantiationException e) {
516                                 access.log(Level.INIT, "OAuth2HttpTaf cannot be instantiated. OAuth2 is disabled", e);
517                             }
518                         }
519                     }
520                 } else {
521                     access.log(Level.INIT, "OAuth TAF is not configured");
522                 }
523             }
524
525             /////////////////////////////////////////////////////
526             // Adding BasicAuth (AAF) last, after other primary Cookie Based
527             // Needs to be before Cert... see below
528             /////////////////////////////////////////////////////
529             if (aaftaf != null) {
530                 htlist.add(new Priori<HttpTaf>(aaftaf, 40));
531             }
532         }
533
534         /////////////////////////////////////////////////////
535         // Any Additional Tafs passed in Constructor
536         /////////////////////////////////////////////////////
537         if (additionalTafLurs != null) {
538             int i = 0;
539             for (Object additional : additionalTafLurs) {
540                 if (additional instanceof BasicHttpTaf) {
541                     BasicHttpTaf ht = (BasicHttpTaf) additional;
542                     for (Object cv : additionalTafLurs) {
543                         if (cv instanceof CredValDomain) {
544                             ht.add((CredValDomain) cv);
545                             access.printf(Level.INIT, "%s Authentication is enabled", cv);
546                         }
547                     }
548                     htlist.add(new Priori<HttpTaf>(ht, 50 + i++));
549                 } else if (additional instanceof HttpTaf) {
550                     HttpTaf ht = (HttpTaf) additional;
551                     htlist.add(new Priori<HttpTaf>(ht, 50 + i++));
552                     access.printf(Level.INIT, "%s Authentication is enabled", additional.getClass().getSimpleName());
553                 } else if (hasOAuthDirectTAF) {
554                     Class<?> daupCls;
555                     try {
556                         daupCls = Class.forName("org.onap.aaf.auth.direct.DirectAAFUserPass");
557                     } catch (ClassNotFoundException e) {
558                         daupCls = null;
559                         access.log(Level.INIT, e);
560                     }
561                     if (daupCls != null && additional.getClass().isAssignableFrom(daupCls)) {
562                         htlist.add(new Priori<HttpTaf>(
563                                 new BasicHttpTaf(access, (CredVal) additional, basicRealm, userExp, basicWarn),
564                                 50 + i++));
565                         access.printf(Level.INIT, "Direct BasicAuth Authentication is enabled",
566                                 additional.getClass().getSimpleName());
567                     }
568                 }
569             }
570         }
571
572         // Add BasicAuth, if any, to x509Taf
573         if (x509TAF != null) {
574             for (Priori<HttpTaf> ht : htlist) {
575                 if (ht.t instanceof BasicHttpTaf) {
576                     x509TAF.add((BasicHttpTaf) ht.t);
577                 }
578             }
579         }
580
581         /////////////////////////////////////////////////////
582         // Additional TAFs by Plugin
583         /////////////////////////////////////////////////////
584         Priori.add(access, CADI_ADD_TAFS, htlist);
585
586         /////////////////////////////////////////////////////
587         // Create EpiTaf from configured TAFs
588         /////////////////////////////////////////////////////
589         if (htlist.size() == 1) {
590             // just return the one
591             taf = htlist.get(0).t;
592         } else {
593             Collections.sort(htlist);
594             HttpTaf[] htarray = new HttpTaf[htlist.size()];
595             int i = -1;
596             StringBuilder sb = new StringBuilder("Tafs processed in this order:\n");
597             for (Priori<HttpTaf> pht : htlist) {
598                 htarray[++i] = pht.t;
599                 sb.append("    ");
600                 sb.append(pht.t.getClass().getName());
601                 sb.append('(');
602                 sb.append(pht.priority);
603                 sb.append(")\n");
604             }
605             access.log(Level.INIT, sb);
606
607             Locator<URI> locator = loadLocator(si, aafURL);
608
609             taf = new HttpEpiTaf(access, locator, tc, htarray); // ok to pass locator == null
610             String level = logProp(access, CADI_LOGLEVEL, null);
611             if (level != null) {
612                 access.setLogLevel(Level.valueOf(level));
613             }
614         }
615
616         return taf;
617     }
618
619     public static String logProp(RegistrationPropHolder rph, String tag, String def) {
620         String rv = rph.access().getProperty(tag, def);
621         if (rv == null) {
622             rph.access().log(Level.INIT, tag, "is not explicitly set");
623         } else {
624             rv = rph.replacements("Config.logProp", rv, null, null);
625             rph.access().log(Level.INIT, tag, "is set to", rv);
626         }
627         return rv;
628
629     }
630
631     public static String logProp(Access access, String tag, String def) {
632         String rv = access.getProperty(tag, def);
633         if (rv == null) {
634             access.log(Level.INIT, tag, "is not explicitly set");
635         } else {
636             access.log(Level.INIT, tag, "is set to", rv);
637         }
638         return rv;
639     }
640
641     public static Lur configLur(SecurityInfoC<HttpURLConnection> si, Connector con, Object... additionalTafLurs)
642             throws CadiException {
643         Access access = si.access;
644         RegistrationPropHolder rph;
645         try {
646             rph = new RegistrationPropHolder(access, 0);
647         } catch (UnknownHostException e2) {
648             throw new CadiException(e2);
649         }
650
651         List<Priori<Lur>> lurs = new ArrayList<>();
652
653         /////////////////////////////////////////////////////
654         // Configure a Local Property Based RBAC/LUR
655         /////////////////////////////////////////////////////
656         try {
657             String users = access.getProperty(USERS, null);
658             String groups = access.getProperty(GROUPS, null);
659
660             if (groups != null || users != null) {
661                 LocalLur ll = new LocalLur(access, users, groups); // note b64==null is ok.. just means no encryption.
662                 lurs.add(new Priori<Lur>(ll, 10));
663
664                 String writeto = access.getProperty(WRITE_TO, null);
665                 if (writeto != null) {
666                     String msg = UsersDump.updateUsers(writeto, ll);
667                     if (msg != null) {
668                         access.log(Level.INIT, "ERROR! Error Updating ", writeto, "with roles and users:", msg);
669                     }
670                 }
671             }
672         } catch (IOException e) {
673             throw new CadiException(e);
674         }
675
676         /////////////////////////////////////////////////////
677         // Configure the OAuth Lur (if any)
678         /////////////////////////////////////////////////////
679         String tokenUrl = logProp(rph, AAF_OAUTH2_TOKEN_URL, null);
680         String introspectUrl = logProp(rph, AAF_OAUTH2_INTROSPECT_URL, null);
681         if (tokenUrl != null && introspectUrl != null) {
682             try {
683                 Class<?> olurCls = loadClass(access, CADI_OLUR_CLASS_DEF);
684                 if (olurCls != null) {
685                     Constructor<?> olurCnst = olurCls.getConstructor(PropAccess.class, String.class, String.class);
686                     Lur olur = (Lur) olurCnst.newInstance(access, tokenUrl, introspectUrl);
687                     lurs.add(new Priori<Lur>(olur, 20));
688                     access.log(Level.INIT, "OAuth2 LUR enabled");
689                 } else {
690                     access.log(Level.INIT, "AAF/OAuth LUR plugin is not available.");
691                 }
692             } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
693                     | IllegalArgumentException | InvocationTargetException e) {
694                 String msg = e.getMessage();
695                 if (msg == null && e.getCause() != null) {
696                     msg = e.getCause().getMessage();
697                 }
698                 access.log(Level.INIT, "AAF/OAuth LUR is not instantiated.", msg, e);
699             }
700         } else {
701             access.log(Level.INIT, "OAuth2 Lur disabled");
702         }
703
704         if (con != null) { // try to reutilize connector
705             lurs.add(new Priori<Lur>(con.newLur(), 30));
706         } else {
707             /////////////////////////////////////////////////////
708             // Configure the AAF Lur (if any)
709             /////////////////////////////////////////////////////
710             String aafURL = logProp(rph, AAF_URL, null); // Trigger Property
711             String aafEnv = access.getProperty(AAF_ENV, null);
712             if (aafEnv == null && aafURL != null && access instanceof PropAccess) { // set AAF_ENV from AAF_URL
713                 int ec = aafURL.indexOf("envContext=");
714                 if (ec > 0) {
715                     ec += 11; // length of envContext=
716                     int slash = aafURL.indexOf('/', ec);
717                     if (slash > 0) {
718                         aafEnv = aafURL.substring(ec, slash);
719                         ((PropAccess) access).setProperty(AAF_ENV, aafEnv);
720                         access.printf(Level.INIT, "Setting aafEnv to %s from aaf_url value", aafEnv);
721                     }
722                 }
723             }
724
725             // Don't configure AAF if it is using DirectAccess
726             if (!hasDirect("DirectAAFLur", additionalTafLurs)) {
727                 if (aafURL == null) {
728                     access.log(Level.INIT, "No AAF LUR properties, AAF will not be loaded");
729                 } else {// There's an AAF_URL... try to configure an AAF
730                     String aafLurClassStr = logProp(access, AAF_LUR_CLASS, AAF_V2_0_AAF_LUR_PERM);
731                     //////////// AAF Lur 2.0 /////////////
732                     if (aafLurClassStr != null && aafLurClassStr.startsWith(AAF_V2_0)) {
733                         try {
734                             Object aafcon = loadAAFConnector(si, aafURL);
735                             if (aafcon == null) {
736                                 access.log(Level.INIT, "AAF LUR class,", aafLurClassStr,
737                                         "cannot be constructed without valid AAFCon object.");
738                             } else {
739                                 Class<?> aafAbsAAFCon = loadClass(access, AAF_V2_0_AAFCON);
740                                 if (aafAbsAAFCon != null) {
741                                     Method mNewLur = aafAbsAAFCon.getMethod("newLur");
742                                     Object aaflur = mNewLur.invoke(aafcon);
743
744                                     if (aaflur == null) {
745                                         access.log(Level.INIT, "ERROR! AAF LUR Failed construction.  NOT Configured");
746                                     } else {
747                                         access.log(Level.INIT, "AAF LUR Configured to ", aafURL);
748                                         lurs.add(new Priori<Lur>((Lur) aaflur, 40));
749                                         String debugIDs = logProp(access, Config.AAF_DEBUG_IDS, null);
750                                         if (debugIDs != null && aaflur instanceof CachingLur) {
751                                             ((CachingLur<?>) aaflur).setDebug(debugIDs);
752                                         }
753                                     }
754                                 }
755                             }
756                         } catch (Exception e) {
757                             access.log(e, "AAF LUR class,", aafLurClassStr,
758                                     "could not be constructed with given Constructors.");
759                         }
760                     }
761                 }
762             }
763         }
764
765         /////////////////////////////////////////////////////
766         // Any Additional passed in Constructor
767         /////////////////////////////////////////////////////
768         if (additionalTafLurs != null) {
769             int i = 0;
770             for (Object additional : additionalTafLurs) {
771                 if (additional instanceof Lur) {
772                     lurs.add(new Priori<Lur>((Lur) additional, 50 + i++));
773                     access.log(Level.INIT, additional);
774                 }
775             }
776         }
777
778         /////////////////////////////////////////////////////
779         // Additional LURs by Plugin
780         /////////////////////////////////////////////////////
781         Priori.add(access, CADI_ADD_LURS, lurs);
782
783         /////////////////////////////////////////////////////
784         // Return a Lur based on how many there are...
785         /////////////////////////////////////////////////////
786         switch (lurs.size()) {
787             case 0:
788                 access.log(Level.INIT, "WARNING! No CADI LURs configured");
789                 // Return a NULL Lur that does nothing.
790                 return new NullLur();
791             case 1:
792                 return lurs.get(0).t; // Only one, just return it, save processing
793             default:
794                 // Multiple Lurs, use EpiLUR to handle
795                 Collections.sort(lurs);
796                 Lur[] la = new Lur[lurs.size()];
797                 int i = -1;
798                 StringBuilder sb = new StringBuilder("Lurs processed in this order:\n");
799                 for (Priori<Lur> pht : lurs) {
800                     la[++i] = pht.t;
801                     sb.append("    ");
802                     sb.append(pht.t.getClass().getName());
803                     sb.append('(');
804                     sb.append(pht.priority);
805                     sb.append(")\n");
806                 }
807                 access.log(Level.INIT, sb);
808                 return new EpiLur(la);
809         }
810     }
811
812     private static boolean hasDirect(String simpleClassName, Object[] additionalTafLurs) {
813         if (additionalTafLurs != null) {
814             for (Object tf : additionalTafLurs) {
815                 if (tf.getClass().getSimpleName().equals(simpleClassName)) {
816                     return true;
817                 }
818             }
819         }
820         return false;
821     }
822
823     @SuppressWarnings("unchecked")
824     public static Object loadAAFConnector(SecurityInfoC<?> si, String aafURL) {
825         Access access = si.access;
826         Object aafcon = null;
827         Class<?> aafConClass = null;
828
829         try {
830             if (aafURL != null) {
831                 String aafConnector = access.getProperty(AAF_CONNECTOR_CLASS, AAF_V2_0_AAF_CON_HTTP);
832                 if (AAF_V2_0_AAF_CON_HTTP.equals(aafConnector)) {
833                     aafConClass = loadClass(access, AAF_V2_0_AAF_CON_HTTP);
834                     if (aafConClass != null) {
835                         for (Constructor<?> c : aafConClass.getConstructors()) {
836                             List<Object> lo = new ArrayList<>();
837                             for (Class<?> pc : c.getParameterTypes()) {
838                                 if (pc.equals(Access.class)) {
839                                     lo.add(access);
840                                 } else if (pc.equals(Locator.class)) {
841                                     lo.add(loadLocator((SecurityInfoC<HttpURLConnection>) si, aafURL));
842                                 }
843                             }
844                             if (c.getParameterTypes().length != lo.size()) {
845                                 continue; // back to another Constructor
846                             } else {
847                                 aafcon = c.newInstance(lo.toArray());
848                             }
849                             break;
850                         }
851                     }
852                 }
853                 if (aafcon != null) {
854                     String mechid = logProp(access, Config.AAF_APPID, null);
855                     String pass = access.getProperty(Config.AAF_APPPASS, null);
856                     if (mechid != null && pass != null) {
857                         try {
858                             Method basicAuth = aafConClass.getMethod("basicAuth", String.class, String.class);
859                             basicAuth.invoke(aafcon, mechid, pass);
860                         } catch (NoSuchMethodException nsme) {
861                             access.log(Level.NONE, nsme);
862                             // it's ok, don't use
863                         }
864                     }
865                 }
866             }
867         } catch (Exception e) {
868             access.log(e, "AAF Connector could not be constructed with given Constructors.");
869         }
870
871         return aafcon;
872     }
873
874     public static Class<?> loadClass(Access access, String className) {
875         Class<?> cls = null;
876         try {
877             cls = access.classLoader().loadClass(className);
878         } catch (ClassNotFoundException cnfe) {
879             access.log(Level.NONE, cnfe);
880             try {
881                 cls = access.getClass().getClassLoader().loadClass(className);
882             } catch (ClassNotFoundException cnfe2) {
883                 access.log(Level.NONE, cnfe2);
884                 // just return null
885             }
886         }
887         return cls;
888     }
889
890     @SuppressWarnings("unchecked")
891     public static Locator<URI> loadLocator(SecurityInfoC<HttpURLConnection> si, final String _url)
892             throws LocatorException {
893         Access access = si.access;
894         Locator<URI> locator = null;
895         if (_url == null) {
896             access.log(Level.INIT, "No URL passed to 'loadLocator'. Disabled");
897         } else {
898             try {
899                 Class<?> aalCls = Class.forName("org.onap.aaf.cadi.aaf.v2_0.AbsAAFLocator");
900                 Method aalMth = aalCls.getMethod("create", String.class, String.class);
901                 int colon = _url.lastIndexOf(':');
902                 if (colon >= 0) {
903                     int slash = _url.indexOf('/', colon);
904                     String version;
905                     if (slash < 0) {
906                         version = _url.substring(colon + 1);
907                     } else {
908                         version = _url.substring(colon + 1, slash);
909                     }
910                     slash = _url.lastIndexOf('/', colon);
911                     if (slash >= 0) {
912                         Object aal = aalMth.invoke(null/* static */, _url.substring(slash + 1, colon), version);
913                         return (Locator<URI>) aal;
914                     }
915                 }
916             } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException
917                     | IllegalArgumentException | InvocationTargetException e) {
918                 String msg;
919                 char quote;
920                 if (e.getCause() != null) {
921                     msg = e.getCause().getMessage();
922                     quote = '"';
923                 } else {
924                     msg = "-";
925                     quote = ' ';
926                 }
927                 access.printf(Level.DEBUG, "Configured AbsAAFLocator not found%c%s%cContinuing Locator creation ",
928                         quote, msg, quote);
929             }
930             // String url = _url.replace("/AAF_NS.", "/%C%CID%AAF_NS.");
931             // String root_ns = access.getProperty(Config.AAF_ROOT_NS, null);
932             String url;
933             RegistrationPropHolder rph;
934             try {
935                 rph = new RegistrationPropHolder(access, 0);
936                 url = rph.replacements("Config.loadLocator", _url, null, null);
937                 access.printf(Level.INFO, "loadLocator URL is %s", url);
938             } catch (UnknownHostException | CadiException e1) {
939                 throw new LocatorException(e1);
940             }
941
942             /**
943              * Simplify logic - if we have a URL with /locate/ in it, we use the default locator.
944              * If we have an explicitly set locator from configuration, we use that one.
945              * Otherwise we fall back to the SingleEndpointLocator, basically default normal HTTP client behavior.
946              */
947             String aaf_locator_class = null;
948             if (url.contains("/locate/")) {
949                 aaf_locator_class = AAF_LOCATOR_CLASS_DEF;
950             } else if (si.access.getProperty(Config.AAF_LOCATOR_CLASS, null) != null) {
951                 aaf_locator_class = si.access.getProperty(Config.AAF_LOCATOR_CLASS, null);
952             }
953             if (aaf_locator_class == null) {
954                 aaf_locator_class = Config.AAF_LOCATOR_CLASS_SINGLE; 
955             }
956
957             try {
958                 Class<?> lcls = loadClass(access,aaf_locator_class);
959                 if (lcls==null) {
960                     throw new CadiException("Need to include aaf-cadi-aaf jar for AAFLocator");
961                 }
962                 // First check for preloaded
963                 try {
964                     Method meth = lcls.getMethod("create",Access.class,String.class);
965                     locator = (Locator<URI>)meth.invoke(null,access,url);
966                 } catch (Exception e) {
967                     access.log(Level.NONE, "(Not fatal) Cannot load by create(String)", e);
968                 }
969                 if (locator==null) {
970                     URI locatorURI = new URI(url);
971                     FixURIinfo fui = new FixURIinfo(locatorURI);
972                     Constructor<?> cnst = lcls.getConstructor(SecurityInfoC.class,URI.class);
973                     locator = (Locator<URI>)cnst.newInstance(new Object[] {si,locatorURI});
974                     int port = fui.getPort();
975                     String portS = port<0?"":(":"+port);
976
977                     access.log(Level.INFO, "AAFLocator [" + locator.getClass().getSimpleName() + "] enabled using " + locatorURI.getScheme() +"://"+fui.getHost() + portS);
978                 } else {
979                     access.log(Level.INFO, "AAFLocator [" + locator.getClass().getSimpleName() + "] enabled using " + url);
980                 }
981             } catch (InvocationTargetException e) {
982                 if (e.getTargetException() instanceof LocatorException) {
983                     throw (LocatorException)e.getTargetException();
984                 }
985                 access.log(Level.INIT,e.getTargetException().getMessage(),"AAFLocator for",url,"could not be created.",e);
986             } catch (Exception e) {
987                 access.log(Level.INIT,"AAFLocator for",url,"could not be created.",e);
988             }
989         }
990         return locator;
991     }
992
993     // Set by CSP, or is hostname.
994     public static String getDefaultRealm() {
995         return defaultRealm;
996     }
997
998     public static String getAAFLocateUrl(Access access) {
999         String rv = null;
1000         String cont = access.getProperty(AAF_LOCATOR_CONTAINER,null);
1001         if(cont!=null) {
1002             rv = access.getProperty(AAF_LOCATE_URL + '.' +cont, null);
1003         }
1004         if(rv==null) {
1005             rv = access.getProperty(AAF_LOCATE_URL, null);
1006         }
1007         return rv;
1008     }
1009
1010     private static class Priori<T> implements Comparable<Priori<T>> {
1011         public final T t;
1012         public final int priority;
1013
1014         public Priori(final T t, final int priority) {
1015             this.t = t;
1016             this.priority = priority;
1017         }
1018
1019         @Override
1020         public int compareTo(Priori<T> o) {
1021             if(priority==o.priority) {
1022                 return 0;
1023             } else if(priority<o.priority) {
1024                 return -1;
1025             } else {
1026                 return 1;
1027             }
1028         }
1029         public static<T> void add(Access access, final String tag, List<Priori<T>> list) {
1030             String plugins = access.getProperty(tag, null);
1031             if(plugins!=null) {
1032                 access.log(Level.INIT, "Adding TAF Plugins: ", plugins);
1033                 for(String tafs : Split.splitTrim(';', plugins)) {
1034                     String[] pluginArray = Split.splitTrim(',', tafs);
1035                     String clssn = null;
1036                     int priority = 60;
1037                     switch(pluginArray.length) {
1038                         case 0:
1039                             break;
1040                         case 1:
1041                             clssn = tafs;
1042                             break;
1043                         default:
1044                             clssn = pluginArray[0];
1045                             try {
1046                                 priority = Integer.parseInt(pluginArray[1]);
1047                             } catch (NumberFormatException nfe) {
1048                                 access.printf(Level.ERROR, "%s format is <classname>,priority[;...]\n",CADI_ADD_TAFS);
1049                             }
1050                     }
1051
1052                     if(clssn!=null) {
1053                         Class<?> cls = loadClass(access, clssn);
1054                         if(cls!=null) {
1055                             try {
1056                                 @SuppressWarnings("unchecked")
1057                                 Constructor<T> cnst = (Constructor<T>)cls.getConstructor(Access.class);
1058                                 try {
1059                                     list.add(new Priori<T>(cnst.newInstance(access),priority));
1060                                 } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
1061                                     String hostname = access.getProperty(Config.HOSTNAME,null);
1062                                     if(hostname==null) {
1063                                         access.printf(Level.ERROR, "%s cannot be constructed on this machine.  Set valid 'hostname' in your properties\n",clssn);
1064                                     } else {
1065                                         access.printf(Level.ERROR, "%s cannot be constructed on %s with Access.\n",clssn, hostname);
1066                                     }
1067                                 }
1068                             } catch (NoSuchMethodException | SecurityException e) {
1069                                 access.printf(Level.ERROR, "%s needs a Constructor taking Access as sole param.\n",clssn);
1070                             }
1071                         }
1072                     }
1073                 }
1074             }
1075         }
1076    }
1077 }
1078