Remove Code from cadi, it is now in authz
[aaf/cadi.git] / aaf / src / main / java / org / onap / aaf / cadi / aaf / ConnectivityTest.java
diff --git a/aaf/src/main/java/org/onap/aaf/cadi/aaf/ConnectivityTest.java b/aaf/src/main/java/org/onap/aaf/cadi/aaf/ConnectivityTest.java
deleted file mode 100644 (file)
index daac0c3..0000000
+++ /dev/null
@@ -1,459 +0,0 @@
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- *  *      http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- *  * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.onap.aaf.cadi.aaf;\r
-\r
-import java.io.IOException;\r
-import java.io.PrintStream;\r
-import java.lang.reflect.Field;\r
-import java.net.HttpURLConnection;\r
-import java.net.InetAddress;\r
-import java.net.InetSocketAddress;\r
-import java.net.Socket;\r
-import java.net.URI;\r
-import java.net.UnknownHostException;\r
-import java.util.Date;\r
-\r
-import org.onap.aaf.cadi.CadiException;\r
-import org.onap.aaf.cadi.Locator;\r
-import org.onap.aaf.cadi.LocatorException;\r
-import org.onap.aaf.cadi.Lur;\r
-import org.onap.aaf.cadi.PropAccess;\r
-import org.onap.aaf.cadi.SecuritySetter;\r
-import org.onap.aaf.cadi.TrustChecker;\r
-import org.onap.aaf.cadi.Locator.Item;\r
-import org.onap.aaf.cadi.aaf.v2_0.AAFCon;\r
-import org.onap.aaf.cadi.aaf.v2_0.AAFConDME2;\r
-import org.onap.aaf.cadi.client.Future;\r
-import org.onap.aaf.cadi.config.Config;\r
-import org.onap.aaf.cadi.config.SecurityInfoC;\r
-import org.onap.aaf.cadi.http.HBasicAuthSS;\r
-import org.onap.aaf.cadi.http.HClient;\r
-import org.onap.aaf.cadi.http.HX509SS;\r
-import org.onap.aaf.cadi.locator.DME2Locator;\r
-import org.onap.aaf.cadi.locator.PropertyLocator;\r
-\r
-import com.att.aft.dme2.api.DME2Client;\r
-import com.att.aft.dme2.api.DME2Manager;\r
-import org.onap.aaf.inno.env.APIException;\r
-import org.onap.aaf.rosetta.env.RosettaDF;\r
-import org.onap.aaf.rosetta.env.RosettaEnv;\r
-\r
-import aaf.v2_0.Perms;\r
-\r
-public class ConnectivityTest {\r
-       private static final String PROD = "PROD";\r
-       private static final String SRV_RESOLVE = "https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=%s/routeOffer=%s";\r
-       private static final String GW_RESOLVE = "https://DME2RESOLVE/service=com.att.authz.authz-gw/version=2.0/envContext=%s/routeOffer=%s";\r
-       \r
-       public static void main(String[] args) {\r
-               if(args.length<2) {\r
-                       System.out.println("Usage: ConnectivityTester <TEST|IST|PROD> <cadi_prop_files>");\r
-               } else {\r
-                       print(true,"START OF CONNECTIVITY TESTS",new Date().toString(),System.getProperty("user.name"),\r
-                                       "Note: All API Calls are /authz/perms/user/<MechID/Alias of the caller>");\r
-\r
-                       final String aaf_env = args[0];\r
-                       args[1]=Config.CADI_PROP_FILES+'='+args[1];\r
-                       \r
-                       PropAccess pa = new PropAccess(args);\r
-                       String user = pa.getProperty(Config.AAF_MECHID);\r
-                       String pass = pa.getProperty(Config.AAF_MECHPASS);\r
-                       String alias = pa.getProperty(Config.CADI_ALIAS);\r
-                       if(user==null) {\r
-                               user=alias;\r
-                       }\r
-                       RosettaEnv env = new RosettaEnv(pa.getProperties());\r
-                       \r
-                       try {\r
-                               RosettaDF<Perms> permsDF = env.newDataFactory(Perms.class);\r
-                               SecurityInfoC<HttpURLConnection> si = new SecurityInfoC<HttpURLConnection>(pa);\r
-                               HBasicAuthSS hbass = new HBasicAuthSS(pa,si);\r
-                               if(hbass.getID()==null) {\r
-                                       hbass=null; // not configured with ID.\r
-                               }\r
-                               HX509SS hxss=null;\r
-                               AAFCon<?> aafcon;\r
-                               \r
-                               try {\r
-                                       hxss = new HX509SS(user,si);\r
-                               } catch(Exception e) {\r
-                                       e.printStackTrace();\r
-                                       print(false,"Continuing");\r
-                               }\r
-                               String aafurl;\r
-                               if(user==null || (pass==null && alias==null)) {\r
-                                       System.out.printf("ERROR: DME2 Client cannot be tested with out %s and %s properties"\r
-                                                       , Config.AAF_MECHID, Config.AAF_MECHPASS );\r
-                               } else {\r
-                                       if("TEST".equals(aaf_env) || "IST".equals(aaf_env) || "PROD".equals(aaf_env)) {\r
-                                               DME2Manager dm = null;\r
-                                               print(false,"Attempt DME2Manager Load");\r
-                                               if(Class.forName("com.att.aft.dme2.api.DME2Manager")==null) {\r
-                                                       print(true,"DME2 jar is not available:  Skipping DME2 Tests");\r
-                                               } else { // DME2 Client Tests\r
-                                                       pass=pa.decrypt(pass,false);\r
-                                                       // Out of the box DME2\r
-                                                       aafurl = String.format(SRV_RESOLVE, aaf_env, PROD.equals(aaf_env)?"DEFAULT":"BAU_SE");\r
-                                                       print(true,"TEST CADI Config",aafurl);\r
-                                                       aafcon = testConfig(pa,aafurl);\r
-                                                       test(aafcon,permsDF,user);\r
-                                                       \r
-                                                       print(true,"Find and TEST Connections with DME2Locator",aafurl);\r
-                                                       DME2Locator dl = new DME2Locator(pa,dm,aafurl);\r
-                                                       connectTest(dl);\r
-       \r
-                                                       dm =  new DME2Manager("DME2Manager",pa.getProperties());\r
-       \r
-                                                       dme2RawTest(dm, aafurl,user,pass);\r
-                                                       \r
-                                                       // URL specific Variant\r
-                                                       if((aafurl = specificDME2URL(dl, aafurl))!=null) {\r
-                                                               print(true,"TEST Specific DME2 CADI Config",aafurl);\r
-                                                               aafcon = testConfig(pa,aafurl);\r
-                                                               test(aafcon,permsDF,user);\r
-       \r
-                                                               dme2RawTest(dm,aafurl,user,pass);\r
-                                                       }\r
-                                                       \r
-                                                       print(true,"CADI Direct AAFConDME2 Object Usage",aafurl);\r
-                                                       try {\r
-                                                               pa.setProperty(Config.AAF_URL,aafurl);\r
-                                                               aafcon = new AAFConDME2(pa);\r
-                                                               test(aafcon,permsDF,user);\r
-                                                       } catch(Throwable t) {\r
-                                                               t.printStackTrace();\r
-                                                       }\r
-                                                       \r
-                                                       // find a direct client to code a Direct HTTP with\r
-       //                                              \r
-                                                       if(hbass!=null) {\r
-                                                               print(true,"CADI Http DME2Locator Client Coding Methodology BasicAuth",aafurl);\r
-                                                               hClientTest(dl,hbass,user);\r
-                                                       }\r
-                                                       if(hxss!=null) {\r
-                                                               print(true,"CADI Http DME2Locator Client Coding Methodology X509",aafurl);\r
-                                                               hClientTest(dl,hxss,user);\r
-                                                       }\r
-                                                       \r
-                                                       // ##### PROXY CHECKS\r
-                                                       aafurl = String.format(GW_RESOLVE, aaf_env, PROD.equals(aaf_env)?"DEFAULT":"BAU_SE");\r
-                                                       print(true,"TEST PROXY DME2 CADI Config",aafurl);\r
-                                                       aafcon = testConfig(pa,aafurl);\r
-                                                       test(aafcon,permsDF,user);\r
-       \r
-       \r
-                                                       dme2RawTest(dm, aafurl,user,pass);\r
-                                                       \r
-                                                       // URL specific Variant\r
-                                                       dl = new DME2Locator(pa,dm,aafurl);\r
-                                                       if((aafurl = specificDME2URL(dl, aafurl))!=null) {\r
-                                                               print(true,"TEST PROXY Specific DME2 CADI Config",aafurl);\r
-                                                               aafcon = testConfig(pa,aafurl);\r
-                                                               test(aafcon,permsDF,user);\r
-       \r
-                                                               dme2RawTest(dm,aafurl,user,pass);\r
-                                                       }\r
-                                               }\r
-                                       }\r
-\r
-                                       // Prop Locator\r
-                                       PropertyLocator pl = servicePropLocator(aaf_env);\r
-                                       connectTest(pl);\r
-                                       URI uri = pl.get(pl.best());\r
-                                       if(uri!=null) {\r
-                                               aafurl = uri.toString();\r
-                                               print(true,"TEST Service PropertyLocator based Config",aafurl);\r
-                                               aafcon = testConfig(pa,aafurl);\r
-                                               test(aafcon,permsDF,user);\r
-       \r
-                                               if(hbass!=null) {\r
-                                                       print(true,"CADI Service Http PropLocator Client Coding Methodology Basic Auth",aafurl);\r
-                                                       hClientTest(pl,hbass, user);\r
-                                                       print(true,"CADI Service Http PropLocator Client Coding Methodology /authn/basicAuth",aafurl);\r
-                                                       basicAuthTest(pl,hbass);\r
-                                               }\r
-                                               if(hxss!=null) {\r
-                                                       print(true,"CADI Service Http PropLocator Client Coding Methodology X509",aafurl);\r
-                                                       hClientTest(pl,hxss, user);\r
-                                               }\r
-                                       }\r
-                                       pl = proxyPropLocator(aaf_env);\r
-                                       connectTest(pl);\r
-                                       uri = pl.get(pl.best());\r
-                                       if(uri!=null) {\r
-                                               aafurl = uri.toString();\r
-                                               print(true,"TEST PROXY PropertyLocator based Config",aafurl);\r
-                                               aafcon = testConfig(pa,aafurl);\r
-                                               test(aafcon,permsDF,user);\r
-       \r
-                                               if(hbass!=null) {\r
-                                                       print(true,"CADI PROXY Http PropLocator Client Coding Methodology Basic Auth",aafurl);\r
-                                                       hClientTest(pl,hbass, user);\r
-                                                       print(true,"CADI PROXY Http PropLocator Client Coding Methodology /proxy/authn/basicAuth",aafurl);\r
-                                                       basicAuthTest(pl,hbass);\r
-                                               }\r
-                                               if(hxss!=null) {\r
-                                                       print(true,"CADI PROXY Http PropLocator Client Coding Methodology X509",aafurl);\r
-                                                       hClientTest(pl,hxss, user);\r
-                                               }\r
-                                       }\r
-                               }\r
-                               \r
-                       } catch(Exception e) {\r
-                               e.printStackTrace(System.err);\r
-                       } finally {\r
-                               print(true,"END OF TESTS");\r
-                       }\r
-               }\r
-       }\r
-       \r
-       private static void print(Boolean strong, String ... args) {\r
-               PrintStream out = System.out;\r
-               out.println();\r
-               if(strong) {\r
-                       for(int i=0;i<70;++i) {\r
-                               out.print('=');\r
-                       }\r
-                       out.println();\r
-               }\r
-               for(String s : args) {\r
-                       out.print(strong?"==  ":"------ ");\r
-                       out.print(s);\r
-                       if(!strong) {\r
-                               out.print("  ------");\r
-                       }\r
-                       out.println();\r
-               }\r
-               if(strong) {\r
-                       for(int i=0;i<70;++i) {\r
-                               out.print('=');\r
-                       }\r
-               }\r
-               out.println();\r
-       }\r
-\r
-       private static void test(AAFCon<?> aafcon,RosettaDF<Perms> permsDF,String user) {\r
-               if(aafcon==null) {\r
-                       print(false,"AAFCon is null");\r
-               } else {\r
-                       try {\r
-                               print(false,"Calling with AAFCon");\r
-                               Future<Perms> fp = aafcon.client("2.0").read("/authz/perms/user/"+user, Perms.class, permsDF);\r
-                               if(fp.get(4000)) {\r
-                                       System.out.printf("Found %d Permission(s)\n",fp.value.getPerm().size());\r
-                               } else {\r
-                                       System.out.printf("Error: %d %s\n",fp.code(),fp.body());\r
-                               }\r
-                       } catch (Throwable t) {\r
-                               t.printStackTrace();\r
-                       }\r
-               }\r
-       }\r
-       \r
-       private static AAFCon<?> testConfig(PropAccess pa, String aafurl) {\r
-               try {\r
-                       pa.setProperty(Config.AAF_URL, aafurl);\r
-                       Lur lur = Config.configLur(pa);\r
-                       Config.configHttpTaf(pa, TrustChecker.NOTRUST, null, lur);\r
-                       if(lur != null) {\r
-                               Field f = null;\r
-                               try {\r
-                                       f = lur.getClass().getField("aaf");\r
-                                       return (AAFCon<?>)f.get(lur);\r
-                               } catch (Exception nsfe) {\r
-                               }\r
-                       }\r
-\r
-               } catch(Throwable t) {\r
-                       t.printStackTrace();\r
-               }\r
-               return null;\r
-       }\r
-       \r
-       private static String specificDME2URL(Locator<URI> loc, String aafurl) throws LocatorException {\r
-               Item item = loc.best();\r
-               if(item!=null) {\r
-                       URI uri = loc.get(item);\r
-                       return aafurl.replace("DME2RESOLVE", String.format("%s:%d",uri.getHost(),uri.getPort()));\r
-               }\r
-               return null;\r
-       }\r
-\r
-       private static void connectTest(Locator<URI> dl) throws LocatorException {\r
-               URI uri;\r
-               Socket socket;\r
-               print(false,"TCP/IP Connect test to all Located Services");\r
-               for(Item li = dl.first();li!=null;li=dl.next(li)) {\r
-                       if((uri = dl.get(li)) == null) {\r
-                               System.out.println("Locator Item empty");\r
-                       } else {\r
-                               try {\r
-                                       socket = new Socket();\r
-                                       socket.connect(new InetSocketAddress(uri.getHost(),  uri.getPort()),3000);\r
-                                       System.out.printf("Can Connect a Socket to %s %d\n",uri.getHost(),uri.getPort());\r
-                                       try {\r
-                                               socket.close();\r
-                                       } catch (IOException e1) {\r
-                                               System.out.printf("Could not close Socket Connection: %s\n",e1.getMessage());\r
-                                       }\r
-                               } catch (IOException e) {\r
-                                       System.out.printf("Cannot Connect a Socket to  %s %d: %s\n",uri.getHost(),uri.getPort(),e.getMessage());\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       private static PropertyLocator servicePropLocator(String env) throws LocatorException {\r
-               String purls;\r
-               switch(env) {\r
-                       case "LOCAL":\r
-                               try {\r
-                                       purls="https://"+InetAddress.getLocalHost().getHostName()+":8100";\r
-                               } catch (UnknownHostException e) {\r
-                                       throw new LocatorException(e);\r
-                               }\r
-                               break;\r
-                       case "DEV":\r
-                               purls="https://aaf.dev.att.com:8100,https://aaf.dev.att.com:8101";\r
-                               break;\r
-                       case "TEST":\r
-                               purls="https://aaftest.test.att.com:8100,https://aaftest.test.att.com:8101";\r
-                               break;\r
-                       case "IST":\r
-                               purls="https://aafist.test.att.com:8100,https://aafist.test.att.com:8101";\r
-                               break;\r
-                       case PROD:\r
-                               purls="https://aaf.it.att.com:8100,https://aaf.it.att.com:8101";\r
-                               break;\r
-                       default:\r
-                               if(env.contains(".")) {\r
-                                       purls="https://"+env+":8100";\r
-                               } else {\r
-                                       throw new LocatorException(ConnectivityTest.class.getSimpleName() + ": unknown Env");\r
-                               }\r
-               }\r
-               System.out.printf("Creating a PropertyLocator for %s\n",purls);\r
-               return new PropertyLocator(purls);\r
-       }\r
-       \r
-       private static PropertyLocator proxyPropLocator(String env) throws LocatorException {\r
-               String purls;\r
-               switch(env) {\r
-                       case "LOCAL":\r
-                               try {\r
-                                       purls="https://"+InetAddress.getLocalHost().getHostAddress()+":8100";\r
-                               } catch (UnknownHostException e) {\r
-                                       throw new LocatorException(e);\r
-                               }\r
-                               break;\r
-                       case "DEV":\r
-                               purls="https://aaf.dev.att.com:8095/proxy";\r
-                               break;\r
-                       case "TEST":\r
-                               purls="https://aaftest.test.att.com:8095/proxy";\r
-                               break;\r
-                       case "IST":\r
-                               purls="https://aafist.test.att.com:8095/proxy";\r
-                               break;\r
-                       case PROD:\r
-                               purls="https://aaf.it.att.com:8095/proxy";\r
-                               break;\r
-                       default:\r
-                               if(env.contains(".")) {\r
-                                       purls="https://"+env+":8095/proxy";\r
-                               } else {\r
-                                       throw new LocatorException(ConnectivityTest.class.getSimpleName() + ": unknown Env");\r
-                               }\r
-\r
-               }\r
-               System.out.printf("Creating a PropertyLocator for %s\n",purls);\r
-               return new PropertyLocator(purls);\r
-       }\r
-               \r
-       \r
-\r
-\r
-       private static void hClientTest(Locator<URI> dl, SecuritySetter<HttpURLConnection> ss, String user)  {\r
-               try {\r
-                       URI uri = dl.get(dl.best());\r
-                       System.out.println("Resolved to: " + uri);\r
-                       HClient client = new HClient(ss, uri, 3000);\r
-                       client.setMethod("GET");\r
-                       client.setPathInfo("/authz/perms/user/"+user);\r
-                       client.send();\r
-                       Future<String> future = client.futureReadString();\r
-                       if(future.get(7000)) {\r
-                               System.out.println(future.body());      \r
-                       } else {\r
-                               System.out.println(future.code() + ":" + future.body());\r
-                       }\r
-               } catch (CadiException | LocatorException | APIException e) {\r
-                       e.printStackTrace();\r
-               }\r
-       }\r
-\r
-\r
-       private static void basicAuthTest(PropertyLocator dl, SecuritySetter<HttpURLConnection> ss) {\r
-               try {\r
-                       URI uri = dl.get(dl.best());\r
-                       System.out.println("Resolved to: " + uri);\r
-                       HClient client = new HClient(ss, uri, 3000);\r
-                       client.setMethod("GET");\r
-                       client.setPathInfo("/authn/basicAuth");\r
-                       client.addHeader("Accept", "text/plain");\r
-                       client.send();\r
-       \r
-               \r
-                       Future<String> future = client.futureReadString();\r
-                       if(future.get(7000)) {\r
-                               System.out.println("BasicAuth Validated");      \r
-                       } else {\r
-                               System.out.println("Failure " + future.code() + ":" + future.body());\r
-                       }\r
-               } catch (CadiException | LocatorException | APIException e) {\r
-                       e.printStackTrace();\r
-               }\r
-       }\r
-\r
-       // Regular DME2Client Coding Style\r
-       private static void dme2RawTest(DME2Manager dm, String aafurl, String user, String pass) {\r
-               try { \r
-                       if(dm==null) {\r
-                               return;\r
-                       }\r
-                       URI uri = new URI(aafurl);\r
-                       print(true,"DME2 Direct Client Coding Methodology",uri.toString());\r
-                       DME2Client client = dm.newClient( uri, 3000);\r
-                       client.setMethod("GET"); // FYI, DME2 defaults to "POST"\r
-                       client.setContext("/authz/perms/user/"+user); // DME2 direct requires separate setting of Context from URI\r
-                       if(pass!=null) { // rely on Cert if no pass\r
-                               client.setCredentials(user, pass);\r
-                       }\r
-                       client.setPayload(""); // DME2  will not send without something\r
-                       String resp = client.sendAndWait(7000);\r
-                       System.out.println(resp);\r
-               } catch(Throwable e) {\r
-                       e.printStackTrace();\r
-               }\r
-       }\r
-}\r