Changeset 7529 for trunk/www/main.jsp


Ignore:
Timestamp:
Nov 26, 2018, 8:30:41 AM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2131: Add support for installing multiple authentication managers

If there are more than one installed login manager the login page now displays a selection list with the ability to switch between them.

One "problem" is that the CSS and javascript for all login managers are loaded and CSS rules may not work well together. For example, if the Yubikey and OTP extensions are both enabled, the yubikey icon is displayed in the "Login" field also for the OTP login. On the other hand, the OTP icon is always displayed in the help text...

To fix this the extensions need to update their CSS rules so that they only apply when their own login form is active. To help with this, BASE will set an attribute on the <body> tag:

  <body data-login-form="id-of-login-form">

where id-of-login-form' is the value returned by the LoginFormAction?.getId()` method. Scripts should also check this value.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/main.jsp

    r7500 r7529  
    4141  import="net.sf.basedb.core.query.Hql"
    4242  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
     43  import="net.sf.basedb.util.extensions.ActionIterator"
    4344  import="net.sf.basedb.clients.web.Base"
    4445  import="net.sf.basedb.clients.web.util.HTML"
     
    5354  import="net.sf.basedb.util.Values"
    5455  import="java.util.Date"
     56  import="java.util.Map"
     57  import="java.util.TreeMap"
    5558%>
    5659<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    6669final String login = Values.getString(request.getParameter("login"), "");
    6770final String error = Values.getString(request.getParameter("error"), null);
     71final String requestedLoginForm = Values.getString(request.getParameter("loginForm"), null);
    6872final String root = request.getContextPath()+"/";
    6973
     
    8387
    8488  LoginFormAction loginAction = null;
    85   for (LoginFormAction action : invoker)
     89  String selectedLoginForm = null;
     90  Map<String, String> allForms = new TreeMap<String, String>();
     91 
     92  ActionIterator<LoginFormAction> it = invoker.iterate();
     93  while (it.hasNext())
    8694  {
     95    LoginFormAction action = it.next();
    8796    if (action != null)
    8897    {
    89       loginAction = action;
    90       break;
     98      String formId = action.getId();
     99      if (formId == null) formId = it.getExtension().getId();
     100      String displayName = action.getDisplayName();
     101      if (displayName == null) displayName = it.getExtension().getAbout().getName();
     102      allForms.put(formId, displayName);
     103     
     104      if (loginAction == null || formId.equals(requestedLoginForm))
     105      {
     106        loginAction = action;
     107        selectedLoginForm = formId;
     108      }
    91109    }
    92110  }
     
    109127    <ext:stylesheets context="<%=jspContext%>" />
    110128  </base:head>
    111   <base:body style="padding-top: 5em;">
     129  <base:body style="padding-top: 5em;" data-login-form="<%=Values.getString(selectedLoginForm)%>">
    112130    <form name="login" action="login.jsp" method="post">
    113131    <input type="hidden" name="ID" value="<%=ID%>">
     
    122140      {
    123141        %>
    124         <div class="messagecontainer help" style="font-style: italic;" id="login-help">
     142        <div class="messagecontainer help" style="margin-bottom: 1em; font-style: italic;" id="login-help">
    125143        <%=loginAction.getHelp() %>
    126144        </div>
     
    130148      {
    131149        %>
    132         <div class="messagecontainer error" style="margin-top: 1em;"><%=error%></div>
    133         <%
    134       }
    135       %>
    136       <table style="width: 100%; margin-top: 1em; border-collapse: separate;">
     150        <div class="messagecontainer error" style="margin-top: 1em; margin-bottom: 1em;"><%=error%></div>
     151        <%
     152      }
     153      if (allForms.size() > 1)
     154      {
     155        %>
     156        <div style="text-align: right; margin-bottom: 0.25em;">
     157          <b>Login with</b>
     158          <select name="loginForm" id="loginForm" style="min-width: 10em;">
     159          <%
     160          for (Map.Entry<String, String> entry : allForms.entrySet())
     161          {
     162            String formId = entry.getKey();
     163            %>
     164            <option value="<%=formId%>" <%=formId.equals(selectedLoginForm) ? "selected" : ""%>><%=HTML.encodeTags(entry.getValue()) %>
     165            <%
     166          }
     167          %>
     168          </select>
     169        </div>
     170        <%
     171      }
     172      else if (selectedLoginForm != null)
     173      {
     174        %>
     175        <input type="hidden" name="loginForm" value="<%=selectedLoginForm%>">
     176        <%
     177      }
     178      %>
     179      <table style="width: 100%; border-collapse: separate;">
    137180      <tr>
    138181        <td class="base-logo"><img src="images/baselogo.png" alt="BASE logo"></td>
Note: See TracChangeset for help on using the changeset viewer.