+++ /dev/null
-/*******************************************************************************\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.client;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.PrintStream;\r
-import java.net.URI;\r
-\r
-import org.onap.aaf.cadi.Symm;\r
-import org.onap.aaf.cadi.config.Config;\r
-\r
-import com.att.aft.dme2.api.DME2Client;\r
-\r
-public abstract class RawClient {\r
- protected static String aafid, aafpass, aafurl;\r
- protected static Symm symm;\r
- \r
- protected static boolean init(PrintStream out) {\r
- try {\r
- String propfile = System.getProperty(Config.CADI_PROP_FILES);\r
- if(propfile==null) {\r
- propfile = "raw.props";\r
- }\r
- File pfile = new File(propfile);\r
- if(!pfile.exists()) {\r
- if(propfile.equals("raw.props")) {\r
- out.println("Creating 'raw.props'. Edit for proper values, then run again. Alternatively, set "\r
- + Config.CADI_PROP_FILES+" to a cadi properties file");\r
- FileOutputStream fos = new FileOutputStream(pfile);\r
- PrintStream ps = new PrintStream(fos);\r
- try {\r
- ps.println("# Use http://www.bing.com/maps to figure out LAT/LONG of an Address");\r
- ps.println("AFT_LATITUDE=38.432930");\r
- ps.println("AFT_LONGITUDE=-90.432480");\r
- ps.println("AFT_ENVIRONMENT=AFTUAT");\r
- ps.print(Config.AAF_URL);\r
- ps.println("=aaf_url=https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=BAU_SE");\r
- ps.print(Config.CADI_KEYFILE);\r
- ps.println("=<keyfile. use java -jar cadi-core*.jar in lib dir>");\r
- ps.println(Config.AAF_MECHID);\r
- ps.print("=<your id>");\r
- ps.println(Config.AAF_MECHPASS);\r
- ps.print("=<your encrypted password. use java -jar cadi-core*.jar in lib dir>");\r
- } finally {\r
- ps.close();\r
- }\r
- }\r
- } else {\r
- FileInputStream fis = new FileInputStream(propfile);\r
- try {\r
- System.getProperties().load(fis);\r
- } finally {\r
- fis.close();\r
- }\r
- \r
- String cadiKeyFile = System.getProperty(Config.CADI_KEYFILE);\r
- aafid = System.getProperty(Config.AAF_MECHID);\r
- aafpass = System.getProperty(Config.AAF_MECHPASS);\r
- aafurl = System.getProperty(Config.AAF_URL);\r
- out.println("Contacting: " + aafurl);\r
-\r
- if(cadiKeyFile==null || aafid==null || aafpass==null || aafurl==null ) {\r
- out.print(Config.CADI_KEYFILE);\r
- out.print(", ");\r
- out.print(Config.CADI_KEYFILE);\r
- out.print(", ");\r
- out.print(Config.CADI_KEYFILE);\r
- out.print(", ");\r
- out.print(Config.CADI_KEYFILE);\r
- out.print(" need to be set in ");\r
- out.println(propfile);\r
- } else {\r
- fis = new FileInputStream(cadiKeyFile);\r
- try {\r
- symm = Symm.obtain(fis);\r
- } finally {\r
- fis.close();\r
- }\r
- }\r
- return true;\r
- }\r
- } catch (Exception e) {\r
- e.printStackTrace(out);\r
- }\r
- return false;\r
-\r
- }\r
- \r
- public abstract String call(final PrintStream out, final String meth, final String path) throws Exception;\r
- \r
- public static void main(String[] args) {\r
- // Sonar idiocy\r
- PrintStream out = System.out;\r
-\r
- try {\r
- if(init(out)) {\r
- if(args.length<2) {\r
- System.out.println("Parameters: <Method> <path>");\r
- } else {\r
- RawClient client = new DME2();\r
- out.println(client.call(out,args[0],args[1]));\r
- }\r
- } \r
- } catch (Exception e) {\r
- e.printStackTrace(out);\r
- }\r
- }\r
- \r
- protected static class DME2 extends RawClient {\r
-\r
- public String call(final PrintStream out, final String meth, final String path) {\r
- try {\r
- DME2Client client = new DME2Client(new URI(aafurl),10000);\r
- client.setCredentials(aafid, symm.depass(aafpass));\r
- client.setMethod(meth);\r
- client.setContext(path);\r
- \r
- if("GET".equalsIgnoreCase(meth) ||\r
- "DELETE".equalsIgnoreCase(meth)) {\r
- client.setPayload("");\r
- } else if("POST".equalsIgnoreCase(meth) ||\r
- "PUT".equalsIgnoreCase(meth)) {\r
- int c;\r
- StringBuilder sb = new StringBuilder();\r
- while((c=System.in.read()) >=0) {\r
- sb.append((char)c);\r
- }\r
- client.setPayload(sb.toString());\r
- }\r
- return client.sendAndWait(10000);\r
- } catch (Exception e) {\r
- e.printStackTrace(out);\r
- return "";\r
- }\r
- }\r
- }\r
-}\r