AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-gui / src / main / java / org / onap / aaf / auth / gui / pages / LoginLanding.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.gui.pages;
23
24 import java.io.IOException;
25 import java.net.URLDecoder;
26
27 import javax.servlet.http.HttpServletRequest;
28
29 import org.onap.aaf.auth.env.AuthzTrans;
30 import org.onap.aaf.auth.gui.AAF_GUI;
31 import org.onap.aaf.auth.gui.NamedCode;
32 import org.onap.aaf.auth.gui.Page;
33 import org.onap.aaf.cadi.config.Config;
34 import org.onap.aaf.misc.env.APIException;
35 import org.onap.aaf.misc.xgen.Cache;
36 import org.onap.aaf.misc.xgen.DynamicCode;
37 import org.onap.aaf.misc.xgen.Mark;
38 import org.onap.aaf.misc.xgen.html.HTMLGen;
39
40 public class LoginLanding extends Page {
41         public static final String HREF = "/login";
42         static final String NAME = "Login";
43         static final String fields[] = {"id","password","environment"};
44         static final String envs[] = {"DEV","TEST","PROD"};
45         
46         public LoginLanding(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
47                 super(gui.env, NAME,HREF, fields, new NamedCode(true, "content") {
48                         @Override
49                         public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
50                                 hgen.leaf("p").text("No login credentials are found in your current session. " +
51                                              "Choose your preferred login option to continue.").end();
52                                 
53                                 Mark loginPaths = hgen.divID("Pages");
54                                 
55                                 cache.dynamic(hgen, new DynamicCode<HTMLGen, AAF_GUI, AuthzTrans>() {
56                                         @Override
57                                         public void code(AAF_GUI authGUI, AuthzTrans trans, Cache<HTMLGen> cache, HTMLGen xgen) throws APIException, IOException {
58                                                 HttpServletRequest req = trans.get(gui.slot_httpServletRequest, null);
59                                                 if(req!=null) {
60                                                         String query = req.getQueryString();
61                                                         if(query!=null) {
62                                                                 for(String qs : query.split("&")) {
63                                                                         int equals = qs.indexOf('=');
64                                                                         xgen.leaf(HTMLGen.A, "href="+URLDecoder.decode(qs.substring(equals+1),Config.UTF_8)).text(qs.substring(0,equals).replace('_', ' ')).end();
65                                                                 }
66                                                         }
67                                                 }
68                                                 xgen.leaf(HTMLGen.A, "href=gui/home?Authentication=BasicAuth").text("AAF Basic Auth").end();
69                                         }
70                                 });
71 //                              hgen.leaf("a", "href=#","onclick=divVisibility('cso');").text("Global Login").end()
72 //                                      .incr("p", "id=cso","style=display:none").text("this will redirect to global login").end()
73 //                                      .leaf("a", "href=#","onclick=divVisibility('tguard');").text("tGuard").end()
74 //                                      .incr("p", "id=tguard","style=display:none").text("this will redirect to tGuard login").end()
75 //                              hgen.leaf("a", "href=#","onclick=divVisibility('basicauth');").text("AAF Basic Auth").end();
76                                 hgen.end(loginPaths);
77                                 
78 //                                      hgen.incr("form","method=post","style=display:none","id=basicauth","gui/home?Authentication=BasicAuth");
79 //                                      Mark table = new Mark(TABLE);
80 //                                      hgen.incr(table);
81 //                                      cache.dynamic(hgen, new DynamicCode<HTMLGen, AuthGUI, AuthzTrans>() {
82 //                                              @Override
83 //                                              public void code(final AuthGUI gui, final AuthzTrans trans,     final Cache<HTMLGen> cache, final HTMLGen hgen) 
84 //                                                              throws APIException, IOException {
85 //                                                      hgen
86 //                                                      .input(fields[0],"Username",true)
87 //                                                      .input(fields[1],"Password",true, "type=password");
88 //                                              Mark selectRow = new Mark();
89 //                                              hgen
90 //                                              .incr(selectRow, "tr")
91 //                                              .incr("td")
92 //                                              .incr("label", "for=envs", "required").text("Environment").end()
93 //                                              .end()
94 //                                              .incr("td")
95 //                                              .incr("select", "name=envs", "id=envs", "required")
96 //                                              .incr("option", "value=").text("Select Environment").end();
97 //                                              for (String env : envs) {
98 //                                                      hgen.incr("option", "value="+env).text(env).end();
99 //                                              }
100 //                                              hgen                    
101 //                                              .end(selectRow) 
102                                                         
103 //                                              hgen.end();
104 //                                              }
105 //                                      });
106 //                                      hgen.end();
107 //                                      hgen.tagOnly("input", "type=submit", "value=Submit")
108 //                                              .tagOnly("input", "type=reset", "value=Reset")
109 //                                      .end();
110                         
111
112                         }
113                 });
114         }
115 }