changed to unmaintained
[aaf/authz.git] / auth / auth-gui / src / main / java / org / onap / aaf / auth / gui / Page.java
index 96c0fc4..b9ade57 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
@@ -63,8 +63,8 @@ import org.onap.aaf.misc.xgen.html.HTMLGen;
 import org.onap.aaf.misc.xgen.html.Imports;
 
 /**
- * A Base "Mobile First" Page 
- * 
+ * A Base "Mobile First" Page
+ *
  * @author Jonathan
  *
  */
@@ -78,21 +78,24 @@ public class Page extends HTMLCacheGen {
     public static final String AAF_URL_CADI_HELP = "aaf_url.cadi_help";
     public static final String PERM_CA_TYPE = "certman";
     public static final String PERM_NS = Define.ROOT_NS();
+    public static final String HREF = "href=";
+    public static final String TARGET_BLANK = "target=_blank";
 
-    public static enum BROWSER {iPhone,html5,ie,ieOld};
+    public enum BROWSER {IPHONE, HTML5, IE, IEOLD};
 
     public static final int MAX_LINE = 20;
     protected static final String[] NO_FIELDS = new String[0];
     private static final String BROWSER_TYPE = "BROWSER_TYPE";
 
-    private final String bcName, bcUrl;
+    private final String bcName;
+    private final String bcUrl;
     private final String[] fields;
 
-    public final boolean no_cache;
+    public final boolean noCache;
 
     // Note: Only access is synchronized in "getPerm"
-    private final static Map<String,Map<String,Permission>> perms = new HashMap<>();
-    
+    private static final Map<String,Map<String,Permission>> perms = new HashMap<>();
+
     /*
      *      Relative path, Menu Name, Full Path
      */
@@ -102,8 +105,8 @@ public class Page extends HTMLCacheGen {
             {"ns","My Namespaces","/gui/ns"},
             {"approve","My Approvals","/gui/approve"},
             {"myrequests","My Pending Requests","/gui/myrequests"},
-                    // Enable later
-           //  {"onboard","Onboarding"},
+             // Enable later
+             //{"onboard","Onboarding"},
             {"passwd","Password Management","/gui/passwd"},
             {"cui","Command Prompt","/gui/cui"},
             {"api","AAF API","/gui/api"},
@@ -113,15 +116,15 @@ public class Page extends HTMLCacheGen {
     public String name() {
         return bcName;
     }
-    
+
     public String url() {
         return bcUrl;
     }
-    
+
     public String[] fields() {
         return fields;
     }
-    
+
     public Page(AuthzEnv env, String name, String url, Enum<?>[] en, final NamedCode ...content) throws APIException, IOException {
         super(CacheGen.PRETTY, new PageCode(env, 1, content));
         fields = new String[en.length];
@@ -133,19 +136,19 @@ public class Page extends HTMLCacheGen {
         bcName = name;
         bcUrl = url;
         // Mark which fields must be "no_cache"
-        boolean no_cacheTemp=false;
+        boolean noCacheTemp=false;
         for (NamedCode nc : content) {
-            if (nc.no_cache()) { 
-                no_cacheTemp=true;
+            if (nc.noCache()) {
+                noCacheTemp=true;
                 break;
             }
         }
-        no_cache=no_cacheTemp;
+        noCache =noCacheTemp;
     }
     public Page(AuthzEnv env, String name, String url, String [] fields, final NamedCode ... content) throws APIException,IOException {
         this(env,name,url,1,fields,content);
     }
-    
+
     public Page(AuthzEnv env, String name, String url, int backdots, String [] fields, final NamedCode ... content) throws APIException,IOException {
         super(CacheGen.PRETTY, new PageCode(env, backdots, content));
         if (fields==null) {
@@ -156,21 +159,21 @@ public class Page extends HTMLCacheGen {
         bcName = name;
         bcUrl = url;
         // Mark which fields must be "no_cache"
-        boolean no_cacheTemp=false;
+        boolean noCacheTemp=false;
         for (NamedCode nc : content) {
-            if (nc.no_cache()) { 
-                no_cacheTemp=true;
+            if (nc.noCache()) {
+                noCacheTemp=true;
                 break;
             }
         }
-        no_cache=no_cacheTemp;
+        noCache =noCacheTemp;
     }
-    
-    
+
+
     private static class PageCode implements Code<HTMLGen> {
             private static final String AAF_GUI_THEME = "aaf.gui.theme";
             private static final String AAF_GUI_TITLE = "aaf_gui_title";
-            
+
             private final ContentCode[] content;
             private final Slot browserSlot;
             private final int backdots;
@@ -210,7 +213,7 @@ public class Page extends HTMLCacheGen {
                                                 props = new Properties();
                                                 themeProps.put(t.getName(), props);
                                             }
-                                            
+
                                             try {
                                                 FileInputStream fis = new FileInputStream(f);
                                                 try {
@@ -233,7 +236,7 @@ public class Page extends HTMLCacheGen {
                 }
                 return themes.get(theme);
             }
-            
+
             protected Imports getImports(Env env, String theme, int backdots, BROWSER browser) {
                 List<String> ls = getThemeFiles(env,theme);
                 Imports imp = new Imports(backdots);
@@ -243,11 +246,11 @@ public class Page extends HTMLCacheGen {
                         imp.js(prefix + f);
                     } else if(f.endsWith(".css")) {
                         if(f.endsWith("iPhone.css")) {
-                            if(BROWSER.iPhone.equals(browser)) {
+                            if(BROWSER.IPHONE.equals(browser)) {
                                 imp.css(prefix + f);
                             }
                         } else if (f.endsWith("Desktop.css")){
-                            if(!BROWSER.iPhone.equals(browser)) {
+                            if(!BROWSER.IPHONE.equals(browser)) {
                                 imp.css(prefix + f);
                             }
                         // Make Console specific to Console page
@@ -258,17 +261,17 @@ public class Page extends HTMLCacheGen {
                 }
                 return imp;
             }
-            
+
             @Override
             public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
-                // Note: I found that App Storage saves everything about the page, or not.  Thus, if you declare the page uncacheable, none of the 
+                // Note: I found that App Storage saves everything about the page, or not.  Thus, if you declare the page uncacheable, none of the
                 // Artifacts, like JPGs are stored, which makes this feature useless for Server driven elements
                 cache.dynamic(hgen,  new DynamicCode<HTMLGen,AAF_GUI,AuthzTrans>() {
                     @Override
                     public void code(AAF_GUI state, AuthzTrans trans, final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
                         switch(browser(trans,browserSlot)) {
-                            case ieOld:
-                            case ie:
+                            case IEOLD:
+                            case IE:
                                 hgen.directive("!DOCTYPE html");
                                 hgen.directive("meta", "http-equiv=X-UA-Compatible","content=IE=11");
                             default:
@@ -277,14 +280,14 @@ public class Page extends HTMLCacheGen {
                 });
                 hgen.html();
                 final String title = env.getProperty(AAF_GUI_TITLE,"Authentication/Authorization Framework");
-                final String defaultTheme = env.get(sTheme,"onap"); 
-              
+                final String defaultTheme = env.get(sTheme,"onap");
+
                 Mark head = hgen.head();
                     hgen.leaf(TITLE).text(title).end();
                     cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI,AuthzTrans>() {
                         @Override
                         public void code(AAF_GUI state, AuthzTrans trans, final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
-                            BROWSER browser = browser(trans,browserSlot);  
+                            BROWSER browser = browser(trans,browserSlot);
                             String theme = null;
                             Cookie[] cookies = trans.hreq().getCookies();
                             if(cookies!=null) {
@@ -298,7 +301,7 @@ public class Page extends HTMLCacheGen {
                                     }
                                 }
                             }
-                            
+
                             if(theme==null) {
                                 for(String t : themes.keySet()) {
                                     if(!t.equals(defaultTheme) && trans.fish(new AAFPermission(null,trans.user()+":id", AAF_GUI_THEME, t))) {
@@ -309,6 +312,10 @@ public class Page extends HTMLCacheGen {
                                 if(theme==null) {
                                     theme = defaultTheme;
                                 }
+                                List<String> ls = getThemeFiles(trans, theme);
+                                if(ls==null) {
+                                    throw new APIException("Theme " + theme + " does not exist.");
+                                }
                                 Cookie cookie = new Cookie(AAF_GUI_THEME,theme);
                                 cookie.setMaxAge(604_800); // one week
                                 trans.hresp().addCookie(cookie);
@@ -317,19 +324,19 @@ public class Page extends HTMLCacheGen {
 
                             hgen.imports(getImports(env,theme,backdots,browser));
                             switch(browser) {
-                                case ie:
-                                case ieOld:
+                                case IE:
+                                case IEOLD:
                                     hgen.js().text("document.createElement('header');")
                                             .text("document.createElement('nav');")
                                             .done();
                                     break;
                                 default:
                             }
-                            
+
                         }
                     });
                     hgen.end(head);
-                    
+
                 Mark body = hgen.body();
                     Mark header = hgen.header();
                     cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI,AuthzTrans>() {
@@ -341,10 +348,11 @@ public class Page extends HTMLCacheGen {
                             String env = trans.getProperty(Config.AAF_ENV,"N/A");
                             xgen.leaf(H1).text(title + " on " + env).end();
                             xgen.leaf("p","id=version").text("AAF Version: " + state.deployedVersion).end();
-                            
+
                             // Obtain User Info, and print
                             TaggedPrincipal p = trans.getUserPrincipal();
-                            String user,secured;
+                            String user;
+                            String secured;
                             if (p==null) {
                                 user = "please choose a Login Authority";
                                 secured = "NOT Secure!";
@@ -357,11 +365,11 @@ public class Page extends HTMLCacheGen {
                                 .text("<sup>")
                                 .text(secured)
                                 .text("</sup>").end();
-                            
+
                             switch(browser(trans,browserSlot)) {
-                                case ieOld:
-                                case ie:
-                                    xgen.incr("h5").text("This app is Mobile First HTML5.  Internet Explorer " 
+                                case IEOLD:
+                                case IE:
+                                    xgen.incr("h5").text("This app is Mobile First HTML5.  Internet Explorer "
                                             + " does not support all HTML5 standards. Old, non TSS-Standard versions may not function correctly.").br()
                                             .text("  For best results, use a highly compliant HTML5 browser like Firefox.")
                                         .end();
@@ -370,9 +378,9 @@ public class Page extends HTMLCacheGen {
                             }
                         }
                     });
-                    
+
                     hgen.hr();
-                    
+
                     int cIdx;
                     ContentCode nc;
                     // If BreadCrumbs, put here
@@ -385,7 +393,7 @@ public class Page extends HTMLCacheGen {
                     } else {
                         cIdx = 0;
                     }
-                    
+
                     hgen.end(header);
 
                     hgen.divID("pageContent");
@@ -398,9 +406,9 @@ public class Page extends HTMLCacheGen {
                             hgen.end(ctnt);
                         }
 
-                    hgen.end(inner);    
+                    hgen.end(inner);
+
 
-                    
                     cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI,AuthzTrans>() {
                         @Override
                         public void code(AAF_GUI state, AuthzTrans trans,Cache<HTMLGen> cache, HTMLGen xgen) throws APIException, IOException {
@@ -411,7 +419,7 @@ public class Page extends HTMLCacheGen {
                             } else {
                                 props = themeProps==null?null:themeProps.get(theme);
                             }
-                            
+
                             if(props!=null && "TRUE".equalsIgnoreCase(props.getProperty("enable_nav_btn"))) {
                                     xgen.leaf("button", "id=navBtn").end();
                             }
@@ -430,13 +438,11 @@ public class Page extends HTMLCacheGen {
                             } else {
                                 props = themeProps==null?null:themeProps.get(theme);
                             }
-                            
-                            if(props!=null) {
-                                if("TRUE".equalsIgnoreCase(props.getProperty("main_menu_in_nav"))) {
+
+                            if((props!=null) && ("TRUE".equalsIgnoreCase(props.getProperty("main_menu_in_nav")))) {
                                     xgen.incr("h2").text("Navigation").end();
                                     Mark mark = new Mark();
                                     boolean selected = isSelected(trans.path(),Home.HREF);
-                                            //trans.path().endsWith("home");
                                     xgen.incr(mark,HTMLGen.UL)
                                         .incr(HTMLGen.LI,selected?"class=selected":"")
                                         .incr(HTMLGen.A, "href=home")
@@ -444,7 +450,6 @@ public class Page extends HTMLCacheGen {
                                         .end(2);
                                     boolean noSelection = !selected;
                                     for(String[] mi : MENU_ITEMS) {
-                                        //selected = trans.path().endsWith(mi[0]);
                                         if(noSelection) {
                                             selected = isSelected(trans.path(),mi[2]);
                                             noSelection = !selected;
@@ -452,12 +457,11 @@ public class Page extends HTMLCacheGen {
                                             selected = false;
                                         }
                                         xgen.incr(HTMLGen.LI,selected?"class=selected":"")
-                                            .incr(HTMLGen.A, "href="+mi[2])
+                                            .incr(HTMLGen.A, HREF+mi[2])
                                             .text(mi[1])
                                             .end(2);
                                     }
                                     xgen.end(mark);
-                                }
                             }
                         }
 
@@ -484,21 +488,21 @@ public class Page extends HTMLCacheGen {
                     });
                     hgen.incr("h2").text("Related Links").end();
                     hgen.incr(UL);
-                    String aaf_help = env.getProperty(AAF_URL_AAF_HELP,null);
-                    if (aaf_help!=null) {
-                        hgen.leaf(LI).leaf(A,"href="+env.getProperty(AAF_URL_AAF_HELP),"target=_blank").text("AAF WIKI").end(2);
+                    String aafHelp = env.getProperty(AAF_URL_AAF_HELP,null);
+                    if (aafHelp!=null) {
+                        hgen.leaf(LI).leaf(A,HREF+env.getProperty(AAF_URL_AAF_HELP),TARGET_BLANK).text("AAF WIKI").end(2);
                         String sub = env.getProperty(AAF_URL_AAF_HELP+".sub");
                         if (sub!=null) {
                             hgen.incr(UL,"style=margin-left:5%");
                             for (String s : Split.splitTrim(',', sub)) {
-                                hgen.leaf(LI).leaf(A,"href="+env.getProperty(AAF_URL_AAF_HELP+".sub."+s),"target=_blank").text(s.replace('+', ' ')).end(2);
+                                hgen.leaf(LI).leaf(A,HREF+env.getProperty(AAF_URL_AAF_HELP+".sub."+s),TARGET_BLANK).text(s.replace('+', ' ')).end(2);
                             }
                             hgen.end();
                         }
                     }
-                    aaf_help = env.getProperty(AAF_URL_CADI_HELP,null);
-                    if (aaf_help!=null) {
-                        hgen.leaf(LI).leaf(A,"href="+aaf_help,"target=_blank").text("CADI WIKI").end(2);
+                    aafHelp = env.getProperty(AAF_URL_CADI_HELP,null);
+                    if (aafHelp!=null) {
+                        hgen.leaf(LI).leaf(A,HREF+aafHelp,TARGET_BLANK).text("CADI WIKI").end(2);
                     }
                     String tools = env.getProperty(AAFURL_TOOLS);
                     if (tools!=null) {
@@ -507,20 +511,20 @@ public class Page extends HTMLCacheGen {
                              .leaf(HTMLGen.H3).text("Related Tools").end();
 
                         for (String tool : Split.splitTrim(',',tools)) {
-                            hgen.leaf(LI).leaf(A,"href="+env.getProperty(AAF_URL_TOOL_DOT+tool),"target=_blank").text(tool.replace('+', ' ')).end(2);
+                            hgen.leaf(LI).leaf(A,HREF+env.getProperty(AAF_URL_TOOL_DOT+tool),TARGET_BLANK).text(tool.replace('+', ' ')).end(2);
                         }
                         hgen.end();
                     }
                     hgen.end();
-                    
+
                     hgen.hr();
-                    
+
                     hgen.end(nav);
                     // Footer - Using older Footer to work with decrepit IE versions
                     Mark footer = hgen.divID("footer");
                         hgen.textCR(1, env.getProperty(AAF_GUI.AAF_GUI_COPYRIGHT))
                         .end(footer);
-                        
+
                     hgen.end(body);
                 hgen.endAll();
         }
@@ -529,27 +533,27 @@ public class Page extends HTMLCacheGen {
     public static String getBrowserType() {
         return BROWSER_TYPE;
     }
-    
+
     /**
      * It's IE if int >=0
-     * 
+     *
      * Use int found in "ieVersion"
-     * 
+     *
      * Official IE 7
-     *         Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; 
+     *         Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322;
      *         .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
      * Official IE 8
-     *         Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; 
+     *         Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2;
      *         .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; ATT)
-     * 
+     *
      * IE 11 Compatibility
-     *         Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; 
+     *         Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727;
      *         .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; InfoPath.3; HVD; ATT)
-     * 
+     *
      * IE 11 (not Compatiblity)
-     *         Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; 
+     *         Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727;
      *         .NET CLR 3.5.30729; .NET CLR 3.0.30729;    Media Center PC 6.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; InfoPath.3; HVD; ATT)
-     * 
+     *
      * @param trans
      * @return
      */
@@ -557,27 +561,27 @@ public class Page extends HTMLCacheGen {
         BROWSER br = trans.get(slot, null);
         if (br==null) {
             String agent = trans.agent();
-            int msie; 
+            int msie;
             if (agent.contains("iPhone") /* other phones? */) {
-                br=BROWSER.iPhone;
+                br=BROWSER.IPHONE;
             } else if ((msie = agent.indexOf("MSIE"))>=0) {
                 msie+=5;
-                int end = agent.indexOf(";",msie);
+                int end = agent.indexOf(';',msie);
                 float ver;
                 try {
                     ver = Float.valueOf(agent.substring(msie,end));
-                    br = ver<8f?BROWSER.ieOld:BROWSER.ie;
+                    br = ver<8f?BROWSER.IEOLD :BROWSER.IE;
                 } catch (Exception e) {
-                    br = BROWSER.ie;
+                    br = BROWSER.IE;
                 }
             } else {
-                br = BROWSER.html5;
+                br = BROWSER.HTML5;
             }
             trans.put(slot,br);
         }
         return br;
     }
-    
+
     /*
      * Get, rather than create each time, permissions for validations
      */
@@ -599,7 +603,7 @@ public class Page extends HTMLCacheGen {
      }
 
     protected static String getSingleParam(HttpServletRequest req, String tag) {
-        String values[] = req.getParameterValues(tag);
+        String[] values = req.getParameterValues(tag);
         return values.length<1?null:values[0];
     }