SONAR flagged fixes 91/90591/1
authorInstrumental <jonathan.gathman@att.com>
Thu, 27 Jun 2019 12:48:27 +0000 (07:48 -0500)
committerInstrumental <jonathan.gathman@att.com>
Thu, 27 Jun 2019 12:48:33 +0000 (07:48 -0500)
Issue-ID: AAF-857
Change-Id: I0b2d6b985fd7f8abc3d133d6db37865aa300e75f
Signed-off-by: Instrumental <jonathan.gathman@att.com>
auth/auth-core/src/main/java/org/onap/aaf/auth/org/OrganizationFactory.java
auth/auth-core/src/main/java/org/onap/aaf/auth/validation/Validator.java
auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Page.java
auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/Home.java
cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java
cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java
cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java

index 943b92f..098fb97 100644 (file)
@@ -71,7 +71,7 @@ public class OrganizationFactory {
                                String realm = env.getProperty(Config.AAF_DEFAULT_REALM,"people.osaaf.org");
                                defaultOrg = cnst.newInstance(env,realm);
                        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) {
-                       env.warn().log("Default Organization Module not linked in",e);
+                       env.init().log("Default Organization Module not linked in",e);
                        }
         }
         if (defaultOrg == null) {
index c0f2f53..98c0907 100644 (file)
@@ -185,13 +185,16 @@ public class Validator {
     }
 
     public final Validator role(String user, String role) {
+       boolean quit = false;
        if(role==null) {
                msg("Role is null");
+               quit = true;
        }
        if(user==null) {
-               msg("User is null");                    
+               msg("User is null");
+               quit = true;
        }
-       if(!err()) {
+       if(!quit) {
                if(role.startsWith(user) && role.endsWith(":user")) {
                        if(!(role.length() == user.length() + 5)) {
                    msg("Role [" + role + "] is invalid.");
index 243e66b..9abd5ee 100644 (file)
@@ -92,6 +92,23 @@ public class Page extends HTMLCacheGen {
 
     // Note: Only access is synchronized in "getPerm"
     private final static Map<String,Map<String,Permission>> perms = new HashMap<>();
+    
+    /*
+     *      Relative path, Menu Name, Full Path
+     */
+    protected static final String[][] MENU_ITEMS = new String[][] {
+               {"myperms","My Permissions","/gui/myperms"},
+               {"myroles","My Roles","/gui/myroles"},
+               {"ns","My Namespaces","/gui/ns"},
+               {"approve","My Approvals","/gui/approve"},
+               {"myrequests","My Pending Requests","/gui/myrequests"},
+                   // Enable later
+               //  {"onboard","Onboarding"},
+               {"passwd","Password Management","/gui/passwd"},
+               {"cui","Command Prompt","/gui/cui"},
+               {"api","AAF API","/gui/api"},
+               {"clear","Clear Preferences","/gui/clear"}
+    };
 
     public String name() {
         return bcName;
@@ -426,7 +443,7 @@ public class Page extends HTMLCacheGen {
                                                .text("Home")
                                                .end(2);
                                        boolean noSelection = !selected;
-                                       for(String[] mi : Home.MENU_ITEMS) {
+                                       for(String[] mi : MENU_ITEMS) {
                                                //selected = trans.path().endsWith(mi[0]);
                                                if(noSelection) {
                                                        selected = isSelected(trans.path(),mi[2]);
index 463ee11..73e118a 100644 (file)
@@ -37,22 +37,6 @@ import org.onap.aaf.misc.xgen.html.HTMLGen;
 
 public class Home extends Page {
     public static final String HREF = "/gui/home";
-    /*
-     *      Relative path, Menu Name, Full Path
-     */
-    public static final String[][] MENU_ITEMS = new String[][] {
-               {"myperms","My Permissions","/gui/myperms"},
-               {"myroles","My Roles","/gui/myroles"},
-               {"ns","My Namespaces","/gui/ns"},
-               {"approve","My Approvals","/gui/approve"},
-               {"myrequests","My Pending Requests","/gui/myrequests"},
-                   // Enable later
-               //  {"onboard","Onboarding"},
-               {"passwd","Password Management","/gui/passwd"},
-               {"cui","Command Prompt","/gui/cui"},
-               {"api","AAF API","/gui/api"},
-               {"clear","Clear Preferences","/gui/clear"}
-    };
     
        public Home(final AAF_GUI gui) throws APIException, IOException {
         super(gui.env,"Home",HREF, NO_FIELDS, new NamedCode(false,"content") {
index 49bab49..98abfbf 100644 (file)
@@ -393,6 +393,9 @@ public class Agent {
     private static String fqi(Deque<String> cmds) {
         if (cmds.size()<1) {
             String alias = env.getProperty(Config.CADI_ALIAS);
+            if(alias==null) {
+               alias = env.getProperty(Config.AAF_APPID);
+            }
             return alias!=null?alias:AAFSSO.cons.readLine("AppID: ");
         }
         return cmds.removeFirst();    
index 4737880..fac6a3f 100644 (file)
@@ -42,7 +42,11 @@ import org.onap.aaf.cadi.util.Split;
 
 public class PropAccess implements Access {
     // Sonar says cannot be static... it's ok.  not too many PropAccesses created.
-    private final static SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+    private final SimpleDateFormat iso8601 = newISO8601();
+               
+    public static SimpleDateFormat newISO8601() {
+       return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+    }
 
     public static final Level DEFAULT = Level.AUDIT;
     
@@ -258,14 +262,13 @@ public class PropAccess implements Access {
         }
     }
 
-    protected StringBuilder buildMsg(Level level, Object[] elements) {
+    public StringBuilder buildMsg(Level level, Object[] elements) {
         return buildMsg(name,iso8601,level,elements);
     }
-
-    public static StringBuilder buildMsg(final String name, Level level, Object[] elements) {
-       return buildMsg(name,iso8601,level,elements);
-    }
     
+    /*
+     * Need to pass in DateFormat per thread, because not marked as thread safe
+     */
     public static StringBuilder buildMsg(final String name, final DateFormat sdf, Level level, Object[] elements) {
        final StringBuilder sb;
         int end = elements.length;
index f74f194..adb6918 100644 (file)
@@ -565,7 +565,7 @@ public class Config {
             }
             access.log(Level.INIT, sb);
 
-            Locator<URI> locator = loadLocator(si, logProp(rph, Config.getAAFLocateUrl(access), null));
+            Locator<URI> locator = loadLocator(si, aafURL);
             
             taf = new HttpEpiTaf(access,locator, tc, htarray); // ok to pass locator == null
             String level = logProp(access, CADI_LOGLEVEL, null);
@@ -850,6 +850,21 @@ public class Config {
         if (_url==null) {
             access.log(Level.INIT,"No URL passed to 'loadLocator'. Disabled");
         } else {
+               try {
+                       Class<?> aalCls = Class.forName("org.onap.aaf.cadi.aaf.v2_0.AbsAAFLocator");
+                       Method aalMth = aalCls.getMethod("create", String.class,String.class);
+                       int colon = _url.lastIndexOf(':');
+                       if(colon>=0) {
+                               String version = _url.substring(colon+1);
+                               int slash = _url.lastIndexOf('/',colon);
+                               if(slash>=0) {
+                                       Object aal = aalMth.invoke(null/*static*/, _url.substring(slash+1, colon),version);
+                                       return (Locator<URI>)aal;
+                               }
+                       }
+               } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+                       access.log(Level.DEBUG, "Configured AbsAAFLocator not found.  Continuing Locator creation");
+               }
 //            String url = _url.replace("/AAF_NS.", "/%C%CID%AAF_NS.");
 //            String root_ns = access.getProperty(Config.AAF_ROOT_NS, null);
                String url;