6ca160806f9ae86071e6465b5e14ab333766652e
[aaf/authz.git] / authz-gui / src / main / java / com / att / authz / gui / pages / LoginLanding.java
1 /*******************************************************************************
2  * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3  *******************************************************************************/
4 package com.att.authz.gui.pages;
5
6 import java.io.IOException;
7 import java.net.URLDecoder;
8
9 import javax.servlet.http.HttpServletRequest;
10
11 import com.att.authz.env.AuthzTrans;
12 import com.att.authz.gui.AuthGUI;
13 import com.att.authz.gui.NamedCode;
14 import com.att.authz.gui.Page;
15 import org.onap.aaf.cadi.config.Config;
16 import org.onap.aaf.inno.env.APIException;
17 import com.att.xgen.Cache;
18 import com.att.xgen.DynamicCode;
19 import com.att.xgen.Mark;
20 import com.att.xgen.html.HTMLGen;
21
22 public class LoginLanding extends Page {
23         public static final String HREF = "/login";
24         static final String NAME = "Login";
25         static final String fields[] = {"id","password","environment"};
26         static final String envs[] = {"DEV","TEST","PROD"};
27         
28         public LoginLanding(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException {
29                 super(gui.env, NAME,HREF, fields, new NamedCode(true, "content") {
30                         @Override
31                         public void code(Cache<HTMLGen> cache, HTMLGen hgen) throws APIException, IOException {
32                                 hgen.leaf("p").text("No login credentials are found in your current session. " +
33                                              "Choose your preferred login option to continue.").end();
34                                 
35                                 Mark loginPaths = hgen.divID("Pages");
36                                 
37                                 cache.dynamic(hgen, new DynamicCode<HTMLGen, AuthGUI, AuthzTrans>() {
38                                         @Override
39                                         public void code(AuthGUI authGUI, AuthzTrans trans, Cache<HTMLGen> cache, HTMLGen xgen) throws APIException, IOException {
40                                                 HttpServletRequest req = trans.get(gui.slot_httpServletRequest, null);
41                                                 if(req!=null) {
42                                                         String query = req.getQueryString();
43                                                         if(query!=null) {
44                                                                 for(String qs : query.split("&")) {
45                                                                         int equals = qs.indexOf('=');
46                                                                         xgen.leaf(HTMLGen.A, "href="+URLDecoder.decode(qs.substring(equals+1),Config.UTF_8)).text(qs.substring(0,equals).replace('_', ' ')).end();
47                                                                 }
48                                                         }
49                                                 }
50                                                 xgen.leaf(HTMLGen.A, "href=gui/home?Authentication=BasicAuth").text("AAF Basic Auth").end();
51                                         }
52                                 });
53 //                              hgen.leaf("a", "href=#","onclick=divVisibility('cso');").text("Global Login").end()
54 //                                      .incr("p", "id=cso","style=display:none").text("this will redirect to global login").end()
55 //                                      .leaf("a", "href=#","onclick=divVisibility('tguard');").text("tGuard").end()
56 //                                      .incr("p", "id=tguard","style=display:none").text("this will redirect to tGuard login").end()
57 //                              hgen.leaf("a", "href=#","onclick=divVisibility('basicauth');").text("AAF Basic Auth").end();
58                                 hgen.end(loginPaths);
59                                 
60 //                                      hgen.incr("form","method=post","style=display:none","id=basicauth","gui/home?Authentication=BasicAuth");
61 //                                      Mark table = new Mark(TABLE);
62 //                                      hgen.incr(table);
63 //                                      cache.dynamic(hgen, new DynamicCode<HTMLGen, AuthGUI, AuthzTrans>() {
64 //                                              @Override
65 //                                              public void code(AuthGUI gui, AuthzTrans trans, Cache<HTMLGen> cache, HTMLGen hgen)     
66 //                                                              throws APIException, IOException {
67 //                                                      hgen
68 //                                                      .input(fields[0],"Username",true)
69 //                                                      .input(fields[1],"Password",true, "type=password");
70 //                                              Mark selectRow = new Mark();
71 //                                              hgen
72 //                                              .incr(selectRow, "tr")
73 //                                              .incr("td")
74 //                                              .incr("label", "for=envs", "required").text("Environment").end()
75 //                                              .end()
76 //                                              .incr("td")
77 //                                              .incr("select", "name=envs", "id=envs", "required")
78 //                                              .incr("option", "value=").text("Select Environment").end();
79 //                                              for (String env : envs) {
80 //                                                      hgen.incr("option", "value="+env).text(env).end();
81 //                                              }
82 //                                              hgen                    
83 //                                              .end(selectRow) 
84                                                         
85 //                                              hgen.end();
86 //                                              }
87 //                                      });
88 //                                      hgen.end();
89 //                                      hgen.tagOnly("input", "type=submit", "value=Submit")
90 //                                              .tagOnly("input", "type=reset", "value=Reset")
91 //                                      .end();
92                         
93
94                         }
95                 });
96         }
97 }