Changeset 7531


Ignore:
Timestamp:
Nov 26, 2018, 1:06:20 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2131: Add support for installing multiple authentication managers

The "Switch user" dialog should now work with multiple login forms.

Location:
trunk/www
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/include/menu.jsp

    r7407 r7531  
    11941194        title="<%=menu.getString("switchuser.title") + "…"%>"
    11951195        url="<%=root+"switch.jsp?ID="+ID%>"
    1196         data-popup="Switch, 480, 320"
     1196        data-popup="Switch, 540, 360"
    11971197        tooltip="<%=menu.getString("switchuser.tooltip")%>"
    11981198      />
  • trunk/www/login.js

    r7530 r7531  
    9191  login.switchLoginForm = function(loginForm)
    9292  {
    93     var url = 'main.jsp?ID='+App.getSessionId();
     93    var url = location.pathname+'?ID='+App.getSessionId();
    9494    url += '&loginForm='+encodeURIComponent(loginForm);
    9595    location.replace(url);
  • trunk/www/switch.jsp

    r7500 r7531  
    3333  import="net.sf.basedb.core.query.Hql"
    3434  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
     35  import="net.sf.basedb.util.extensions.ActionIterator"
    3536  import="net.sf.basedb.clients.web.Base"
    3637  import="net.sf.basedb.clients.web.util.HTML"
     
    4142  import="net.sf.basedb.clients.web.extensions.login.FieldInfo"
    4243  import="net.sf.basedb.util.Values"
     44  import="java.util.Map"
     45  import="java.util.TreeMap"
    4346%>
    4447<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    5356<%
    5457final String login = Values.getString(request.getParameter("login"), "");
     58final String requestedLoginForm = Values.getString(request.getParameter("loginForm"), null);
    5559
    5660final SessionControl sc = Base.getSessionControl(pageContext, true);
     
    6165  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext);
    6266  ExtensionsInvoker<LoginFormAction> invoker = (ExtensionsInvoker<LoginFormAction>)ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form");
     67
    6368  LoginFormAction loginAction = null;
    64   for (LoginFormAction action : invoker)
     69  String selectedLoginForm = null;
     70  Map<String, String> allForms = new TreeMap<String, String>();
     71
     72  ActionIterator<LoginFormAction> it = invoker.iterate();
     73  while (it.hasNext())
    6574  {
     75    LoginFormAction action = it.next();
    6676    if (action != null)
    6777    {
    68       loginAction = action;
    69       break;
     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      }
    7089    }
    7190  }
     
    7796    bean.setPasswordField(FieldInfo.DEFAULT_PASSWORD);
    7897    loginAction = bean;
     98    selectedLoginForm = "password";
    7999  }
    80100  FieldInfo loginField = loginAction.getLoginField();
     
    87107    <ext:stylesheets context="<%=jspContext%>" />
    88108  </base:head>
    89   <base:body>
     109  <base:body data-login-form="<%=HTML.encodeTags(selectedLoginForm)%>" data-requested-form="<%=HTML.encodeTags(requestedLoginForm) %>">
    90110    <h1>Switch user <base:help helpid="switchuser" /></h1>
    91111    <form name="login" action="login.jsp" method="post">
     
    98118    <div class="content">
    99119      <table class="fullform input100 bottomborder ">
     120      <%
     121      if (allForms.size() > 0)
     122      {
     123        %>
     124        <tr>
     125          <th>Login with</th>
     126          <td>
     127          <select name="loginForm" id="loginForm" style="min-width: 10em;">
     128          <%
     129          for (Map.Entry<String, String> entry : allForms.entrySet())
     130          {
     131            String formId = entry.getKey();
     132            %>
     133            <option value="<%=formId%>" <%=formId.equals(selectedLoginForm) ? "selected" : ""%>><%=HTML.encodeTags(entry.getValue()) %>
     134            <%
     135          }
     136          %>
     137          </select>
     138          </td>
     139        </tr>
     140        <%
     141      }
     142      %>
    100143      <tr <%=valueIfNotNull("class=\"", loginField.getClazz(), "\"")%> id="login-row">
    101144        <th><%=loginField.getPrompt() %></th>
Note: See TracChangeset for help on using the changeset viewer.