1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.client;
\r
25 import java.io.File;
\r
26 import java.io.FileInputStream;
\r
27 import java.io.FileOutputStream;
\r
28 import java.io.PrintStream;
\r
29 import java.net.URI;
\r
31 import org.onap.aaf.cadi.Symm;
\r
32 import org.onap.aaf.cadi.config.Config;
\r
34 import com.att.aft.dme2.api.DME2Client;
\r
36 public abstract class RawClient {
\r
37 protected static String aafid, aafpass, aafurl;
\r
38 protected static Symm symm;
\r
40 protected static boolean init(PrintStream out) {
\r
42 String propfile = System.getProperty(Config.CADI_PROP_FILES);
\r
43 if(propfile==null) {
\r
44 propfile = "raw.props";
\r
46 File pfile = new File(propfile);
\r
47 if(!pfile.exists()) {
\r
48 if(propfile.equals("raw.props")) {
\r
49 out.println("Creating 'raw.props'. Edit for proper values, then run again. Alternatively, set "
\r
50 + Config.CADI_PROP_FILES+" to a cadi properties file");
\r
51 FileOutputStream fos = new FileOutputStream(pfile);
\r
52 PrintStream ps = new PrintStream(fos);
\r
54 ps.println("# Use http://www.bing.com/maps to figure out LAT/LONG of an Address");
\r
55 ps.println("AFT_LATITUDE=38.432930");
\r
56 ps.println("AFT_LONGITUDE=-90.432480");
\r
57 ps.println("AFT_ENVIRONMENT=AFTUAT");
\r
58 ps.print(Config.AAF_URL);
\r
59 ps.println("=aaf_url=https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=BAU_SE");
\r
60 ps.print(Config.CADI_KEYFILE);
\r
61 ps.println("=<keyfile. use java -jar cadi-core*.jar in lib dir>");
\r
62 ps.println(Config.AAF_MECHID);
\r
63 ps.print("=<your id>");
\r
64 ps.println(Config.AAF_MECHPASS);
\r
65 ps.print("=<your encrypted password. use java -jar cadi-core*.jar in lib dir>");
\r
71 FileInputStream fis = new FileInputStream(propfile);
\r
73 System.getProperties().load(fis);
\r
78 String cadiKeyFile = System.getProperty(Config.CADI_KEYFILE);
\r
79 aafid = System.getProperty(Config.AAF_MECHID);
\r
80 aafpass = System.getProperty(Config.AAF_MECHPASS);
\r
81 aafurl = System.getProperty(Config.AAF_URL);
\r
82 out.println("Contacting: " + aafurl);
\r
84 if(cadiKeyFile==null || aafid==null || aafpass==null || aafurl==null ) {
\r
85 out.print(Config.CADI_KEYFILE);
\r
87 out.print(Config.CADI_KEYFILE);
\r
89 out.print(Config.CADI_KEYFILE);
\r
91 out.print(Config.CADI_KEYFILE);
\r
92 out.print(" need to be set in ");
\r
93 out.println(propfile);
\r
95 fis = new FileInputStream(cadiKeyFile);
\r
97 symm = Symm.obtain(fis);
\r
104 } catch (Exception e) {
\r
105 e.printStackTrace(out);
\r
111 public abstract String call(final PrintStream out, final String meth, final String path) throws Exception;
\r
113 public static void main(String[] args) {
\r
115 PrintStream out = System.out;
\r
119 if(args.length<2) {
\r
120 System.out.println("Parameters: <Method> <path>");
\r
122 RawClient client = new DME2();
\r
123 out.println(client.call(out,args[0],args[1]));
\r
126 } catch (Exception e) {
\r
127 e.printStackTrace(out);
\r
131 protected static class DME2 extends RawClient {
\r
133 public String call(final PrintStream out, final String meth, final String path) {
\r
135 DME2Client client = new DME2Client(new URI(aafurl),10000);
\r
136 client.setCredentials(aafid, symm.depass(aafpass));
\r
137 client.setMethod(meth);
\r
138 client.setContext(path);
\r
140 if("GET".equalsIgnoreCase(meth) ||
\r
141 "DELETE".equalsIgnoreCase(meth)) {
\r
142 client.setPayload("");
\r
143 } else if("POST".equalsIgnoreCase(meth) ||
\r
144 "PUT".equalsIgnoreCase(meth)) {
\r
146 StringBuilder sb = new StringBuilder();
\r
147 while((c=System.in.read()) >=0) {
\r
148 sb.append((char)c);
\r
150 client.setPayload(sb.toString());
\r
152 return client.sendAndWait(10000);
\r
153 } catch (Exception e) {
\r
154 e.printStackTrace(out);
\r