X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fconfig%2FConfig.java;h=b94ef86e92d0fe97ca44470c2f0232b8d163e98f;hb=628b7105ce4d9818aac69a082e515f9275fd46fd;hp=4784d1ee5f3a1a09386879b92e9ea5eee8686073;hpb=4b5a7d721d994a49057e9bfb403c7bff1b376660;p=aaf%2Fauthz.git diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java index 4784d1ee..b94ef86e 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java @@ -33,6 +33,7 @@ import java.net.UnknownHostException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.onap.aaf.cadi.AbsUserCache; @@ -57,6 +58,8 @@ import org.onap.aaf.cadi.taf.HttpTaf; import org.onap.aaf.cadi.taf.basic.BasicHttpTaf; import org.onap.aaf.cadi.taf.cert.X509Taf; import org.onap.aaf.cadi.taf.dos.DenialOfServiceTaf; +import org.onap.aaf.cadi.util.FixURIinfo; +import org.onap.aaf.cadi.util.Split; /** * Create a Consistent Configuration mechanism, even when configuration styles are as vastly different as @@ -104,6 +107,12 @@ public class Config { public static final String CADI_NOAUTHN = "cadi_noauthn"; public static final String CADI_LOC_LIST = "cadi_loc_list"; + // Special Behaviors + public static final String CADI_BATH_CONVERT = "cadi_bath_convert"; + public static final String CADI_API_ENFORCEMENT = "cadi_api_enforcement"; + public static final String CADI_ADD_TAFS = "cadi_add_tafs"; + public static final String CADI_ADD_LURS = "cadi_add_lurs"; + public static final String CADI_USER_CHAIN_TAG = "cadi_user_chain"; public static final String CADI_USER_CHAIN = "USER_CHAIN"; @@ -138,24 +147,44 @@ public class Config { public static final String AAF_ROOT_NS_DEF = "org.osaaf.aaf"; public static final String AAF_ROOT_COMPANY = "aaf_root_company"; public static final String AAF_LOCATE_URL = "aaf_locate_url"; //URL for AAF locator - private static final String AAF_LOCATE_URL_TAG = "AAF_LOCATE_URL"; // Name of Above for use in Config Variables. - public static final String AAF_DEFAULT_VERSION = "2.1"; + public static final String AAF_LOCATE_URL_TAG = "AAF_LOCATE_URL"; // Name of Above for use in Config Variables. + public static final String AAF_DEFAULT_API_VERSION = "2.1"; + public static final String AAF_API_VERSION = "aaf_api_version"; public static final String AAF_URL = "aaf_url"; //URL for AAF... Use to trigger AAF configuration - public static final String AAF_URL_DEF = "https://AAF_LOCATE_URL/AAF_NS.service:" + AAF_DEFAULT_VERSION; - public static final String GUI_URL_DEF = "https://AAF_LOCATE_URL/AAF_NS.gui:" + AAF_DEFAULT_VERSION; - public static final String CM_URL_DEF = "https://AAF_LOCATE_URL/AAF_NS.cm:" + AAF_DEFAULT_VERSION; - public static final String FS_URL_DEF = "https://AAF_LOCATE_URL/AAF_NS.fs:" + AAF_DEFAULT_VERSION; - public static final String HELLO_URL_DEF = "https://AAF_LOCATE_URL/AAF_NS.hello:" + AAF_DEFAULT_VERSION; - public static final String OAUTH2_TOKEN_URL = "https://AAF_LOCATE_URL/AAF_NS.token:" + AAF_DEFAULT_VERSION; - public static final String OAUTH2_INTROSPECT_URL = "https://AAF_LOCATE_URL/AAF_NS.introspect:" + AAF_DEFAULT_VERSION; - - public static final String AAF_REGISTER_AS = "aaf_register_as"; + public static final String AAF_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.service:" + AAF_DEFAULT_API_VERSION; + public static final String GUI_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.gui:" + AAF_DEFAULT_API_VERSION; + public static final String CM_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.cm:" + AAF_DEFAULT_API_VERSION; + public static final String FS_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.fs:" + AAF_DEFAULT_API_VERSION; + public static final String HELLO_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.hello:" + AAF_DEFAULT_API_VERSION; + public static final String OAUTH2_TOKEN_URL = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.token:" + AAF_DEFAULT_API_VERSION; + public static final String OAUTH2_INTROSPECT_URL = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.introspect:" + AAF_DEFAULT_API_VERSION; + + public static final String AAF_LOCATOR_CLASS = "aaf_locator_class"; + // AAF Locator Entries are ADDITIONAL entries, which also gives the Property ability + // to set these entries manually + // example: adding a K8S name like "oom" + // this will allow Registrations to pick up + // locator_ns.oom for onap's "OOM" based k8s entries, etc. + public static final String AAF_LOCATOR_CONTAINER="aaf_locator_container"; + // An ID for another Container, to be used to avoid picking up the wrong internal info + // for another container. + public static final String AAF_LOCATOR_CONTAINER_ID = "aaf_locator_container_id"; + public static final String AAF_LOCATOR_CONTAINER_NS = "aaf_locator_container_ns"; + public static final String AAF_LOCATOR_VERSION = "aaf_locator_version"; + public static final String AAF_LOCATOR_PROTOCOL = "aaf_locator_protocol"; + public static final String AAF_LOCATOR_SUBPROTOCOL = "aaf_locator_subprotocol"; + public static final String AAF_LOCATOR_NS = "aaf_locator_ns"; + public static final String AAF_LOCATOR_ENTRIES = "aaf_locator_entries"; + public static final String AAF_LOCATOR_FQDN = "aaf_locator_fqdn"; + public static final String AAF_LOCATOR_NAME = "aaf_locator_name"; + public static final String AAF_LOCATOR_PUBLIC_PORT = "aaf_locator_public_port"; + public static final String AAF_LOCATOR_PUBLIC_HOSTNAME = "aaf_locator_public_hostname"; + public static final String AAF_APPID = "aaf_id"; public static final String AAF_APPPASS = "aaf_password"; public static final String AAF_LUR_CLASS = "aaf_lur_class"; public static final String AAF_TAF_CLASS = "aaf_taf_class"; public static final String AAF_CONNECTOR_CLASS = "aaf_connector_class"; - public static final String AAF_LOCATOR_CLASS = "aaf_locator_class"; public static final String AAF_CONN_TIMEOUT = "aaf_conn_timeout"; public static final String AAF_CONN_TIMEOUT_DEF = "3000"; public static final String AAF_CONN_IDLE_TIMEOUT = "aaf_conn_idle_timeout"; // only for Direct Jetty Access. @@ -180,10 +209,11 @@ public class Config { public static final String AAF_HIGH_COUNT = "aaf_high_count"; public static final String AAF_HIGH_COUNT_DEF = "1000"; // Default is 1000 entries public static final String AAF_PERM_MAP = "aaf_perm_map"; - public static final String AAF_COMPONENT = "aaf_component"; +// public static final String AAF_COMPONENT = "aaf_component"; public static final String AAF_CERT_IDS = "aaf_cert_ids"; public static final String AAF_DEBUG_IDS = "aaf_debug_ids"; // comma delimited public static final String AAF_DATA_DIR = "aaf_data_dir"; // AAF processes and Components only. + public static final String AAF_RELEASE = "aaf_release"; public static final String GW_URL = "gw_url"; public static final String CM_URL = "cm_url"; @@ -233,9 +263,9 @@ public class Config { ///////////////////////////////////////////////////// Class aafConClass = loadClass(access,CADI_AAF_CON_DEF); Object aafcon = null; - if(con!=null && aafConClass!=null && aafConClass.isAssignableFrom(con.getClass())) { + if (con!=null && aafConClass!=null && aafConClass.isAssignableFrom(con.getClass())) { aafcon = con; - } else if(lur != null) { + } else if (lur != null) { Field f; try { f = lur.getClass().getField("aaf"); @@ -248,14 +278,14 @@ public class Config { boolean hasDirectAAF = hasDirect("DirectAAFLur",additionalTafLurs); // IMPORTANT! Don't attempt to load AAF Connector if there is no AAF URL String aafURL = access.getProperty(AAF_URL,null); - if(!hasDirectAAF && aafcon==null && aafURL!=null) { + if (!hasDirectAAF && aafcon==null && aafURL!=null) { aafcon = loadAAFConnector(si, aafURL); } HttpTaf taf; // Setup Host, in case Network reports an unusable Hostname (i.e. VTiers, VPNs, etc) String hostname = logProp(access, HOSTNAME,null); - if(hostname==null) { + if (hostname==null) { try { hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e1) { @@ -265,24 +295,24 @@ public class Config { access.log(Level.INIT, "Hostname set to",hostname); // Get appropriate TAFs - ArrayList htlist = new ArrayList<>(); + ArrayList> htlist = new ArrayList<>(); ///////////////////////////////////////////////////// // Add a Denial of Service TAF // Note: how IPs and IDs are added are up to service type. // They call "DenialOfServiceTaf.denyIP(String) or denyID(String) ///////////////////////////////////////////////////// - htlist.add(new DenialOfServiceTaf(access)); + htlist.add(new Priori(new DenialOfServiceTaf(access),0)); ///////////////////////////////////////////////////// // Configure Client Cert TAF ///////////////////////////////////////////////////// X509Taf x509TAF = null; String truststore = logProp(access, CADI_TRUSTSTORE,null); - if(truststore!=null) { + if (truststore!=null) { String truststorePwd = access.getProperty(CADI_TRUSTSTORE_PASSWORD,null); - if(truststorePwd!=null) { - if(truststorePwd.startsWith(Symm.ENC)) { + if (truststorePwd!=null) { + if (truststorePwd.startsWith(Symm.ENC)) { try { access.decrypt(truststorePwd,false); } catch (IOException e) { @@ -291,7 +321,7 @@ public class Config { } try { x509TAF=new X509Taf(access,lur); - htlist.add(x509TAF); + htlist.add(new Priori(x509TAF,10)); access.log(Level.INIT,"Certificate Authorization enabled"); } catch (SecurityException | IllegalArgumentException e) { access.log(Level.INIT,"AAFListedCertIdentity cannot be instantiated. Certificate Authorization is now disabled",e); @@ -314,42 +344,42 @@ public class Config { long userExp = Long.parseLong(aafCleanup); boolean basicWarn = "TRUE".equals(access.getProperty(BASIC_WARN,"FALSE")); - if(!hasDirectAAF) { + if (!hasDirectAAF) { HttpTaf aaftaf=null; - if(!hasOAuthDirectTAF) { - if(basicRealm!=null) { + if (!hasOAuthDirectTAF) { + if (basicRealm!=null) { @SuppressWarnings("unchecked") Class obasicCls = (Class)loadClass(access,CADI_OBASIC_HTTP_TAF_DEF); - if(obasicCls!=null) { + if (obasicCls!=null) { try { String tokenurl = logProp(access,Config.AAF_OAUTH2_TOKEN_URL, null); String introspecturl = logProp(access,Config.AAF_OAUTH2_INTROSPECT_URL, null); - if(tokenurl==null || introspecturl==null) { + if (tokenurl==null || introspecturl==null) { access.log(Level.INIT,"Both tokenurl and introspecturl are required. Oauth Authorization is disabled."); } Constructor obasicConst = obasicCls.getConstructor(PropAccess.class,String.class, String.class, String.class); - htlist.add(obasicConst.newInstance(access,basicRealm,tokenurl,introspecturl)); + htlist.add(new Priori(obasicConst.newInstance(access,basicRealm,tokenurl,introspecturl),20)); access.log(Level.INIT,"Oauth supported Basic Authorization is enabled"); } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { access.log(Level.INIT, e); } - } else if(up!=null) { + } else if (up!=null) { access.log(Level.INIT,"Basic Authorization is enabled using realm",basicRealm); // Allow warning about insecure channel to be turned off - if(!basicWarn) { + if (!basicWarn) { access.log(Level.INIT, "WARNING! The basicWarn property has been set to false.", " There will be no additional warning if Basic Auth is used on an insecure channel"); } BasicHttpTaf bht = new BasicHttpTaf(access, up, basicRealm, userExp, basicWarn); - for(Object o : additionalTafLurs) { - if(o instanceof CredValDomain) { + for (Object o : additionalTafLurs) { + if (o instanceof CredValDomain) { bht.add((CredValDomain)o); } } - if(x509TAF!=null) { + if (x509TAF!=null) { x509TAF.add(bht); } - htlist.add(bht); + htlist.add(new Priori(bht,20)); access.log(Level.INIT,"Basic Authorization is enabled"); } } else { @@ -359,28 +389,28 @@ public class Config { ///////////////////////////////////////////////////// // Configure AAF Driven Basic Auth ///////////////////////////////////////////////////// - if(aafcon==null) { + if (aafcon==null) { access.log(Level.INIT,"AAF Connection (AAFcon) is null. Cannot create an AAF TAF"); - } else if(aafURL==null) { + } else if (aafURL==null) { access.log(Level.INIT,"No AAF URL in properties, Cannot create an AAF TAF"); } else {// There's an AAF_URL... try to configure an AAF String aafTafClassName = logProp(access, AAF_TAF_CLASS,AAF_TAF_CLASS_DEF); // Only 2.0 available at this time - if(AAF_TAF_CLASS_DEF.equals(aafTafClassName)) { + if (AAF_TAF_CLASS_DEF.equals(aafTafClassName)) { try { Class aafTafClass = loadClass(access,aafTafClassName); - if(aafTafClass!=null) { + if (aafTafClass!=null) { Constructor cstr = aafTafClass.getConstructor(Connector.class,boolean.class,AbsUserCache.class); - if(cstr!=null) { - if(lur instanceof AbsUserCache) { + if (cstr!=null) { + if (lur instanceof AbsUserCache) { aaftaf = (HttpTaf)cstr.newInstance(aafcon,basicWarn,lur); } else { cstr = aafTafClass.getConstructor(Connector.class,boolean.class); - if(cstr!=null) { + if (cstr!=null) { aaftaf = (HttpTaf)cstr.newInstance(aafcon,basicWarn); } } - if(aaftaf==null) { + if (aaftaf==null) { access.log(Level.INIT,"ERROR! AAF TAF Failed construction. NOT Configured"); } else { access.log(Level.INIT,"AAF TAF Configured to ",aafURL); @@ -390,7 +420,7 @@ public class Config { } else { access.log(Level.INIT, "There is no AAF TAF class available: %s. AAF TAF not configured.",aafTafClassName); } - } catch(Exception e) { + } catch (Exception e) { access.log(Level.INIT,"ERROR! AAF TAF Failed construction. NOT Configured",e); } } @@ -400,35 +430,35 @@ public class Config { ///////////////////////////////////////////////////// // Configure OAuth TAF ///////////////////////////////////////////////////// - if(!hasOAuthDirectTAF) { + if (!hasOAuthDirectTAF) { String oauthTokenUrl = logProp(access,Config.AAF_OAUTH2_TOKEN_URL,null); Class oadtClss; try { oadtClss = Class.forName(OAUTH_DIRECT_TAF); } catch (ClassNotFoundException e1) { oadtClss = null; - access.log(Level.INIT, e1); + access.log(Level.DEBUG, e1); } - if(additionalTafLurs!=null && additionalTafLurs.length>0 && (oadtClss!=null && additionalTafLurs[0].getClass().isAssignableFrom(oadtClss))) { - htlist.add((HttpTaf)additionalTafLurs[0]); + if (additionalTafLurs!=null && additionalTafLurs.length>0 && (oadtClss!=null && additionalTafLurs[0].getClass().isAssignableFrom(oadtClss))) { + htlist.add(new Priori((HttpTaf)additionalTafLurs[0],30)); String[] array= new String[additionalTafLurs.length-1]; - if(array.length>0) { + if (array.length>0) { System.arraycopy(htlist, 1, array, 0, array.length); } additionalTafLurs = array; access.log(Level.INIT,"OAuth2 Direct is enabled"); - } else if(oauthTokenUrl!=null) { + } else if (oauthTokenUrl!=null) { String oauthIntrospectUrl = logProp(access,Config.AAF_OAUTH2_INTROSPECT_URL,null); @SuppressWarnings("unchecked") Class oaTCls = (Class)loadClass(access,OAUTH_HTTP_TAF); - if(oaTCls!=null) { + if (oaTCls!=null) { Class oaTTmgrCls = loadClass(access, OAUTH_TOKEN_MGR); - if(oaTTmgrCls!=null) { + if (oaTTmgrCls!=null) { try { Method oaTTmgrGI = oaTTmgrCls.getMethod("getInstance",PropAccess.class,String.class,String.class); Object oaTTmgr = oaTTmgrGI.invoke(null /*this is static method*/,access,oauthTokenUrl,oauthIntrospectUrl); Constructor oaTConst = oaTCls.getConstructor(Access.class,oaTTmgrCls); - htlist.add(oaTConst.newInstance(access,oaTTmgr)); + htlist.add(new Priori(oaTConst.newInstance(access,oaTTmgr),30)); access.log(Level.INIT,"OAuth2 TAF is enabled"); } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException e) { access.log(Level.INIT,"OAuth2HttpTaf cannot be instantiated. OAuth2 is disabled",e); @@ -444,30 +474,31 @@ public class Config { // Adding BasicAuth (AAF) last, after other primary Cookie Based // Needs to be before Cert... see below ///////////////////////////////////////////////////// - if(aaftaf!=null) { - htlist.add(aaftaf); + if (aaftaf!=null) { + htlist.add(new Priori(aaftaf,40)); } } ///////////////////////////////////////////////////// - // Any Additional Lurs passed in Constructor + // Any Additional Tafs passed in Constructor ///////////////////////////////////////////////////// - if(additionalTafLurs!=null) { - for(Object additional : additionalTafLurs) { - if(additional instanceof BasicHttpTaf) { + if (additionalTafLurs!=null) { + int i=0; + for (Object additional : additionalTafLurs) { + if (additional instanceof BasicHttpTaf) { BasicHttpTaf ht = (BasicHttpTaf)additional; - for(Object cv : additionalTafLurs) { - if(cv instanceof CredValDomain) { + for (Object cv : additionalTafLurs) { + if (cv instanceof CredValDomain) { ht.add((CredValDomain)cv); access.printf(Level.INIT,"%s Authentication is enabled",cv); } } - htlist.add(ht); - } else if(additional instanceof HttpTaf) { + htlist.add(new Priori(ht,50+i++)); + } else if (additional instanceof HttpTaf) { HttpTaf ht = (HttpTaf)additional; - htlist.add(ht); + htlist.add(new Priori(ht,50+i++)); access.printf(Level.INIT,"%s Authentication is enabled",additional.getClass().getSimpleName()); - } else if(hasOAuthDirectTAF) { + } else if (hasOAuthDirectTAF) { Class daupCls; try { daupCls = Class.forName("org.onap.aaf.auth.direct.DirectAAFUserPass"); @@ -475,8 +506,8 @@ public class Config { daupCls = null; access.log(Level.INIT, e); } - if(daupCls != null && additional.getClass().isAssignableFrom(daupCls)) { - htlist.add(new BasicHttpTaf(access, (CredVal)additional , basicRealm, userExp, basicWarn)); + if (daupCls != null && additional.getClass().isAssignableFrom(daupCls)) { + htlist.add(new Priori(new BasicHttpTaf(access, (CredVal)additional , basicRealm, userExp, basicWarn),50+i++)); access.printf(Level.INIT,"Direct BasicAuth Authentication is enabled",additional.getClass().getSimpleName()); } } @@ -484,27 +515,45 @@ public class Config { } // Add BasicAuth, if any, to x509Taf - if(x509TAF!=null) { - for( HttpTaf ht : htlist) { - if(ht instanceof BasicHttpTaf) { - x509TAF.add((BasicHttpTaf)ht); + if (x509TAF!=null) { + for ( Priori ht : htlist) { + if (ht.t instanceof BasicHttpTaf) { + x509TAF.add((BasicHttpTaf)ht.t); } } } + + ///////////////////////////////////////////////////// + // Additional TAFs by Plugin + ///////////////////////////////////////////////////// + Priori.add(access, CADI_ADD_TAFS, htlist); + ///////////////////////////////////////////////////// // Create EpiTaf from configured TAFs ///////////////////////////////////////////////////// - if(htlist.size()==1) { + if (htlist.size()==1) { // just return the one - taf = htlist.get(0); + taf = htlist.get(0).t; } else { + Collections.sort(htlist); HttpTaf[] htarray = new HttpTaf[htlist.size()]; - htlist.toArray(htarray); + int i=-1; + StringBuilder sb = new StringBuilder("Tafs processed in this order:\n"); + for(Priori pht : htlist) { + htarray[++i] = pht.t; + sb.append(" "); + sb.append(pht.t.getClass().getName()); + sb.append('('); + sb.append(pht.priority); + sb.append(")\n"); + } + access.log(Level.INIT, sb); + Locator locator = loadLocator(si, logProp(access, AAF_LOCATE_URL, null)); taf = new HttpEpiTaf(access,locator, tc, htarray); // ok to pass locator == null String level = logProp(access, CADI_LOGLEVEL, null); - if(level!=null) { + if (level!=null) { access.setLogLevel(Level.valueOf(level)); } } @@ -514,7 +563,7 @@ public class Config { public static String logProp(Access access,String tag, String def) { String rv = access.getProperty(tag, def); - if(rv == null) { + if (rv == null) { access.log(Level.INIT,tag,"is not explicitly set"); } else { access.log(Level.INIT,tag,"is set to",rv); @@ -524,7 +573,7 @@ public class Config { public static Lur configLur(SecurityInfoC si, Connector con, Object ... additionalTafLurs) throws CadiException { Access access = si.access; - List lurs = new ArrayList<>(); + List> lurs = new ArrayList<>(); ///////////////////////////////////////////////////// // Configure a Local Property Based RBAC/LUR @@ -533,14 +582,14 @@ public class Config { String users = access.getProperty(USERS,null); String groups = access.getProperty(GROUPS,null); - if(groups!=null || users!=null) { + if (groups!=null || users!=null) { LocalLur ll = new LocalLur(access, users, groups); // note b64==null is ok.. just means no encryption. - lurs.add(ll); + lurs.add(new Priori(ll,10)); String writeto = access.getProperty(WRITE_TO,null); - if(writeto!=null) { + if (writeto!=null) { String msg = UsersDump.updateUsers(writeto, ll); - if(msg!=null) { + if (msg!=null) { access.log(Level.INIT,"ERROR! Error Updating ",writeto,"with roles and users:",msg); } } @@ -554,20 +603,20 @@ public class Config { ///////////////////////////////////////////////////// String tokenUrl = logProp(access,AAF_OAUTH2_TOKEN_URL, null); String introspectUrl = logProp(access,AAF_OAUTH2_INTROSPECT_URL, null); - if(tokenUrl!=null && introspectUrl !=null) { + if (tokenUrl!=null && introspectUrl !=null) { try { Class olurCls = loadClass(access, CADI_OLUR_CLASS_DEF); - if(olurCls!=null) { + if (olurCls!=null) { Constructor olurCnst = olurCls.getConstructor(PropAccess.class,String.class,String.class); Lur olur = (Lur)olurCnst.newInstance(access,tokenUrl,introspectUrl); - lurs.add(olur); + lurs.add(new Priori(olur,20)); access.log(Level.INIT, "OAuth2 LUR enabled"); } else { access.log(Level.INIT,"AAF/OAuth LUR plugin is not available."); } } catch (NoSuchMethodException| SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { String msg = e.getMessage(); - if(msg==null && e.getCause()!=null) { + if (msg==null && e.getCause()!=null) { msg = e.getCause().getMessage(); } access.log(Level.INIT,"AAF/OAuth LUR is not instantiated.",msg,e); @@ -576,20 +625,20 @@ public class Config { access.log(Level.INIT, "OAuth2 Lur disabled"); } - if(con!=null) { // try to reutilize connector - lurs.add(con.newLur()); + if (con!=null) { // try to reutilize connector + lurs.add(new Priori(con.newLur(),30)); } else { ///////////////////////////////////////////////////// // Configure the AAF Lur (if any) ///////////////////////////////////////////////////// String aafURL = logProp(access,AAF_URL,null); // Trigger Property String aafEnv = access.getProperty(AAF_ENV,null); - if(aafEnv == null && aafURL!=null && access instanceof PropAccess) { // set AAF_ENV from AAF_URL + if (aafEnv == null && aafURL!=null && access instanceof PropAccess) { // set AAF_ENV from AAF_URL int ec = aafURL.indexOf("envContext="); - if(ec>0) { + if (ec>0) { ec += 11; // length of envContext= int slash = aafURL.indexOf('/', ec); - if(slash>0) { + if (slash>0) { aafEnv = aafURL.substring(ec, slash); ((PropAccess)access).setProperty(AAF_ENV, aafEnv); access.printf(Level.INIT, "Setting aafEnv to %s from aaf_url value",aafEnv); @@ -598,30 +647,30 @@ public class Config { } // Don't configure AAF if it is using DirectAccess - if(!hasDirect("DirectAAFLur",additionalTafLurs)) { - if(aafURL==null) { + if (!hasDirect("DirectAAFLur",additionalTafLurs)) { + if (aafURL==null) { access.log(Level.INIT,"No AAF LUR properties, AAF will not be loaded"); } else {// There's an AAF_URL... try to configure an AAF String aafLurClassStr = logProp(access,AAF_LUR_CLASS,AAF_V2_0_AAF_LUR_PERM); ////////////AAF Lur 2.0 ///////////// - if(aafLurClassStr!=null && aafLurClassStr.startsWith(AAF_V2_0)) { + if (aafLurClassStr!=null && aafLurClassStr.startsWith(AAF_V2_0)) { try { Object aafcon = loadAAFConnector(si, aafURL); - if(aafcon==null) { + if (aafcon==null) { access.log(Level.INIT,"AAF LUR class,",aafLurClassStr,"cannot be constructed without valid AAFCon object."); } else { Class aafAbsAAFCon = loadClass(access, AAF_V2_0_AAFCON); - if(aafAbsAAFCon!=null) { + if (aafAbsAAFCon!=null) { Method mNewLur = aafAbsAAFCon.getMethod("newLur"); Object aaflur = mNewLur.invoke(aafcon); - if(aaflur==null) { + if (aaflur==null) { access.log(Level.INIT,"ERROR! AAF LUR Failed construction. NOT Configured"); } else { access.log(Level.INIT,"AAF LUR Configured to ",aafURL); - lurs.add((Lur)aaflur); + lurs.add(new Priori((Lur)aaflur,40)); String debugIDs = logProp(access,Config.AAF_DEBUG_IDS, null); - if(debugIDs !=null && aaflur instanceof CachingLur) { + if (debugIDs !=null && aaflur instanceof CachingLur) { ((CachingLur)aaflur).setDebug(debugIDs); } } @@ -638,15 +687,21 @@ public class Config { ///////////////////////////////////////////////////// // Any Additional passed in Constructor ///////////////////////////////////////////////////// - if(additionalTafLurs!=null) { - for(Object additional : additionalTafLurs) { - if(additional instanceof Lur) { - lurs.add((Lur)additional); + if (additionalTafLurs!=null) { + int i=0; + for (Object additional : additionalTafLurs) { + if (additional instanceof Lur) { + lurs.add(new Priori((Lur)additional,50+i++)); access.log(Level.INIT, additional); } } } + ///////////////////////////////////////////////////// + // Additional LURs by Plugin + ///////////////////////////////////////////////////// + Priori.add(access, CADI_ADD_LURS, lurs); + ///////////////////////////////////////////////////// // Return a Lur based on how many there are... ///////////////////////////////////////////////////// @@ -656,19 +711,30 @@ public class Config { // Return a NULL Lur that does nothing. return new NullLur(); case 1: - return lurs.get(0); // Only one, just return it, save processing + return lurs.get(0).t; // Only one, just return it, save processing default: // Multiple Lurs, use EpiLUR to handle + Collections.sort(lurs); Lur[] la = new Lur[lurs.size()]; - lurs.toArray(la); + int i=-1; + StringBuilder sb = new StringBuilder("Lurs processed in this order:\n"); + for(Priori pht : lurs) { + la[++i] = pht.t; + sb.append(" "); + sb.append(pht.t.getClass().getName()); + sb.append('('); + sb.append(pht.priority); + sb.append(")\n"); + } + access.log(Level.INIT, sb); return new EpiLur(la); } } private static boolean hasDirect(String simpleClassName, Object[] additionalTafLurs) { - if(additionalTafLurs!=null) { - for(Object tf : additionalTafLurs) { - if(tf.getClass().getSimpleName().equals(simpleClassName)) { + if (additionalTafLurs!=null) { + for (Object tf : additionalTafLurs) { + if (tf.getClass().getSimpleName().equals(simpleClassName)) { return true; } } @@ -746,24 +812,54 @@ public class Config { public static Locator loadLocator(SecurityInfoC si, final String _url) throws LocatorException { Access access = si.access; Locator locator = null; - if(_url==null) { + if (_url==null) { access.log(Level.INIT,"No URL passed to 'loadLocator'. Disabled"); } else { - String url = _url; +// String url = _url.replace("/AAF_NS.", "/%C%CID%AAF_NS."); +// String root_ns = access.getProperty(Config.AAF_ROOT_NS, null); + String url; + RegistrationPropHolder rph; + try { + rph = new RegistrationPropHolder(access, 0); + url = rph.replacements(_url, null, null); + } catch (UnknownHostException | CadiException e1) { + throw new LocatorException(e1); + } + +// if(url.indexOf('%')>=0) { +// String str = access.getProperty(Config.AAF_LOCATOR_CONTAINER_ID, null); +// if(str==null) { +// url = url.replace("%CID",""); +// } else { +// url = url.replace("%CID",str+'.'); +// } +// str = access.getProperty(Config.AAF_LOCATOR_CONTAINER, null); +// if(str==null) { +// url = url.replace("%C",""); +// } else { +// url = url.replace("%C",str+'.'); +// } +// +// if (root_ns==null) { +// url = url.replace("%AAF_NS",""); +// } else { +// url = url.replace("%AAF_NS",root_ns); +// } +// } String replacement; int idxAAFLocateUrl; - if((idxAAFLocateUrl=_url.indexOf(AAF_LOCATE_URL_TAG))>0 && ((replacement=access.getProperty(AAF_LOCATE_URL, null))!=null)) { + if ((idxAAFLocateUrl=url.indexOf(AAF_LOCATE_URL_TAG))>0 && ((replacement=access.getProperty(AAF_LOCATE_URL, null))!=null)) { StringBuilder sb = new StringBuilder(replacement); - if(!replacement.endsWith("/locate")) { + if (!replacement.endsWith("/locate")) { sb.append("/locate"); } - sb.append(_url,idxAAFLocateUrl+AAF_LOCATE_URL_TAG.length(),_url.length()); + sb.append(url,idxAAFLocateUrl+AAF_LOCATE_URL_TAG.length(),url.length()); url = sb.toString(); } - + try { Class lcls = loadClass(access,AAF_LOCATOR_CLASS_DEF); - if(lcls==null) { + if (lcls==null) { throw new CadiException("Need to include aaf-cadi-aaf jar for AAFLocator"); } // First check for preloaded @@ -771,21 +867,22 @@ public class Config { Method meth = lcls.getMethod("create",String.class); locator = (Locator)meth.invoke(null,url); } catch (Exception e) { - access.log(Level.INIT, e); + access.log(Level.DEBUG, "(Not fatal) Cannot load by create(String)", e); } - if(locator==null) { + if (locator==null) { URI locatorURI = new URI(url); + FixURIinfo fui = new FixURIinfo(locatorURI); Constructor cnst = lcls.getConstructor(SecurityInfoC.class,URI.class); locator = (Locator)cnst.newInstance(new Object[] {si,locatorURI}); - int port = locatorURI.getPort(); - String portS = port<0?"":(":"+locatorURI.getPort()); + int port = fui.getPort(); + String portS = port<0?"":(":"+port); - access.log(Level.INFO, "AAFLocator enabled using " + locatorURI.getScheme() +"://"+locatorURI.getHost() + portS); + access.log(Level.INFO, "AAFLocator enabled using " + locatorURI.getScheme() +"://"+fui.getHost() + portS); } else { access.log(Level.INFO, "AAFLocator enabled using preloaded " + locator.getClass().getSimpleName()); } } catch (InvocationTargetException e) { - if(e.getTargetException() instanceof LocatorException) { + if (e.getTargetException() instanceof LocatorException) { throw (LocatorException)e.getTargetException(); } access.log(Level.INIT,e.getTargetException().getMessage(),"AAFLocator for",url,"could not be created.",e); @@ -801,5 +898,66 @@ public class Config { return defaultRealm; } + private static class Priori implements Comparable> { + public final T t; + public final int priority; + + public Priori(final T t, final int priority) { + this.t = t; + this.priority = priority; + } + + @Override + public int compareTo(Priori o) { + if(priority==o.priority) { + return 0; + } else if(priority void add(Access access, final String tag, List> list) { + String plugins = access.getProperty(tag, null); + if(plugins!=null) { + for(String tafs : Split.splitTrim(';', plugins)) { + String[] pluginArray = Split.splitTrim(',', tafs); + String clssn = null; + int priority = 60; + switch(pluginArray.length) { + case 0: + break; + case 1: + clssn = tafs; + break; + default: + clssn = pluginArray[0]; + try { + priority = Integer.parseInt(pluginArray[1]); + } catch (NumberFormatException nfe) { + access.printf(Level.ERROR, "%s format is ,priority[;...]\n",CADI_ADD_TAFS); + } + } + + if(clssn!=null) { + Class cls = loadClass(access, clssn); + if(cls!=null) { + try { + @SuppressWarnings("unchecked") + Constructor cnst = (Constructor)cls.getConstructor(Access.class); + try { + list.add(new Priori(cnst.newInstance(access),priority)); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + access.printf(Level.ERROR, "%s cannot be constructed with Access.\n",clssn); + } + } catch (NoSuchMethodException | SecurityException e) { + access.printf(Level.ERROR, "%s needs a Constructor taking Access as sole param.\n",clssn); + } + } + } + } + } + } + } }