Merge "Sonar Fix: ApprovalDAO.java"
[aaf/authz.git] / auth / auth-cmd / src / main / java / org / onap / aaf / auth / cmd / AAFcli.java
index ea36657..9e01d7c 100644 (file)
@@ -3,6 +3,8 @@
  * org.onap.aaf
  * ===========================================================================
  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ *
+ * Modifications Copyright (C) 2018 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<HttpURLConnection> si, SecuritySetter<HttpURLConnection> 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<HttpURLConnection> si, SecuritySetter<HttpURLConnection> ss) throws APIException, CadiException {
+    public AAFcli(Access access, AuthzEnv env, Writer wtr, HMangr hman, SecurityInfoC<HttpURLConnection> si, SecuritySetter<HttpURLConnection> 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;
     }
@@ -251,6 +257,41 @@ public class AAFcli {
                 } 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 + " <encrypted>");
+                            }
+                        } 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
                 }
 
             } 
@@ -264,41 +305,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 + " <encrypted>");
-                        }
-                    } 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;
@@ -326,7 +332,7 @@ public class AAFcli {
                             Thread.sleep((long)(delay+globalDelay));
                         }
                     } catch (Exception e) {
-                        if (expect.contains(-1)) {
+                       if (expect.contains(-1)) {
                             pw.println(e.getMessage());
                             ret = -1;
                         } else {
@@ -335,7 +341,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();
@@ -500,7 +506,7 @@ 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) {
                             access.setProperty(Config.AAF_DEFAULT_REALM, "people.osaaf.org");
@@ -536,7 +542,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;