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