Changeset 6424


Ignore:
Timestamp:
Feb 25, 2014, 2:37:04 PM (9 years ago)
Author:
Nicklas Nordborg
Message:

References #1599: Convert authentication plug-in system to an extension point

Avoid calling deprecated methods.

Added OldAuthenticationWrapperFactory for backwards compatibility with old external authentication implementations.

Location:
trunk
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/config/dist/base.config

    r6351 r6424  
    6262# ======================
    6363
    64 # ----------------
    65 # POP3 mail server
    66 # ----------------
    67 #auth.driver         = net.sf.basedb.core.authentication.POP3Authenticator
    68 #auth.jarpath        =
    69 #auth.init           = mail.example.com
     64# If extra information such as address, email, phone, etc. should
     65# be synchronized or not from external authentication managers
    7066#auth.synchronize    = 0
     67
     68# If passwords should be cached locally or not to allow
     69# fallback to internal authentication when external authentication
     70# system is not responding
    7171#auth.cachepasswords = 0
     72
     73# Number of days to cache passwords locally
    7274#auth.daystocache    = 0
    7375
  • trunk/src/clients/jobagent/net/sf/basedb/clients/jobagent/Agent.java

    r6268 r6424  
    5252import net.sf.basedb.core.Project;
    5353import net.sf.basedb.core.SessionControl;
    54 
     54import net.sf.basedb.core.authentication.LoginRequest;
    5555import net.sf.basedb.util.SocketUtil;
    5656import net.sf.basedb.util.Values;
     
    892892    {
    893893      log.info("Logging in as user: " + login);
    894       sc.login(login, password, "Job agent running on host " + getServerName());
     894      LoginRequest loginRequest = new LoginRequest(login, password);
     895      loginRequest.setComment("Job agent running on host " + getServerName());
     896      sc.login(loginRequest);
    895897    }
    896898    return sc;
  • trunk/src/clients/jobagent/net/sf/basedb/clients/jobagent/executors/ThreadJobExecutor.java

    r6127 r6424  
    3636import net.sf.basedb.core.Project;
    3737import net.sf.basedb.core.SessionControl;
     38import net.sf.basedb.core.authentication.LoginRequest;
    3839import net.sf.basedb.core.plugin.Response;
    3940import net.sf.basedb.core.signal.SignalReceiver;
     
    177178      sc = Application.newSessionControl("net.sf.basedb.clients.jobagent",
    178179        SocketUtil.getLocalHost().toString(), null);
    179       sc.login(login, password, loginComment);
     180      LoginRequest loginRequest = new LoginRequest(login, password);
     181      loginRequest.setComment(loginComment);
     182      sc.login(loginRequest);
    180183      dc = sc.newDbControl();
    181184      Job job = Job.getById(dc, jobId);
  • trunk/src/core/core-extensions.xml

    r6423 r6424  
    247247    </action-factory>
    248248  </extension>
     249 
     250  <extension
     251    id="net.sf.basedb.core.authentication.old-auth-manager"
     252    extends="net.sf.basedb.core.authentication-manager"
     253    >
     254    <about>
     255      <name>Old authentication manager</name>
     256      <description>
     257        Wrapper implementation for supporting the old external
     258        authentication style. The implemention is only enabled if
     259        the 'auth.driver' settings exists in 'base.config'.
     260      </description>
     261    </about>
     262    <index>999</index>
     263    <action-factory>
     264      <factory-class>net.sf.basedb.core.authentication.OldAuthenticationWrapperFactory</factory-class>
     265    </action-factory>
     266  </extension>
    249267
    250268  <!--
  • trunk/src/core/net/sf/basedb/core/Install.java

    r6358 r6424  
    2525package net.sf.basedb.core;
    2626
     27import net.sf.basedb.core.authentication.LoginRequest;
    2728import net.sf.basedb.core.data.BioPlateEventTypeData;
    2829import net.sf.basedb.core.data.BioPlateTypeData;
     
    6465import net.sf.basedb.core.data.PluginTypeData;
    6566import net.sf.basedb.core.hibernate.SchemaGenerator;
    66 
    6767import net.sf.basedb.core.SessionControl;
    6868import net.sf.basedb.core.DbControl;
    69 
    7069import net.sf.basedb.util.FileUtil;
    7170import net.sf.basedb.util.Values;
     
    227226      // Now that we have a root user let's create a session
    228227      sessionControl = Application.newSessionControl( null, null, null );
    229       sessionControl.login(rootLogin, rootPassword, "InitDBSessionId");
     228      LoginRequest loginRequest = new LoginRequest(rootLogin, rootPassword);
     229      loginRequest.setComment("InitDBSessionId");
     230      sessionControl.login(loginRequest);
    230231 
    231232      progressStep++;
  • trunk/src/core/net/sf/basedb/core/PluginSessionControl.java

    r6127 r6424  
    6464  */
    6565  @Override
     66  @Deprecated
    6667  public synchronized void login(String login, String password, String comment)
    6768    throws ItemNotFoundException, PermissionDeniedException, InvalidPasswordException, BaseException
  • trunk/src/core/net/sf/basedb/core/SessionControl.java

    r6423 r6424  
    430430    if (userData == null)
    431431    {
    432       throw new ItemNotFoundException("User[login="+login+"]");
     432      throw new ItemNotFoundException("The user with login '" + login + "' is not known to BASE.");
    433433    }
    434434    if (userData.isRemoved())
    435435    {
    436       throw new PermissionDeniedException("The account has been flagged for deletion: User[login="+login+"]"); 
     436      throw new PermissionDeniedException("The user with login '" + login + "' is flagged for deletion."); 
    437437    }
    438438    if (userData.isDisabled())
    439439    {
    440       throw new PermissionDeniedException("The account has been disabled: User[login="+login+"]"); 
     440      throw new PermissionDeniedException("The user with login '" + login + "' is disabled."); 
    441441    }
    442442    Date expirationDate = userData.getExpirationDate();
     
    450450    if (cryptedPassword == null || !User.checkPassword(password, cryptedPassword))
    451451    {
    452       throw new InvalidPasswordException("User[login="+login+"]");
     452      throw new InvalidPasswordException("The password for login '" + login + "' is not correct.");
    453453    }
    454454   
     
    491491    catch (net.sf.basedb.core.authentication.UnknownLoginException ex)
    492492    {
    493       throw new ItemNotFoundException("User[login="+loginRequest.getLogin()+"]", ex);
     493      throw new ItemNotFoundException("The user with login '" + loginRequest.getLogin() + "' is not known to BASE.", ex);
    494494    }
    495495    catch (net.sf.basedb.core.authentication.InvalidPasswordException ex)
    496496    {
    497       throw new InvalidPasswordException("User[login="+loginRequest.getLogin()+"]", ex);
     497      throw new InvalidPasswordException("The password for login '" + loginRequest.getLogin() + "' is not correct.", ex);
    498498    }
    499499    catch (net.sf.basedb.core.authentication.AuthenticationException ex)
     
    508508    if (info == null) return null;
    509509
     510    // Load user information, first try 'id' and then 'login'
    510511    UserData userData = context.getUserByExternalId(info.id);
     512    if (userData == null)
     513    {
     514      userData = context.getUserByLogin(info.login);
     515    }
    511516    if (userData == null)
    512517    {
  • trunk/src/core/net/sf/basedb/core/Update.java

    r6390 r6424  
    4545
    4646
     47
     48import net.sf.basedb.core.authentication.LoginRequest;
    4749import net.sf.basedb.core.data.AnnotatableData;
    4850import net.sf.basedb.core.data.AnnotationSetData;
     
    241243      // Test root user account
    242244      SessionControl sc = Application.newSessionControl(null, null, null);
    243       sc.login(rootLogin, rootPassword, null);
     245      LoginRequest loginRequest = new LoginRequest(rootLogin, rootPassword);
     246      sc.login(loginRequest);
    244247      if (sc.getLoggedInUserId() != SystemItems.getId(User.ROOT))
    245248      {
     
    522525      // Test root user account
    523526      SessionControl sc = Application.newSessionControl(null, null, null);
    524       sc.login(rootLogin, rootPassword, null);
     527      LoginRequest loginRequest = new LoginRequest(rootLogin, rootPassword);
     528      sc.login(loginRequest);
    525529      if (sc.getLoggedInUserId() != SystemItems.getId(User.ROOT))
    526530      {
     
    10591063      // Test root user account
    10601064      SessionControl sc = Application.newSessionControl(null, null, null);
    1061       sc.login(rootLogin, rootPassword, "Upgrading to BASE 3");
     1065      LoginRequest loginRequest = new LoginRequest(rootLogin, rootPassword);
     1066      loginRequest.setComment("Upgrading to BASE 3");
     1067      sc.login(loginRequest);
    10621068      if (sc.getLoggedInUserId() != SystemItems.getId(User.ROOT))
    10631069      {
  • trunk/src/core/net/sf/basedb/core/authentication/AuthenticationInformation.java

    r6423 r6424  
    2525/**
    2626  Objects of this class are returned by the
    27   {@link Authenticator#authenticate(String,String)}
     27  {@link AuthenticationManager#authenticate()}
    2828  method and contains information about the authenticated
    2929  user. The only required fields are {@link #id} and {@link #login}.
     
    3232  <p>
    3333  If the implementation supports extra information, ie. the call to
    34   {@link Authenticator#supportsExtraInformation()}
     34  {@link AuthenticationManager#supportsExtraInformation()}
    3535  returns TRUE, the other fields may also contain information.
    3636 
  • trunk/src/install/net/sf/basedb/install/Webclient.java

    r6070 r6424  
    3535import net.sf.basedb.core.BaseException;
    3636import net.sf.basedb.core.ItemNotFoundException;
     37import net.sf.basedb.core.authentication.LoginRequest;
    3738import net.sf.basedb.plugins.HelpImporter;
    3839import net.sf.basedb.util.extensions.xml.PluginInfo;
     
    9394    Application.start(false);
    9495    SessionControl sc = Application.newSessionControl(null, null, null);
    95     sc.login(login, password, "Installing web client");
     96    LoginRequest loginRequest = new LoginRequest(login, password);
     97    loginRequest.setComment("Installing web client");
     98    sc.login(loginRequest);
    9699   
    97100    DbControl dc = sc.newDbControl();
  • trunk/src/test/TestClient.java

    r5827 r6424  
    2222*/
    2323import net.sf.basedb.core.*;
     24import net.sf.basedb.core.authentication.LoginRequest;
    2425
    2526import java.util.Date;
     
    204205      Client c = Client.getById(dc, id);
    205206      SessionControl sc = Application.newSessionControl(c.getExternalId(), null, null);
    206       sc.login(TestUtil.getLogin(), TestUtil.getPassword(), "Running test program");
     207      LoginRequest loginRequest = new LoginRequest(TestUtil.getLogin(), TestUtil.getPassword());
     208      loginRequest.setComment("Running test program");
     209      sc.login(loginRequest);
    207210      sc.logout();
    208211      write("--Login/logout OK");
  • trunk/src/test/TestUtil.java

    r5827 r6424  
    2828import net.sf.basedb.core.Permission;
    2929import net.sf.basedb.core.Version;
     30import net.sf.basedb.core.authentication.LoginRequest;
    3031
    3132import java.io.File;
     
    188189    throws BaseException
    189190  {
    190     sc.login(login, password, "Running test program");
     191    LoginRequest loginRequest = new LoginRequest(login, password);
     192    loginRequest.setComment("Running test program");
     193    sc.login(loginRequest);
    191194  }
    192195
  • trunk/src/test/net/sf/basedb/test/TestUtil.java

    r5827 r6424  
    3737import net.sf.basedb.core.DbControl;
    3838import net.sf.basedb.core.SessionControl;
     39import net.sf.basedb.core.authentication.LoginRequest;
    3940
    4041/**
     
    165166  {
    166167    write("--Logging in as: " + login + "\n");
    167     getSessionControl().login(login, password, "Running test program");
     168    LoginRequest loginRequest = new LoginRequest(login, password);
     169    loginRequest.setComment("Running test program");
     170    getSessionControl().login(loginRequest);
    168171  }
    169172
  • trunk/src/webservices/server/net/sf/basedb/ws/server/SessionService.java

    r5827 r6424  
    2424import net.sf.basedb.core.Application;
    2525import net.sf.basedb.core.SessionControl;
     26import net.sf.basedb.core.authentication.LoginRequest;
    2627import net.sf.basedb.info.VersionInfo;
    2728
     
    6566  {
    6667    SessionControl sc = getSessionControl(ID);
    67     sc.login(login, password, comment);
     68    LoginRequest loginRequest = new LoginRequest(login, password);
     69    loginRequest.setComment(comment);
     70    sc.login(loginRequest);
    6871    return ID;
    6972  }
  • trunk/www/login.jsp

    r5827 r6424  
    3636<%@ page pageEncoding="UTF-8" session="false"
    3737  import="net.sf.basedb.core.*"
     38  import="net.sf.basedb.core.authentication.LoginRequest"
    3839  import="net.sf.basedb.clients.web.Base"
    3940  import="net.sf.basedb.clients.web.WebException"
     
    5960    {
    6061      if (sc.isLoggedIn()) sc.logout();
    61       sc.login(login, password, null);
     62      LoginRequest loginRequest = new LoginRequest(login, password);
     63      sc.login(loginRequest);
    6264    }
    6365    catch (LoginException ex)
     
    6971    {
    7072      errorTitle = "Login not found";
    71       errorMessage = Values.formatMessage(
    72         "The user with login {1} is not a registered user for BASE.",
    73         HTML.encodeTags(login)
    74       );
     73      errorMessage = ex.getMessage();
    7574    }
    7675    catch (InvalidPasswordException ex)
    7776    {
    7877      errorTitle = "Invalid password";
    79       errorMessage = Values.formatMessage(
    80         "The password for login {1} is not correct.",
    81         HTML.encodeTags(login)
    82       );
     78      errorMessage = ex.getMessage();
    8379    }
    8480    catch (PermissionDeniedException ex)
    8581    {
    8682      errorTitle = "Permission denied";
    87       errorMessage = Values.formatMessage(
    88         "You do not have permission to log in to BASE.<br>"+ex.getMessage(),
    89         HTML.encodeTags(login)
    90       );
     83      errorMessage = ex.getMessage();
    9184    }
    9285
Note: See TracChangeset for help on using the changeset viewer.