X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Faaf%2FTestConnectivity.java;h=6301ac3c3e9f1df1800e4d7c444f0b538f363b71;hb=861b557b294032f9443ee1fca6b42d7252e92481;hp=efcaa7ef3896937eb025d084ecfb8aff08a30737;hpb=f727f876191f815a850b89eb501f49bfd6e65c5d;p=aaf%2Fauthz.git 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 efcaa7ef..6301ac3c 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -53,11 +53,11 @@ import org.onap.aaf.cadi.util.FixURIinfo; import org.onap.aaf.misc.env.APIException; public class TestConnectivity { - + private static Map aaf_urls; - public static void main(String[] args) { + public static void main(String[] args) { if (args.length<1) { System.out.println("Usage: ConnectivityTester []"); } else { @@ -72,7 +72,7 @@ public class TestConnectivity { try { SecurityInfoC si = SecurityInfoC.instance(access, HttpURLConnection.class); aaf_urls = Agent.loadURLs(access); - + List> lss = loadSetters(access,si); ///////// String directAAFURL = aaf_urls.get(Config.AAF_URL); @@ -80,54 +80,55 @@ public class TestConnectivity { print(true,"Test Connections by non-located aaf_url"); Locator locator = new SingleEndpointLocator(directAAFURL); connectTest(locator,new URI(directAAFURL)); - + SecuritySetter ss = si.defSS; permTest(locator,ss); + basicAuthTest(locator,ss); } else { - ///////// - print(true,"Test Connections driven by AAFLocator"); - String serviceURI = aaf_urls.get(Config.AAF_URL); - - for (String url : new String[] { - serviceURI, - 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 locator = new AAFLocator(si, uri); - try { - connectTest(locator, uri); - } catch (Exception e) { - e.printStackTrace(); - System.err.flush(); - } - } - - ///////// - print(true,"Test Service for Perms driven by AAFLocator"); - Locator locator = new AAFLocator(si,new URI(serviceURI)); - for (SecuritySetter ss : lss) { - permTest(locator,ss); - } - - ////////// - print(true,"Test essential BasicAuth Service call, driven by AAFLocator"); - boolean hasBath=false; - for (SecuritySetter ss : lss) { - if (ss instanceof HBasicAuthSS) { - hasBath=true; - basicAuthTest(new AAFLocator(si, new URI(serviceURI)),ss); - } - } - if(!hasBath) { - System.out.println("No User/Password to test"); - } + ///////// + print(true,"Test Connections driven by AAFLocator"); + String serviceURI = aaf_urls.get(Config.AAF_URL); + + for (String url : new String[] { + serviceURI, + 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 locator = new AAFLocator(si, uri); + try { + connectTest(locator, uri); + } catch (Exception e) { + e.printStackTrace(); + System.err.flush(); + } + } + + ///////// + print(true,"Test Service for Perms driven by AAFLocator"); + Locator locator = new AAFLocator(si,new URI(serviceURI)); + for (SecuritySetter ss : lss) { + permTest(locator,ss); + } + + ////////// + print(true,"Test essential BasicAuth Service call, driven by AAFLocator"); + boolean hasBath=false; + for (SecuritySetter ss : lss) { + if (ss instanceof HBasicAuthSS) { + hasBath=true; + basicAuthTest(new AAFLocator(si, new URI(serviceURI)),ss); + } + } + if(!hasBath) { + System.out.println("No User/Password to test"); + } } - + } catch (Exception e) { e.printStackTrace(System.err); } finally { @@ -135,14 +136,14 @@ public class TestConnectivity { } } } - - private static List> loadSetters(PropAccess access, SecurityInfoC si) { + + private static List> loadSetters(PropAccess access, SecurityInfoC si) { print(true,"Load Security Setters from Configuration Information"); String user = access.getProperty(Config.AAF_APPID); ArrayList> lss = new ArrayList<>(); - + try { HBasicAuthSS hbass = new HBasicAuthSS(si,true); @@ -177,7 +178,7 @@ public class TestConnectivity { } catch (Exception e) { access.log(Level.INFO, "AAF OAUTH2 Security Setter constructor threw exception: \"",e.getMessage(),"\". AAF OAUTH2 tests will not be conducted... Continuing"); } - + tokenURL = access.getProperty(Config.AAF_ALT_OAUTH2_TOKEN_URL); if (tokenURL==null) { access.log(Level.INFO, "AAF Alternative OAUTH2 requires",Config.AAF_ALT_OAUTH2_TOKEN_URL, "OAuth2 tests to", tokenURL, "will not be conducted... Continuing"); @@ -190,7 +191,7 @@ public class TestConnectivity { access.log(Level.INFO, "ALT OAUTH2 Security Setter constructor threw exception: \"",e.getMessage(),"\". ALT OAuth2 tests to", tokenURL, " will not be conducted... Continuing"); } } - + return lss; } @@ -227,10 +228,10 @@ 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()); + System.out.printf("Located %s using %s\n",uri.toString(), locatorURI.toString()); socket = new Socket(); try { - FixURIinfo fui = new FixURIinfo(uri); + FixURIinfo fui = new FixURIinfo(uri); try { socket.connect(new InetSocketAddress(fui.getHost(), fui.getPort()),3000); System.out.printf("Can Connect a Socket to %s %d\n",fui.getHost(),fui.getPort()); @@ -261,7 +262,7 @@ public class TestConnectivity { if (ss instanceof HRenewingTokenSS) { System.out.println(" " + ((HRenewingTokenSS)ss).tokenURL()); } else { - System.out.println(); + System.out.println(); } HClient client = new HClient(ss, uri, 3000); client.setMethod("GET"); @@ -270,11 +271,11 @@ public class TestConnectivity { String pathInfo = "/authz/perms/user/"+user; client.setPathInfo(pathInfo); System.out.println(pathInfo); - + client.send(); Future future = client.futureReadString(); if (future.get(7000)) { - System.out.println(future.body()); + System.out.println(future.body()); } else { if (future.code()==401 && ss instanceof HX509SS) { System.out.println(" Authentication denied with 401 for Certificate.\n\t" @@ -298,11 +299,11 @@ public class TestConnectivity { client.setPathInfo("/authn/basicAuth"); client.addHeader("Accept", "text/plain"); client.send(); - - + + Future future = client.futureReadString(); if (future.get(7000)) { - System.out.println("BasicAuth Validated"); + System.out.println("BasicAuth Validated"); } else { System.out.println("Failure " + future.code() + ":" + future.body()); }