From dcaa1072621c7e0f586e2965fd8bb952d4b01880 Mon Sep 17 00:00:00 2001 From: Instrumental Date: Thu, 24 May 2018 10:03:19 -0500 Subject: Add Cert Cred for aafcli Issue-ID: AAF-322 Change-Id: I507e43b56922d8c5771a3027deda173be00fa4af Signed-off-by: Instrumental --- auth/auth-cmd/pom.xml | 33 ++- auth/auth-cmd/src/assemble/auth-cmd.xml | 34 +++ .../main/java/org/onap/aaf/auth/cmd/AAFcli.java | 292 ++++++++++----------- auth/auth-cmd/temp | 0 .../main/java/org/onap/aaf/auth/common/Define.java | 2 +- 5 files changed, 206 insertions(+), 155 deletions(-) create mode 100644 auth/auth-cmd/src/assemble/auth-cmd.xml delete mode 100644 auth/auth-cmd/temp (limited to 'auth') diff --git a/auth/auth-cmd/pom.xml b/auth/auth-cmd/pom.xml index 1adf1350..3f7c74a3 100644 --- a/auth/auth-cmd/pom.xml +++ b/auth/auth-cmd/pom.xml @@ -95,7 +95,6 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.7 true ${nexusproxy} @@ -106,7 +105,6 @@ org.jacoco jacoco-maven-plugin - ${jacoco.version} **/gen/** @@ -165,6 +163,35 @@ + + maven-assembly-plugin + + tests + + + org.onap.aaf.auth.cmd.AAFcli + + + true + + + + + + full + package + + single + + + + src/assemble/auth-cmd.xml + + + + + + @@ -172,13 +199,11 @@ org.onap.aaf.authz aaf-cadi-aaf - ${project.version} org.onap.aaf.authz aaf-auth-core - ${project.version} diff --git a/auth/auth-cmd/src/assemble/auth-cmd.xml b/auth/auth-cmd/src/assemble/auth-cmd.xml new file mode 100644 index 00000000..7a86ea84 --- /dev/null +++ b/auth/auth-cmd/src/assemble/auth-cmd.xml @@ -0,0 +1,34 @@ + + + + full + + jar + + + false + + + true + compile + + org.onap.aaf.authz:aaf-auth-cmd + org.onap.aaf.authz:aaf-auth-core + org.onap.aaf.authz:aaf-auth-client + org.onap.aaf.authz:aaf-cadi-aaf + org.onap.aaf.authz:aaf-cadi-core + org.onap.aaf.authz:aaf-cadi-client + org.onap.aaf.authz:aaf-misc-env + org.onap.aaf.authz:aaf-misc-rosetta + jline:jline + + + + + + + src/main/xsd + + + \ No newline at end of file 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 72aa0ccd..2efbff73 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 @@ -42,11 +42,11 @@ import org.onap.aaf.auth.cmd.user.User; import org.onap.aaf.auth.common.Define; import org.onap.aaf.auth.env.AuthzEnv; import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.Locator; import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.SecuritySetter; -import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.aaf.v2_0.AAFLocator; import org.onap.aaf.cadi.client.Retryable; import org.onap.aaf.cadi.config.Config; @@ -59,7 +59,6 @@ import org.onap.aaf.misc.env.APIException; import jline.console.ConsoleReader; public class AAFcli { - private static final String HTTPS = "https://"; protected static PrintWriter pw; protected HMangr hman; // Storage for last reused client. We can do this @@ -439,174 +438,167 @@ public class AAFcli { AAFSSO aafsso = new AAFSSO(args); try { PropAccess access = aafsso.access(); - Define.set(access); - AuthzEnv env = new AuthzEnv(access); - - StringBuilder err = aafsso.err(); - String noexit = access.getProperty("no_exit"); - if (err != null) { - err.append("to continue..."); - System.err.println(err); - if(noexit!=null) { - System.exit(1); - } - } - - Reader rdr = null; - boolean exitOnFailure = true; - /* - * Check for "-" options anywhere in command line - */ - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < args.length; ++i) { - if ("-i".equalsIgnoreCase(args[i])) { - rdr = new InputStreamReader(System.in); - // } else if("-o".equalsIgnoreCase(args[i])) { - // // shall we do something different? Output stream is - // already done... - } else if ("-f".equalsIgnoreCase(args[i])) { - if (args.length > i + 1) { - rdr = new FileReader(args[++i]); - } - } else if ("-a".equalsIgnoreCase(args[i])) { - exitOnFailure = false; - } else if ("-c".equalsIgnoreCase(args[i])) { - isConsole = true; - } else if ("-s".equalsIgnoreCase(args[i]) && args.length > i + 1) { - access.setProperty(Cmd.STARTDATE, args[++i]); - } else if ("-e".equalsIgnoreCase(args[i]) && args.length > i + 1) { - access.setProperty(Cmd.ENDDATE, args[++i]); - } else if ("-t".equalsIgnoreCase(args[i])) { - isTest = true; - } else if ("-d".equalsIgnoreCase(args[i])) { - showDetails = true; - } else if ("-n".equalsIgnoreCase(args[i])) { - ignoreDelay = true; - } else { - if (sb.length() > 0) { - sb.append(' '); - } - sb.append(args[i]); - } - } - - SecurityInfoC si = SecurityInfoC.instance(access, HttpURLConnection.class); - Locator loc; - String aafUrl = access.getProperty(Config.AAF_URL); - if(aafUrl==null) { - aafsso.setLogDefault(); - aafsso.setStdErrDefault(); - aafUrl=AAFSSO.cons.readLine("aaf_url=%s", HTTPS); - if(aafUrl.length()==0) { - System.exit(0); - } else if(!aafUrl.startsWith(HTTPS)) { - aafUrl=HTTPS+aafUrl; - } - aafsso.addProp(Config.AAF_URL, aafUrl); - } - // Note, with AAF Locator, this may not longer be necessary 3/2018 Jonathan - if(!aafsso.loginOnly()) { - try { - loc = new AAFLocator(si,new URI(aafUrl)); - } catch (Throwable t) { - aafsso.setStdErrDefault(); - throw t; - } finally { - // 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("2.0"); + if(aafsso.ok()) { + Define.set(access); + AuthzEnv env = new AuthzEnv(access); - if(access.getProperty(Config.AAF_DEFAULT_REALM)==null) { - access.log(Level.ERROR, Config.AAF_DEFAULT_REALM,"is required"); + Reader rdr = null; + boolean exitOnFailure = true; + /* + * Check for "-" options anywhere in command line + */ + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < args.length; ++i) { + if ("-i".equalsIgnoreCase(args[i])) { + rdr = new InputStreamReader(System.in); + // } else if("-o".equalsIgnoreCase(args[i])) { + // // shall we do something different? Output stream is + // already done... + } else if ("-f".equalsIgnoreCase(args[i])) { + if (args.length > i + 1) { + rdr = new FileReader(args[++i]); + } + } else if ("-a".equalsIgnoreCase(args[i])) { + exitOnFailure = false; + } else if ("-c".equalsIgnoreCase(args[i])) { + isConsole = true; + } else if ("-s".equalsIgnoreCase(args[i]) && args.length > i + 1) { + access.setProperty(Cmd.STARTDATE, args[++i]); + } else if ("-e".equalsIgnoreCase(args[i]) && args.length > i + 1) { + access.setProperty(Cmd.ENDDATE, args[++i]); + } else if ("-t".equalsIgnoreCase(args[i])) { + isTest = true; + } else if ("-d".equalsIgnoreCase(args[i])) { + showDetails = true; + } else if ("-n".equalsIgnoreCase(args[i])) { + ignoreDelay = true; + } else { + if (sb.length() > 0) { + sb.append(' '); + } + sb.append(args[i]); + } } + SecurityInfoC si = SecurityInfoC.instance(access, HttpURLConnection.class); + Locator loc; - AAFcli aafcli = new AAFcli(access,env, new OutputStreamWriter(System.out), hman, si, - new HBasicAuthSS(si,aafsso.user(), access.decrypt(aafsso.enc_pass(),false))); - if(!ignoreDelay) { - File delay = new File("aafcli.delay"); - if(delay.exists()) { - BufferedReader br = new BufferedReader(new FileReader(delay)); - try { - globalDelay = Integer.parseInt(br.readLine()); - } catch(Exception e) { - access.log(Level.DEBUG,e); - } finally { - br.close(); + aafsso.setLogDefault(); + aafsso.setStdErrDefault(); + + // Note, with AAF Locator, this may not longer be necessary 3/2018 Jonathan + if(!aafsso.loginOnly()) { + try { + loc = new AAFLocator(si,new URI(access.getProperty(Config.AAF_URL))); + } catch (Throwable t) { + aafsso.setStdErrDefault(); + throw t; + } finally { + // 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); + + 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), hman, si, + new HBasicAuthSS(si,aafsso.user(), access.decrypt(aafsso.enc_pass(),false))); + if(!ignoreDelay) { + File delay = new File("aafcli.delay"); + if(delay.exists()) { + BufferedReader br = new BufferedReader(new FileReader(delay)); + try { + globalDelay = Integer.parseInt(br.readLine()); + } catch(Exception e) { + access.log(Level.DEBUG,e); + } finally { + br.close(); + } } } - } - try { - if (isConsole) { - 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 > "); + try { + if (isConsole) { + 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; + + if (line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("q") || line.equalsIgnoreCase("exit")) { + break; + } else if (line.equalsIgnoreCase("--help -d") || line.equalsIgnoreCase("help -d") + || line.equalsIgnoreCase("help")) { + line = "--help"; + } else if (line.equalsIgnoreCase("cls")) { + reader.clearScreen(); + continue; + } else if (line.equalsIgnoreCase("?")) { + keyboardHelp(); + continue; + } + try { + aafcli.eval(line); + pw.flush(); + } catch (Exception e) { + pw.println(e.getMessage()); + pw.flush(); + } + } + } finally { + reader.close(); + } + } else if (rdr != null) { + BufferedReader br = new BufferedReader(rdr); String line; - while ((line = reader.readLine()) != null) { - showDetails = (line.contains("-d"))?true:false; - - if (line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("q") || line.equalsIgnoreCase("exit")) { + while ((line = br.readLine()) != null) { + if (!aafcli.eval(line) && exitOnFailure) { + rv = 1; break; - } else if (line.equalsIgnoreCase("--help -d") || line.equalsIgnoreCase("help -d") - || line.equalsIgnoreCase("help")) { - line = "--help"; - } else if (line.equalsIgnoreCase("cls")) { - reader.clearScreen(); - continue; - } else if (line.equalsIgnoreCase("?")) { - keyboardHelp(); - continue; - } - try { - aafcli.eval(line); - pw.flush(); - } catch (Exception e) { - pw.println(e.getMessage()); - pw.flush(); } } - } finally { - reader.close(); - } - } else if (rdr != null) { - BufferedReader br = new BufferedReader(rdr); - String line; - while ((line = br.readLine()) != null) { - if (!aafcli.eval(line) && exitOnFailure) { - rv = 1; - break; + } else { // just run the command line + aafcli.verbose(false); + if (sb.length() == 0) { + sb.append("--help"); } + rv = aafcli.eval(sb.toString()) ? 0 : 1; } - } else { // just run the command line - aafcli.verbose(false); - if (sb.length() == 0) { - sb.append("--help"); + + } 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(); } - 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(); } } } - aafsso.writeFiles(); } finally { aafsso.close(); + StringBuilder err = aafsso.err(); + String noexit = aafsso.access().getProperty("no_exit"); + if (err != null) { + err.append("to continue..."); + System.err.println(err); + } + if(noexit==null) { + return; + } + } - } catch (MessageException e) { System.out.println("MessageException caught"); diff --git a/auth/auth-cmd/temp b/auth/auth-cmd/temp deleted file mode 100644 index e69de29b..00000000 diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/common/Define.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/common/Define.java index 6f0ea084..1e7a0530 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/common/Define.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/common/Define.java @@ -51,7 +51,7 @@ public class Define { } public static void set(Access access) throws CadiException { - ROOT_NS = access.getProperty(Config.AAF_ROOT_NS,"org.onap.aaf"); + ROOT_NS = access.getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); ROOT_COMPANY = access.getProperty(Config.AAF_ROOT_COMPANY,null); if(ROOT_COMPANY==null) { int last = ROOT_NS.lastIndexOf('.'); -- cgit 1.2.3-korg