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