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=bd8f1a5212cef49e65a3d420ad257f8211214ac3;hb=b91f022e5c6ba0e5360e4b26c320814b07c2607d;hp=c308e775832f83b076dcbd97e56f1e6f145dc7f2;hpb=4b5a7d721d994a49057e9bfb403c7bff1b376660;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 c308e775..bd8f1a52 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,6 +3,8 @@ * 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. @@ -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 { 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; } @@ -161,7 +167,7 @@ public class AAFcli { sb.append(largs[idx], e, v); if ((e = largs[idx].indexOf(']', v)) >= 0) { String p = access.getProperty(largs[idx].substring(v + 2, e),null); - if(p==null) { + if (p==null) { p = System.getProperty(largs[idx].substring(v+2,e)); } ++e; @@ -183,7 +189,7 @@ public class AAFcli { while (rv && idx < largs.length) { // Allow Script to change Credential if (!gui) { - if("as".equalsIgnoreCase(largs[idx])) { + if ("as".equalsIgnoreCase(largs[idx])) { if (largs.length > ++idx) { // get Password from Props with ID as Key String user = largs[idx++]; @@ -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,8 +228,7 @@ public class AAFcli { } } ++idx; - } - } + } continue; // Sleep, typically for reports, to allow DB to update // Milliseconds @@ -244,61 +248,67 @@ 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])) { + if ("REQUEST".equalsIgnoreCase(largs[idx])) { request=true; ++idx; - } else if("FORCE".equalsIgnoreCase(largs[idx])) { + } else if ("FORCE".equalsIgnoreCase(largs[idx])) { force="true"; ++idx; - } else if("DETAILS".equalsIgnoreCase(largs[idx])) { + } 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) { @@ -380,7 +391,7 @@ public class AAFcli { } else { quote = ch; } - } else if(ch=='|' && quote==0) { + } else if (ch=='|' && quote==0) { arr.add(sb.toString()); sb.setLength(0); start = true; @@ -437,7 +448,7 @@ public class AAFcli { try { PropAccess access = aafsso.access(); - if(aafsso.ok()) { + if (aafsso.ok()) { Define.set(access); AuthzEnv env = new AuthzEnv(access); @@ -450,7 +461,7 @@ public class AAFcli { for (int i = 0; i < args.length; ++i) { if ("-i".equalsIgnoreCase(args[i])) { rdr = new InputStreamReader(System.in); - // } else if("-o".equalsIgnoreCase(args[i])) { + // } else if ("-o".equalsIgnoreCase(args[i])) { // // shall we do something different? Output stream is // already done... } else if ("-f".equalsIgnoreCase(args[i])) { @@ -488,7 +499,7 @@ public class AAFcli { aafsso.setStdErrDefault(); // Note, with AAF Locator, this may not longer be necessary 3/2018 Jonathan - if(!aafsso.loginOnly()) { + if (!aafsso.loginOnly()) { // try { // loc = new AAFLocator(si,new URI(access.getProperty(Config.AAF_URL))); // } catch (Throwable t) { @@ -500,9 +511,9 @@ public class AAFcli { // } 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) { + 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"); } @@ -511,13 +522,13 @@ public class AAFcli { aafcon.hman(), aafcon.securityInfo(), aafcon.securityInfo().defSS); // new HBasicAuthSS(si,aafsso.user(), access.decrypt(aafsso.enc_pass(),false))); // } - if(!ignoreDelay) { + if (!ignoreDelay) { File delay = new File("aafcli.delay"); - if(delay.exists()) { + if (delay.exists()) { BufferedReader br = new BufferedReader(new FileReader(delay)); try { globalDelay = Integer.parseInt(br.readLine()); - } catch(Exception e) { + } catch (Exception e) { access.log(Level.DEBUG,e); } finally { br.close(); @@ -536,7 +547,7 @@ public class 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; @@ -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); @@ -596,7 +611,7 @@ public class AAFcli { System.err.println(err); } } - if(noexit==null) { + if (noexit==null) { return; }