X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cmd%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fcmd%2FAAFcli.java;h=2c084428d052282cf5a17b238e55d2903180b857;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=ea366576269761408630afa4a3f57a3d273a02ad;hpb=7e966914050e66219689001ff4ab601a49eef0ac;p=aaf%2Fauthz.git diff --git a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/AAFcli.java b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/AAFcli.java index ea366576..2c084428 100644 --- a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/AAFcli.java +++ b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/AAFcli.java @@ -3,13 +3,15 @@ * org.onap.aaf * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2019 IBM. * =========================================================================== * 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. @@ -86,17 +88,13 @@ public class AAFcli { private static boolean showDetails = false; private static boolean ignoreDelay = false; private static int globalDelay=0; - - public static int timeout() { - return TIMEOUT; - } // Create when only have Access - public AAFcli(Access access, Writer wtr, HMangr hman, SecurityInfoC si, SecuritySetter ss) throws APIException, CadiException { + public AAFcli(Access access, Writer wtr, HMangr hman, SecurityInfoC si, SecuritySetter ss) throws APIException { this(access,new AuthzEnv(access.getProperties()),wtr,hman, si,ss); } - public AAFcli(Access access, AuthzEnv env, Writer wtr, HMangr hman, SecurityInfoC si, SecuritySetter ss) throws APIException, CadiException { + public AAFcli(Access access, AuthzEnv env, Writer wtr, HMangr hman, SecurityInfoC si, SecuritySetter ss) throws APIException { this.env = env; this.access = access; this.ss = ss; @@ -125,6 +123,14 @@ public class AAFcli { cmds.add(new Mgmt(this)); } + public AuthzEnv env() { + return env; + } + + public static int timeout() { + return TIMEOUT; + } + public void verbose(boolean v) { verbose = v; } @@ -209,8 +215,7 @@ public class AAFcli { } } else if ("expect".equalsIgnoreCase(largs[idx])) { expect.clear(); - if (largs.length > idx++) { - if (!"nothing".equals(largs[idx])) { + if ((largs.length > idx++)&&(!"nothing".equals(largs[idx]))) { for (String str : largs[idx].split(",")) { try { if ("Exception".equalsIgnoreCase(str)) { @@ -223,12 +228,11 @@ public class AAFcli { } } ++idx; - } - } + } continue; // Sleep, typically for reports, to allow DB to update // Milliseconds - + } else if ("sleep".equalsIgnoreCase(largs[idx])) { Integer t = Integer.parseInt(largs[++idx]); pw.println("sleep " + t); @@ -244,17 +248,58 @@ public class AAFcli { pw.println("Press to continue..."); ++idx; // Sonar insists we do something with the string, though it's only a pause. Not very helpful... - String sonar = new BufferedReader(new InputStreamReader(System.in)).readLine(); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String sonar; + try { + sonar = br.readLine(); + } finally { + br.close(); + } sonar=""; // this useless code brought to you by Sonar. pw.print(sonar); continue; } else if ("exit".equalsIgnoreCase(largs[idx])) { pw.println("Exiting..."); return false; + } else if ("set".equalsIgnoreCase(largs[idx])) { + while (largs.length > ++idx) { + int equals = largs[idx].indexOf('='); + String tag, value; + if (equals < 0) { + tag = largs[idx]; + value = access.getProperty(Config.AAF_APPPASS,null); + if (value==null) { + break; + } else { + value = access.decrypt(value, false); + if (value==null) { + break; + } + access.getProperties().put(tag, value); + pw.println("set " + tag + " "); + } + } else { + tag = largs[idx].substring(0, equals); + value = largs[idx].substring(++equals); + pw.println("set " + tag + ' ' + value); + } + boolean isTrue = "TRUE".equalsIgnoreCase(value); + if ("FORCE".equalsIgnoreCase(tag)) { + force = value; + } else if ("REQUEST".equalsIgnoreCase(tag)) { + request = isTrue; + } else if ("DETAILS".equalsIgnoreCase(tag)) { + showDetails = isTrue; + } else { + access.getProperties().put(tag, value); + } + } + continue; + // Allow Script to indicate if Failure is what is expected } - } - + } + if ("REQUEST".equalsIgnoreCase(largs[idx])) { request=true; ++idx; @@ -264,41 +309,6 @@ public class AAFcli { } else if ("DETAILS".equalsIgnoreCase(largs[idx])) { showDetails=true; ++idx; - } else if ("set".equalsIgnoreCase(largs[idx])) { - while (largs.length > ++idx) { - int equals = largs[idx].indexOf('='); - String tag, value; - if (equals < 0) { - tag = largs[idx]; - value = access.getProperty(Config.AAF_APPPASS,null); - if (value==null) { - break; - } else { - value = access.decrypt(value, false); - if (value==null) { - break; - } - access.getProperties().put(tag, value); - pw.println("set " + tag + " "); - } - } else { - tag = largs[idx].substring(0, equals); - value = largs[idx].substring(++equals); - pw.println("set " + tag + ' ' + value); - } - boolean isTrue = "TRUE".equalsIgnoreCase(value); - if ("FORCE".equalsIgnoreCase(tag)) { - force = value; - } else if ("REQUEST".equalsIgnoreCase(tag)) { - request = isTrue; - } else if ("DETAILS".equalsIgnoreCase(tag)) { - showDetails = isTrue; - } else { - access.getProperties().put(tag, value); - } - } - continue; - // Allow Script to indicate if Failure is what is expected } int ret = 0; @@ -335,7 +345,7 @@ public class AAFcli { } finally { clearSingleLineProperties(); } - rv = expect.isEmpty() ? true : expect.contains(ret); + rv = expect.isEmpty() || expect.contains(ret); if (verbose) { if (rv) { pw.println(); @@ -364,7 +374,8 @@ public class AAFcli { char last = 0; for (int i = 0; i < line.length(); ++i) { char ch; - if (Character.isWhitespace(ch = line.charAt(i))) { + ch = line.charAt(i); + if (Character.isWhitespace(ch)) { if (start || last==',') { continue; // trim } else if (quote != 0) { @@ -405,7 +416,7 @@ public class AAFcli { System.out.println("For instance, C-b means hold ctrl key and press b, M-b means hold alt and press b\n"); System.out.println("Basic Keybindings:"); - System.out.println("\tC-l - clear screen"); + System.out.println("\tC-l - clear screen"); System.out.println("\tC-a - beginning of line"); System.out.println("\tC-e - end of line"); System.out.println("\tC-b - backward character (left arrow also works)"); @@ -430,7 +441,7 @@ public class AAFcli { */ public static void main(String[] args) { int rv = 0; - + try { AAFSSO aafsso = new AAFSSO(args); String noexit = aafsso.access().getProperty("no_exit"); @@ -440,7 +451,7 @@ public class AAFcli { if (aafsso.ok()) { Define.set(access); AuthzEnv env = new AuthzEnv(access); - + Reader rdr = null; boolean exitOnFailure = true; /* @@ -478,15 +489,15 @@ public class AAFcli { sb.append(args[i]); } } - + AAFConHttp aafcon = new AAFConHttp(access); -// +// // SecurityInfoC si = aafcon.securityInfo(); // Locator loc; - + aafsso.setLogDefault(); aafsso.setStdErrDefault(); - + // Note, with AAF Locator, this may not longer be necessary 3/2018 Jonathan if (!aafsso.loginOnly()) { // try { @@ -498,16 +509,16 @@ public class AAFcli { // // Other Access is done writing to StdOut and StdErr, reset Std out // aafsso.setLogDefault(); // } - + TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); -// HMangr hman = new HMangr(access, loc).readTimeout(TIMEOUT).apiVersion(Config.AAF_DEFAULT_VERSION); - +// HMangr hman = new HMangr(access, loc).readTimeout(TIMEOUT).apiVersion(Config.AAF_DEFAULT_API_VERSION); + if (access.getProperty(Config.AAF_DEFAULT_REALM)==null) { access.setProperty(Config.AAF_DEFAULT_REALM, "people.osaaf.org"); aafsso.addProp(Config.AAF_DEFAULT_REALM, "people.osaaf.org"); } - - AAFcli aafcli = new AAFcli(access,env, new OutputStreamWriter(System.out), + + AAFcli aafcli = new AAFcli(access,env, new OutputStreamWriter(System.out), aafcon.hman(), aafcon.securityInfo(), aafcon.securityInfo().defSS); // new HBasicAuthSS(si,aafsso.user(), access.decrypt(aafsso.enc_pass(),false))); // } @@ -529,18 +540,18 @@ public class AAFcli { System.out.println("Type 'help' for short help or 'help -d' for detailed help with aafcli commands"); System.out.println("Type '?' for help with command line editing"); System.out.println("Type 'q', 'quit', or 'exit' to quit aafcli\n"); - + ConsoleReader reader = new ConsoleReader(); try { reader.setPrompt("aafcli > "); - + String line; while ((line = reader.readLine()) != null) { - showDetails = (line.contains("-d"))?true:false; - + showDetails = (line.contains("-d")); + if (line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("q") || line.equalsIgnoreCase("exit")) { break; - } else if (line.equalsIgnoreCase("--help -d") || line.equalsIgnoreCase("help -d") + } else if (line.equalsIgnoreCase("--help -d") || line.equalsIgnoreCase("help -d") || line.equalsIgnoreCase("help")) { line = "--help"; } else if (line.equalsIgnoreCase("cls")) { @@ -563,12 +574,16 @@ public class AAFcli { } } else if (rdr != null) { BufferedReader br = new BufferedReader(rdr); - String line; - while ((line = br.readLine()) != null) { - if (!aafcli.eval(line) && exitOnFailure) { - rv = 1; - break; + try { + String line; + while ((line = br.readLine()) != null) { + if (!aafcli.eval(line) && exitOnFailure) { + rv = 1; + break; + } } + } finally { + br.close(); } } else { // just run the command line aafcli.verbose(false); @@ -577,10 +592,10 @@ public class AAFcli { } rv = aafcli.eval(sb.toString()) ? 0 : 1; } - + } finally { aafcli.close(); - + // Don't close if No Reader, or it's a Reader of Standard In if (rdr != null && !(rdr instanceof InputStreamReader)) { rdr.close(); @@ -614,7 +629,7 @@ public class AAFcli { public boolean isTest() { return AAFcli.isTest; } - + public boolean isDetailed() { return AAFcli.showDetails; }