source: trunk/www/switch.jsp @ 7536

Last change on this file since 7536 was 7536, checked in by Nicklas Nordborg, 4 years ago

References #2131: Add support for installing multiple authentication managers

Added an "external" version of the default username+password login form. This is is disabled by default but need to be used when another external authentication manager has been installed and some users still need to be able to login with username+password.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 7.6 KB
Line 
1<%-- $Id: switch.jsp 7536 2018-11-28 07:49:22Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006, 2007 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.Application"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.News"
30  import="net.sf.basedb.core.ItemQuery"
31  import="net.sf.basedb.core.ItemResultList"
32  import="net.sf.basedb.core.query.Orders"
33  import="net.sf.basedb.core.query.Hql"
34  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
35  import="net.sf.basedb.util.extensions.ActionIterator"
36  import="net.sf.basedb.clients.web.Base"
37  import="net.sf.basedb.clients.web.util.HTML"
38  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
39  import="net.sf.basedb.clients.web.extensions.JspContext"
40  import="net.sf.basedb.clients.web.extensions.login.LoginFormAction"
41  import="net.sf.basedb.clients.web.extensions.login.PasswordLoginFormFactory"
42  import="net.sf.basedb.clients.web.extensions.login.FieldInfo"
43  import="net.sf.basedb.util.Values"
44  import="java.util.Map"
45  import="java.util.TreeMap"
46%>
47<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
48<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
49<%! 
50// If value is null, return "", else <prefix>+<value>+<suffix>
51String valueIfNotNull(String prefix, String value, String suffix)
52{
53  return value == null ? "" : prefix+value+suffix;
54}
55%>
56<%
57final String login = Values.getString(request.getParameter("login"), "");
58final String requestedLoginForm = Values.getString(request.getParameter("loginForm"), null);
59
60final SessionControl sc = Base.getSessionControl(pageContext, true);
61final String ID = sc.getId();
62final DbControl dc = sc.newDbControl();
63try
64{
65  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext);
66  ExtensionsInvoker<LoginFormAction> invoker = (ExtensionsInvoker<LoginFormAction>)ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form");
67
68  LoginFormAction loginAction = null;
69  String selectedLoginForm = null;
70  Map<String, String> allForms = new TreeMap<String, String>();
71
72  ActionIterator<LoginFormAction> it = invoker.iterate();
73  while (it.hasNext())
74  {
75    LoginFormAction action = it.next();
76    if (action != null)
77    {
78      String formId = action.getId();
79      if (formId == null) formId = it.getExtension().getId();
80      String displayName = action.getDisplayName();
81      if (displayName == null) displayName = it.getExtension().getAbout().getName();
82      allForms.put(formId, displayName);
83     
84      if (loginAction == null || formId.equals(requestedLoginForm))
85      {
86        loginAction = action;
87        selectedLoginForm = formId;
88      }
89    }
90  }
91  if (loginAction == null)
92  {
93    loginAction = PasswordLoginFormFactory.INSTANCE;
94    selectedLoginForm = loginAction.getId();
95  }
96  FieldInfo loginField = loginAction.getLoginField();
97  FieldInfo passwordField = loginAction.getPasswordField();
98  FieldInfo extraField = loginAction.getExtraField();
99  %>
100  <base:page type="popup" title="Switch user">
101  <base:head styles="login.css" scripts="~login.js">
102    <ext:scripts context="<%=jspContext%>" />
103    <ext:stylesheets context="<%=jspContext%>" />
104  </base:head>
105  <base:body data-login-form="<%=HTML.encodeTags(selectedLoginForm)%>" data-requested-form="<%=HTML.encodeTags(requestedLoginForm) %>">
106    <h1>Switch user <base:help helpid="switchuser" /></h1>
107    <form name="login" action="login.jsp" method="post">
108    <input type="hidden" name="ID" value="<%=ID%>">
109    <input type="hidden" name="again" value="1">
110    <input type="hidden" name="redirect" value="">
111    <input type="hidden" name="useAutoStartPage" value="0">
112    <input type="hidden" name="deviceToken" value="">
113 
114    <div class="content">
115      <table class="fullform input100 bottomborder ">
116      <%
117      if (allForms.size() > 0)
118      {
119        %>
120        <tr>
121          <th>Login with</th>
122          <td>
123          <select name="loginForm" id="loginForm" style="min-width: 10em;">
124          <%
125          for (Map.Entry<String, String> entry : allForms.entrySet())
126          {
127            String formId = entry.getKey();
128            %>
129            <option value="<%=formId%>" <%=formId.equals(selectedLoginForm) ? "selected" : ""%>><%=HTML.encodeTags(entry.getValue()) %>
130            <%
131          }
132          %>
133          </select>
134          </td>
135        </tr>
136        <%
137      }
138      %>
139      <tr <%=valueIfNotNull("class=\"", loginField.getClazz(), "\"")%> id="login-row">
140        <th><%=loginField.getPrompt() %></th>
141        <td><input class="text" name="login" id="login"
142          type="<%=loginField.hasHiddenCharacters() ? "password" : "text"%>"
143          value="<%=loginAction.rememberLastLogin() ? HTML.encodeTags(login) : ""%>" 
144          <%=valueIfNotNull("style=\"", loginField.getStyle(), "\"") %>
145          <%=valueIfNotNull("title=\"", loginField.getTooltip(), "\"") %>
146          <%=valueIfNotNull("placeholder=\"", loginField.getPlaceHolder(), "\"") %>
147          <%=loginAction.rememberLastLogin() ? "" : "autocomplete=\"off\""%>
148          data-use-last-login="0"
149          maxlength="100" 
150          tabindex="0">
151        </td>
152      </tr>
153      <tr <%=valueIfNotNull("class=\"", passwordField.getClazz(), "\"")%> id="password-row">
154        <th><%=passwordField.getPrompt() %></th>
155        <td><input class="text" name="password" id="password"
156          type="<%=passwordField.hasHiddenCharacters() ? "password" : "text"%>"
157          <%=valueIfNotNull("style=\"", passwordField.getStyle(), "\"") %>
158          <%=valueIfNotNull("title=\"", passwordField.getTooltip(), "\"") %>
159          <%=valueIfNotNull("placeholder=\"", passwordField.getPlaceHolder(), "\"") %>
160          maxlength="80"
161          tabindex="0">
162        </td>
163      </tr>
164      <%
165      if (extraField != null)
166      {
167        %>
168        <tr <%=valueIfNotNull("class=\"", extraField.getClazz(), "\"")%> id="extra-row">
169          <th><%=extraField.getPrompt() %></th>
170          <td><input class="text" name="extraField" id="extraField"
171            type="<%=extraField.hasHiddenCharacters() ? "password" : "text"%>"
172            <%=valueIfNotNull("style=\"", extraField.getStyle(), "\"") %>
173            <%=valueIfNotNull("title=\"", extraField.getTooltip(), "\"") %>
174            <%=valueIfNotNull("placeholder=\"", extraField.getPlaceHolder(), "\"") %>
175            maxlength="80"
176            tabindex="0">
177          </td>
178        </tr>
179        <%
180      }
181      %>
182      <tr>
183        <th><label for="remainOnPage">Remain on this page</label></th>
184        <td><input type="checkbox" name="remainOnPage" id="remainOnPage" checked value="1"></td>
185      </tr>
186      <%
187      if (loginAction.getHelp() != null)
188      {
189        %>
190        <tr class="dynamic bg-filled-50 topborder">
191          <td colspan="2">
192          <div class="padded">
193            <div class="messagecontainer help" style="font-style: italic;" id="login-help">
194            <%=loginAction.getHelp() %>
195            </div>
196          </div>
197          </td>
198        </tr>
199        <%
200      }
201      else
202      {
203        %>
204        <tr class="dynamic">
205          <th></th>
206          <td></td>
207        </tr>
208        <%
209      }
210      %>
211      </table>
212     
213    </div>
214    </form>
215   
216    <base:buttongroup subclass="dialogbuttons">
217      <base:button id="btnLogin" image="login.png" title="Login" />
218      <base:button id="close" title="Cancel" />
219    </base:buttongroup>
220
221  </base:body>
222  </base:page>
223  <%
224}
225finally
226{
227  if (dc != null) dc.close();
228}
229%>
230
Note: See TracBrowser for help on using the repository browser.