389bc90345731f1dc52a4281df65e927c5f683ae
[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.slotHttpServletRequest, 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.end(loginPaths);
72             }
73         });
74     }
75 }