diff options
author | Instrumental <jonathan.gathman@att.com> | 2019-04-10 13:01:30 -0500 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2019-04-10 13:13:33 -0500 |
commit | 4ac37bffd664bbc2d6d419d9420393193573320d (patch) | |
tree | 92f0f1e1903488ec0cf2a3ae9835690f085214ea /cadi | |
parent | dcd0cb51ce490f0d790713a2c1e9dc5fda36e70d (diff) |
switch Internal/External Locator Names for Dublin
Issue-ID: AAF-808
Change-Id: If7c600cddef0f7d0fce1a8f7b1518d9ffe0983fe
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'cadi')
13 files changed, 196 insertions, 127 deletions
diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java index d3804743..e5a0a28c 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java @@ -27,10 +27,10 @@ import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.Socket; import java.net.URI; -import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.CadiException; @@ -43,6 +43,7 @@ import org.onap.aaf.cadi.aaf.v2_0.AAFLocator; import org.onap.aaf.cadi.client.Future; import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.config.SecurityInfoC; +import org.onap.aaf.cadi.configure.Agent; import org.onap.aaf.cadi.http.HBasicAuthSS; import org.onap.aaf.cadi.http.HClient; import org.onap.aaf.cadi.http.HX509SS; @@ -53,7 +54,10 @@ import org.onap.aaf.misc.env.APIException; public class TestConnectivity { - public static void main(String[] args) { + private static Map<String, String> aaf_urls; + + + public static void main(String[] args) { if (args.length<1) { System.out.println("Usage: ConnectivityTester <cadi_prop_files> [<AAF FQDN (i.e. aaf.dev.att.com)>]"); } else { @@ -65,24 +69,14 @@ public class TestConnectivity { } PropAccess access = new PropAccess(args); - String aaflocate; - if (args.length>1) { - aaflocate = "https://" + args[1]; - access.setProperty(Config.AAF_LOCATE_URL, "https://" + args[1]); - } else { - aaflocate = access.getProperty(Config.AAF_LOCATE_URL); - if (aaflocate==null) { - print(true,"Properties must contain ",Config.AAF_LOCATE_URL); - } - } - try { SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(access, HttpURLConnection.class); + aaf_urls = Agent.loadURLs(access); List<SecuritySetter<HttpURLConnection>> lss = loadSetters(access,si); ///////// - String directAAFURL = access.getProperty(Config.AAF_URL,null); - if(directAAFURL!=null && !directAAFURL.contains("AAF_LOCATE")) { + String directAAFURL = aaf_urls.get(Config.AAF_URL); + if(directAAFURL!=null && !directAAFURL.contains("/locate/")) { print(true,"Test Connections by non-located aaf_url"); Locator<URI> locator = new SingleEndpointLocator(directAAFURL); connectTest(locator,new URI(directAAFURL)); @@ -92,17 +86,18 @@ public class TestConnectivity { } else { ///////// print(true,"Test Connections driven by AAFLocator"); - URI serviceURI = uri(access,"service"); + String serviceURI = aaf_urls.get(Config.AAF_URL); - for (URI uri : new URI[] { + for (String url : new String[] { serviceURI, - uri(access,"token"), - uri(access,"introspect"), - uri(access,"cm"), - uri(access,"gui"), - uri(access,"fs"), - uri(access,"hello") + aaf_urls.get(Config.AAF_OAUTH2_TOKEN_URL), + aaf_urls.get(Config.AAF_OAUTH2_INTROSPECT_URL), + aaf_urls.get(Config.AAF_URL_CM), + aaf_urls.get(Config.AAF_URL_GUI), + aaf_urls.get(Config.AAF_URL_FS), + aaf_urls.get(Config.AAF_URL_HELLO) }) { + URI uri = new URI(url); Locator<URI> locator = new AAFLocator(si, uri); try { connectTest(locator, uri); @@ -114,7 +109,7 @@ public class TestConnectivity { ///////// print(true,"Test Service for Perms driven by AAFLocator"); - Locator<URI> locator = new AAFLocator(si,serviceURI); + Locator<URI> locator = new AAFLocator(si,new URI(serviceURI)); for (SecuritySetter<HttpURLConnection> ss : lss) { permTest(locator,ss); } @@ -125,7 +120,7 @@ public class TestConnectivity { for (SecuritySetter<HttpURLConnection> ss : lss) { if (ss instanceof HBasicAuthSS) { hasBath=true; - basicAuthTest(new AAFLocator(si, serviceURI),ss); + basicAuthTest(new AAFLocator(si, new URI(serviceURI)),ss); } } if(!hasBath) { @@ -141,25 +136,6 @@ public class TestConnectivity { } } - private static URI uri(PropAccess access, String ms) throws URISyntaxException { - String aaf_root_ns = access.getProperty(Config.AAF_ROOT_NS,Config.AAF_ROOT_NS_DEF); - String aaf_api_version = access.getProperty(Config.AAF_API_VERSION,Config.AAF_DEFAULT_API_VERSION); - String aaf_locate_url = access.getProperty(Config.AAF_LOCATE_URL,Defaults.AAF_LOCATE_CONST); - String aaf_container = access.getProperty(Config.AAF_LOCATOR_CONTAINER,null); - if(aaf_container!=null) { - String ns = access.getProperty(Config.AAF_LOCATOR_CONTAINER_NS+'.'+aaf_container,null); - if(ns==null) { - ns = access.getProperty(Config.AAF_LOCATOR_CONTAINER_NS,null); - } - if(ns!=null) { - aaf_root_ns=ns + '.' + aaf_root_ns; - } - } - if("cm".equals(ms) && "2.0".equals(aaf_api_version)) { - ms = "certman"; - } - return new URI(aaf_locate_url + "/locate/" + aaf_root_ns + '.' + ms + ':' + aaf_api_version); - } private static List<SecuritySetter<HttpURLConnection>> loadSetters(PropAccess access, SecurityInfoC<HttpURLConnection> si) { print(true,"Load Security Setters from Configuration Information"); @@ -192,12 +168,7 @@ public class TestConnectivity { access.log(Level.INFO, "X509 (Client certificate) Security Setter constructor threw exception: \"",e.getMessage(),"\". X509 tests will not be performed"); } - String tokenURL = access.getProperty(Config.AAF_OAUTH2_TOKEN_URL); - String locateURL=access.getProperty(Config.AAF_LOCATE_URL); - if (tokenURL==null || (tokenURL.contains("/locate/") && locateURL!=null)) { - tokenURL=Config.OAUTH2_TOKEN_URL_DEF; - } - + String tokenURL = aaf_urls.get(Config.AAF_OAUTH2_TOKEN_URL); try { HRenewingTokenSS hrtss = new HRenewingTokenSS(access, tokenURL); @@ -256,6 +227,7 @@ public class TestConnectivity { if ((uri = dl.get(li)) == null) { System.out.println("Locator Item empty"); } else { + System.out.printf("Located %s using %s\n",uri.toString(), locatorURI.toString()); socket = new Socket(); try { FixURIinfo fui = new FixURIinfo(uri); diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFLocator.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFLocator.java index 16fdb79c..eda4a5aa 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFLocator.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFLocator.java @@ -130,4 +130,5 @@ public class AAFLocator extends AbsAAFLocator<BasicTrans> { protected HClient createClient(SecuritySetter<HttpURLConnection> ss, URI uri, int connectTimeout) throws LocatorException { return new HClient(ss, uri, connectTimeout); } + } diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java index 5214ddba..2405962c 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java @@ -60,7 +60,7 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI> protected String myhostname; protected int myport; protected final String aaf_locator_host; - protected final URI aaf_locator_uri; + protected URI aaf_locator_uri; private long earliest; private final long refreshWait; @@ -462,5 +462,10 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI> return rv; } + protected void clear() { + epList.clear(); + earliest=0L; + } + } diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java index e04015c4..caf15d35 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java @@ -50,6 +50,7 @@ import org.onap.aaf.cadi.CmdLine; import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.Symm; +import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.aaf.client.ErrMessage; import org.onap.aaf.cadi.aaf.v2_0.AAFCon; import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; @@ -57,6 +58,7 @@ import org.onap.aaf.cadi.client.Future; import org.onap.aaf.cadi.client.Rcli; import org.onap.aaf.cadi.client.Retryable; import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.config.RegistrationPropHolder; import org.onap.aaf.cadi.config.SecurityInfoC; import org.onap.aaf.cadi.http.HBasicAuthSS; import org.onap.aaf.cadi.locator.SingleEndpointLocator; @@ -113,6 +115,11 @@ public class Agent { Config.CADI_TRUSTSTORE,Config.CADI_TRUSTSTORE_PASSWORD, Config.CADI_ALIAS, Config.CADI_X509_ISSUERS }); + private static List<String> LOC_TAGS = Arrays.asList(new String[] { + Config.CADI_LATITUDE, Config.CADI_LONGITUDE + }); + // Note: This is set by loadURLs. Use that function as singleton, not directly. + private static Map<String,String> aaf_urls = null; public static void main(String[] args) { @@ -227,11 +234,8 @@ public class Agent { aafsso.setLogDefault(); aafsso.setStdErrDefault(); - // if CM_URL can be obtained, add to sso.props, if written - String cm_url = getProperty(access,env,false, Config.CM_URL,Config.CM_URL_DEF); - if (cm_url!=null) { - aafsso.addProp(Config.CM_URL, cm_url); - } + Map<String, String> aaf_urls = loadURLs(access); + aafsso.addProp(Config.AAF_URL_CM, aaf_urls.get(Config.AAF_URL_CM)); aafsso.writeFiles(); } @@ -300,9 +304,53 @@ public class Agent { } } - private static synchronized AAFCon<?> aafcon(Access access) throws APIException, CadiException, LocatorException { + public synchronized static Map<String,String> loadURLs(Access access) throws UnknownHostException, CadiException { + if(aaf_urls==null) { + Map<String,String> rv = new HashMap<>(); + RegistrationPropHolder rph = new RegistrationPropHolder(access, 0); + String dot_le = access.getProperty(Config.AAF_LOCATOR_CONTAINER,null); + dot_le=dot_le==null?"":'.'+dot_le; + String version = access.getProperty(Config.AAF_API_VERSION,Config.AAF_DEFAULT_API_VERSION); + for(String u : new String[] {"aaf","locate","oauth","cm","gui","fs","hello","token","introspect"}) { + String proto = "fs".equals(u)?"http://":"https://"; + String lhost; + if("locate".equals(u)) { + lhost=rph.default_fqdn; + } else { + lhost=Config.AAF_LOCATE_URL_TAG; + } + String value = rph.replacements("Agent:loadURLs", + proto + lhost + "/AAF_NS." + ("aaf".equals(u)?"service":u) + ':' + version, + null,dot_le); + switch(u) { + case "aaf": rv.put(Config.AAF_URL, value); break; + case "locate": rv.put(Config.AAF_LOCATE_URL, value); break; + case "token": rv.put(Config.AAF_OAUTH2_TOKEN_URL, value); break; + case "introspect": rv.put(Config.AAF_OAUTH2_INTROSPECT_URL, value); break; + case "cm": rv.put(Config.AAF_URL_CM, value); break; + case "gui": rv.put(Config.AAF_URL_GUI, value); break; + case "fs": rv.put(Config.AAF_URL_FS, value); break; + case "hello": rv.put(Config.AAF_URL_HELLO, value); break; + default: + rv.put("aaf_url_" + u, value); + } + }; + aaf_urls = rv; + } + return aaf_urls; + } + + public static void fillMissing(PropAccess access, Map<String, String> map) { + for(Entry<String, String> es : map.entrySet()) { + if(access.getProperty(es.getKey())==null) { + access.setProperty(es.getKey(),es.getValue()); + } + } + } + + private static synchronized AAFCon<?> aafcon(Access access) throws APIException, CadiException, LocatorException { if (aafcon==null) { - aafcon = new AAFConHttp(access,Config.CM_URL); + aafcon = new AAFConHttp(access,Config.AAF_URL_CM); } return aafcon; } @@ -743,7 +791,6 @@ public class Agent { Artifact arti = new Artifact(); arti.setDir(propAccess.getProperty(Config.CADI_ETCDIR, ".")); arti.setNs(FQI.reverseDomain(fqi)); - PropHolder loc = PropHolder.get(arti, "location.props"); PropHolder cred = PropHolder.get(arti,"cred.props"); PropHolder app= PropHolder.get(arti,"props"); @@ -771,51 +818,62 @@ public class Agent { } } + // load all properties that are already setup. + Map<String, String> aaf_urls = loadURLs(propAccess); + for(Entry<String, String> es : aaf_urls.entrySet()) { + app.add(es.getKey(), es.getValue()); + } + app.add(Config.AAF_LOCATE_URL, propAccess, null); for(Entry<Object, Object> aaf_loc_prop : propAccess.getProperties().entrySet()) { String key = aaf_loc_prop.getKey().toString(); - if(key.startsWith("aaf_locator")) { + if("aaf_env".equals(key) || key.startsWith("aaf_locator")) { app.add(key, aaf_loc_prop.getValue().toString()); } } app.add(Config.AAF_APPID, fqi); - app.add(Config.AAF_URL, propAccess, Config.AAF_URL_DEF); String cts = propAccess.getProperty(Config.CADI_TRUSTSTORE); + System.out.println("Passed in Truststore is " + cts); if (cts!=null) { File origTruststore = new File(cts); - if (!origTruststore.exists()) { - // Try same directory as cadi_prop_files - String cpf = propAccess.getProperty(Config.CADI_PROP_FILES); - if (cpf!=null) { - for (String f : Split.split(File.pathSeparatorChar, cpf)) { - File fcpf = new File(f); - if (fcpf.exists()) { - int lastSep = cts.lastIndexOf(File.pathSeparator); - origTruststore = new File(fcpf.getParentFile(),lastSep>=0?cts.substring(lastSep):cts); - if (origTruststore.exists()) { - break; - } - } - } - if (!origTruststore.exists()) { - throw new CadiException(cts + " does not exist"); - } - } - - } File newTruststore = new File(app.getDir(),origTruststore.getName()); - if (!newTruststore.exists()) { - Files.copy(origTruststore.toPath(), newTruststore.toPath()); + if(!newTruststore.exists()) { + if (!origTruststore.exists()) { + // Try same directory as cadi_prop_files + String cpf = propAccess.getProperty(Config.CADI_PROP_FILES); + if (cpf!=null) { + for (String f : Split.split(File.pathSeparatorChar, cpf)) { + File fcpf = new File(f); + if (fcpf.exists()) { + int lastSep = cts.lastIndexOf(File.pathSeparator); + origTruststore = new File(fcpf.getParentFile(),lastSep>=0?cts.substring(lastSep):cts); + if (origTruststore.exists()) { + break; + } + } + } + if (!origTruststore.exists()) { + throw new CadiException(cts + " does not exist"); + } + } + + } + if (!newTruststore.exists() && origTruststore.exists()) { + Files.copy(origTruststore.toPath(), newTruststore.toPath()); + } } - - cred.add(Config.CADI_TRUSTSTORE, propAccess, newTruststore.getCanonicalPath()); - cred.addEnc(Config.CADI_TRUSTSTORE_PASSWORD, propAccess, "changeit" /* Java default */); + + System.out.println("New Truststore is " + newTruststore); + cred.add(Config.CADI_TRUSTSTORE, newTruststore.getCanonicalPath()); + cred.add(Config.CADI_TRUSTSTORE_PASSWORD, "changeit" /* Java default */); String cpf = propAccess.getProperty(Config.CADI_PROP_FILES); if (cpf!=null){ - for (String f : Split.split(File.pathSeparatorChar, cpf)) { + String[] propFiles = Split.splitTrim(File.pathSeparatorChar, cpf); + for (int pfi = propFiles.length-1;pfi>=0;--pfi) { + String f = propFiles[pfi]; System.out.format("Reading %s\n",f); FileInputStream fis = new FileInputStream(f); try { @@ -824,6 +882,9 @@ public class Agent { for (Entry<Object, Object> prop : props.entrySet()) { boolean lower = true; String key = prop.getKey().toString(); + if(LOC_TAGS.contains(key)) { + break; + } for(int i=0;lower && i<key.length();++i) { if(Character.isUpperCase(key.charAt(i))) { lower = false; @@ -876,8 +937,6 @@ public class Agent { } - private static List<String> LOC_TAGS = Arrays.asList(new String[] {Config.CADI_LATITUDE, Config.CADI_LONGITUDE}); - private static void validate(final PropAccess pa) throws LocatorException, CadiException, APIException { System.out.println("Validating Configuration..."); final AAFCon<?> aafcon = new AAFConHttp(pa,Config.AAF_URL,new SecurityInfoC<HttpURLConnection>(pa)); diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenClientFactory.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenClientFactory.java index c507a826..772040c3 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenClientFactory.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenClientFactory.java @@ -38,11 +38,11 @@ import org.onap.aaf.cadi.Hash; import org.onap.aaf.cadi.Locator; import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.Symm; -import org.onap.aaf.cadi.aaf.Defaults; import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; import org.onap.aaf.cadi.aaf.v2_0.AAFLocator; import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.config.SecurityInfoC; +import org.onap.aaf.cadi.configure.Agent; import org.onap.aaf.cadi.locator.PropertyLocator; import org.onap.aaf.cadi.locator.SingleEndpointLocator; import org.onap.aaf.cadi.oauth.TokenClient.AUTHN_METHOD; @@ -62,12 +62,12 @@ public class TokenClientFactory extends Persist<Token,TimedToken> { private TokenClientFactory(Access pa) throws APIException, GeneralSecurityException, IOException, CadiException { super(pa, new RosettaEnv(pa.getProperties()),Token.class,"outgoing"); - + Map<String, String> aaf_urls = Agent.loadURLs(pa); if (access.getProperty(Config.AAF_OAUTH2_TOKEN_URL,null)==null) { - access.getProperties().put(Config.AAF_OAUTH2_TOKEN_URL, Config.OAUTH2_TOKEN_URL_DEF); // Default to AAF + access.getProperties().put(Config.AAF_OAUTH2_TOKEN_URL, aaf_urls.get(Config.AAF_OAUTH2_TOKEN_URL)); // Default to AAF } if (access.getProperty(Config.AAF_OAUTH2_INTROSPECT_URL,null)==null) { - access.getProperties().put(Config.AAF_OAUTH2_INTROSPECT_URL, Config.OAUTH2_INTROSPECT_URL_DEF); // Default to AAF); + access.getProperties().put(Config.AAF_OAUTH2_INTROSPECT_URL, aaf_urls.get(Config.AAF_OAUTH2_INTROSPECT_URL)); // Default to AAF); } symm = Symm.encrypt.obtain(); diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java index 75cddfff..c9b8b4ee 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java @@ -246,7 +246,7 @@ public class AAFSSO { Symm decryptor = ArtifactDir.getSymm(dot_aaf_kf); if (user == null) { if (sso.exists()) { - String cm_url = access.getProperty(Config.CM_URL); // SSO might overwrite... + String cm_url = access.getProperty(Config.AAF_URL_CM); // SSO might overwrite... FileInputStream fos = new FileInputStream(sso); try { access.load(fos); @@ -256,7 +256,7 @@ public class AAFSSO { access.setProperty(Config.AAF_APPPASS, access.encrypt(decryptor.depass(encrypted_pass))); if (cm_url != null) { //Command line CM_URL Overwrites ssofile. - access.setProperty(Config.CM_URL, cm_url); + access.setProperty(Config.AAF_URL_CM, cm_url); } } finally { fos.close(); @@ -325,8 +325,8 @@ public class AAFSSO { access.setProperty(Config.AAF_URL, locateRoot+".service:"+apiVersion); } - if(access.getProperty(Config.CM_URL)==null) { - access.setProperty(Config.CM_URL, locateRoot+".cm:"+apiVersion); + if(access.getProperty(Config.AAF_URL_CM)==null) { + access.setProperty(Config.AAF_URL_CM, locateRoot+".cm:"+apiVersion); } String cadiLatitude = access.getProperty(Config.CADI_LATITUDE); if (cadiLatitude==null) { diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/oauth/test/JU_OAuthTest.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/oauth/test/JU_OAuthTest.java index 03c99d2a..6759d314 100644 --- a/cadi/aaf/src/test/java/org/onap/aaf/cadi/oauth/test/JU_OAuthTest.java +++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/oauth/test/JU_OAuthTest.java @@ -67,6 +67,8 @@ public class JU_OAuthTest { System.setOut(new PrintStream(outStream)); access = new PropAccess(); + access.setProperty(Config.CADI_LATITUDE, "38"); + access.setProperty(Config.CADI_LONGITUDE, "-72"); try { tcf = TokenClientFactory.instance(access); } catch (Exception e) { diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/register/test/JU_RegistrationCreator.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/register/test/JU_RegistrationCreator.java index 6f3884b7..af344d2f 100644 --- a/cadi/aaf/src/test/java/org/onap/aaf/cadi/register/test/JU_RegistrationCreator.java +++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/register/test/JU_RegistrationCreator.java @@ -45,6 +45,7 @@ public class JU_RegistrationCreator { PropAccess pa = new PropAccess(); pa.setProperty(Config.CADI_LATITUDE, "32.7"); pa.setProperty(Config.CADI_LONGITUDE, "-72.0"); + pa.setProperty(Config.AAF_LOCATOR_NAME, ""); try { String hostname = Inet4Address.getLocalHost().getHostName(); diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java index 056651eb..9255128c 100644 --- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java +++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java @@ -168,6 +168,10 @@ public class HClient implements EClient<HttpURLConnection> { public URI getURI() { return uri; } + + public void setURI(URI uri) { + this.uri = uri; + } public int timeout() { return connectTimeout; 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 07a791e8..ff1f3955 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 @@ -152,15 +152,7 @@ public class Config { 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/%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_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.token:" + AAF_DEFAULT_API_VERSION +"/token"; - public static final String OAUTH2_INTROSPECT_URL_DEF = "https://AAF_LOCATE_URL/%CNS.%AAF_NS.introspect:" + AAF_DEFAULT_API_VERSION +"/introspect";; - + public static final String AAF_URL = "aaf_url"; //URL for AAF... Use to trigger AAF configuration public static final String AAF_LOCATOR_CLASS = "aaf_locator_class"; // AAF Locator Entries are ADDITIONAL entries, which also gives the Property ability // to set these entries manually @@ -181,6 +173,7 @@ public class Config { 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_FQDN = "aaf_locator_public_fqdn"; + public static final String AAF_LOCATOR_PUBLIC_NAME = "aaf_locator_public_name"; public static final String AAF_APPID = "aaf_id"; public static final String AAF_APPPASS = "aaf_password"; @@ -217,8 +210,10 @@ public class Config { 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"; + public static final String AAF_URL_GUI="aaf_url_gui"; + public static final String AAF_URL_FS="aaf_url_fs"; + public static final String AAF_URL_CM = "aaf_url_cm"; + public static final String AAF_URL_HELLO = "aaf_url_hello"; public static final String CM_TRUSTED_CAS = "cm_trusted_cas"; public static final String PATHFILTER_URLPATTERN = "pathfilter_urlpattern"; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java index 997803bb..50f17e88 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java @@ -24,8 +24,8 @@ import java.net.Inet4Address; import java.net.UnknownHostException; import org.onap.aaf.cadi.Access; -import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.Access.Level; +import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.util.Split; public class RegistrationPropHolder { @@ -89,8 +89,17 @@ public class RegistrationPropHolder { if(firstlog) { access.printf(Level.INIT, REGI,"public_fqdn",public_fqdn); } - - default_name = access.getProperty(Config.AAF_LOCATOR_NAME, PUBLIC_NAME); + + // Allow Container to reset the standard name for public + String container_public_name = access.getProperty(Config.AAF_LOCATOR_PUBLIC_NAME+'.'+default_container, null); + if(container_public_name==null) { + container_public_name = access.getProperty(Config.AAF_LOCATOR_PUBLIC_NAME, null); + if(container_public_name==null) { + container_public_name = access.getProperty(Config.AAF_LOCATOR_NAME, PUBLIC_NAME); + } + } + default_name = container_public_name; + if(firstlog) { access.printf(Level.INIT, REGI,"default_name",default_name); } @@ -171,12 +180,23 @@ public class RegistrationPropHolder { return replacements("RegistrationPropHolder.getEntryName",str,entry,dot_le); } + public String getPublicEntryName(final String entry, final String dot_le) { + String str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_NAME+dot_le, null); + if(str==null) { + str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_NAME,null); + } + if(str==null) { + str = default_name; + } + return replacements("RegistrationPropHolder.getEntryName",str,entry,dot_le); + } + private String getNS(String dot_le) { String ns; ns = access.getProperty(Config.AAF_LOCATOR_APP_NS+dot_le,null); if(ns==null) { - ns = access.getProperty(Config.AAF_LOCATOR_APP_NS, ""); + ns = access.getProperty(Config.AAF_LOCATOR_APP_NS, "AAF_NS"); } return ns; } @@ -214,7 +234,12 @@ public class RegistrationPropHolder { if(!str.endsWith("/locate/")) { str+="locate/"; } - value = value.replace("https://AAF_LOCATE_URL/", str); + if(value.startsWith("http:")) { + value = value.replace("http://AAF_LOCATE_URL/", str); + } else { + value = value.replace("https://AAF_LOCATE_URL/", str); + + } } } } diff --git a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java index 10bcdcc2..b09c2b78 100644 --- a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java +++ b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OAuthExample.java @@ -26,17 +26,18 @@ import java.net.ConnectException; import java.security.GeneralSecurityException; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Map; import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.aaf.Defaults; import org.onap.aaf.cadi.client.Future; import org.onap.aaf.cadi.client.Rcli; import org.onap.aaf.cadi.client.Result; import org.onap.aaf.cadi.client.Retryable; import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.configure.Agent; import org.onap.aaf.cadi.oauth.TimedToken; import org.onap.aaf.cadi.oauth.TokenClient; import org.onap.aaf.cadi.oauth.TokenClientFactory; @@ -73,14 +74,16 @@ public class OAuthExample { // Obtain Endpoints for OAuth2 from Properties. Expected is "cadi.properties" file, pointed to by "cadi_prop_files" - String tokenServiceURL = access.getProperty(Config.AAF_OAUTH2_TOKEN_URL,Config.OAUTH2_TOKEN_URL_DEF); // Default to AAF - String tokenIntrospectURL = access.getProperty(Config.AAF_OAUTH2_INTROSPECT_URL,Config.OAUTH2_INTROSPECT_URL_DEF); // Default to AAF); - // Get Hello Service - final String endServicesURL = access.getProperty(Config.AAF_OAUTH2_HELLO_URL,Config.HELLO_URL_DEF); - - final int CALL_TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CALL_TIMEOUT,Config.AAF_CALL_TIMEOUT_DEF)); - try { + Map<String, String> aaf_urls = Agent.loadURLs(access); + Agent.fillMissing(access, aaf_urls); + String tokenServiceURL = access.getProperty(Config.AAF_OAUTH2_TOKEN_URL); // Default to AAF + String tokenIntrospectURL = access.getProperty(Config.AAF_OAUTH2_INTROSPECT_URL); // Default to AAF); + // Get Hello Service + final String endServicesURL = access.getProperty(Config.AAF_OAUTH2_HELLO_URL); + + final int CALL_TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CALL_TIMEOUT,Config.AAF_CALL_TIMEOUT_DEF)); + ////////////////////////////////////////////////////////////////////// // Scenario 1: // Get and use an OAuth Client, which understands Token Management diff --git a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java index 0a653297..b5d087ea 100644 --- a/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java +++ b/cadi/oauth-enduser/src/test/java/org/onap/aaf/cadi/enduser/test/OnapClientExample.java @@ -26,17 +26,18 @@ import java.net.ConnectException; import java.security.GeneralSecurityException; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Map; import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.aaf.Defaults; import org.onap.aaf.cadi.client.Future; import org.onap.aaf.cadi.client.Rcli; import org.onap.aaf.cadi.client.Result; import org.onap.aaf.cadi.client.Retryable; import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.configure.Agent; import org.onap.aaf.cadi.oauth.TimedToken; import org.onap.aaf.cadi.oauth.TokenClient; import org.onap.aaf.cadi.oauth.TokenClientFactory; @@ -59,12 +60,13 @@ public class OnapClientExample { // Property Access // This method will allow you to set "cadi_prop_files" (or any other property) on Command line access = new PropAccess(args); - - // access = PropAccess(); // Note: This style will load "cadi_prop_files" from VM Args - - // Token aware Client Factory + // access = PropAccess(); try { + Map<String, String> aaf_urls = Agent.loadURLs(access); + Agent.fillMissing(access, aaf_urls); + + // Token aware Client Factory tcf = TokenClientFactory.instance(access); } catch (APIException | GeneralSecurityException | IOException | CadiException e1) { access.log(e1, "Unable to setup OAuth Client Factory, Fail Fast"); @@ -104,7 +106,7 @@ public class OnapClientExample { // Use this Token in your client calls with "Tokenized Client" (TzClient) // These should NOT be used cross thread. // Get Hello Service URL... roll your own in your own world. - final String endServicesURL = access.getProperty(Config.AAF_OAUTH2_HELLO_URL,Config.HELLO_URL_DEF); + final String endServicesURL = access.getProperty(Config.AAF_OAUTH2_HELLO_URL); TzClient helloClient = tcf.newTzClient(endServicesURL); |