Changeset 4918


Ignore:
Timestamp:
Aug 8, 2018, 2:20:30 PM (4 years ago)
Author:
Nicklas Nordborg
Message:

References #1055: Implement extension for logging in with OTP

The login form extension has been updated with support for both otp-only and otp+password authentication.

Location:
extensions/net.sf.basedb.otp/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.otp/trunk/resources/css/otp.css

    r4863 r4918  
    1818  min-height: 70px;
    1919}
     20
     21#extra-row.optional td::after
     22{
     23  content: "(optional)";
     24  opacity: 0.5;
     25}
     26
     27#extra-row.required td::after
     28{
     29  content: "(required)";
     30  opacity: 0.5;
     31}
  • extensions/net.sf.basedb.otp/trunk/resources/scripts/login.js

    r4863 r4918  
    77  otp.initPage = function()
    88  {
    9     var pwd = Doc.element('password');
    10     if (pwd.type == 'text')
     9    // The OTP field can be either the password field or the
     10    // extra field
     11    var otpField = Doc.element('extraField');
     12    if (!otpField) otpField = Doc.element('password');
     13    // If the OTP field is text type, the user is not
     14    // supposed to enter password into it
     15    if (otpField.type == 'text')
    1116    {
    1217      // Limit to digits
    13       Events.addEventHandler(pwd, 'keypress', Events.integerOnly);
     18      Events.addEventHandler(otpField, 'keypress', Events.integerOnly);
    1419      // Disable auto-complete
    15       pwd.setAttribute('autocomplete', 'off');
     20      otpField.setAttribute('autocomplete', 'off');
    1621    }
    1722  }
  • extensions/net.sf.basedb.otp/trunk/src/net/sf/basedb/otp/Otp.java

    r4851 r4918  
    131131    return clientId != null && requireOtpLogin != null && requireOtpLogin.contains(clientId);
    132132  }
     133 
     134  /**
     135    Get the authentication method to use:
     136    {@link #OTP_ONLY_AUTHENTICATION_METHOD} or
     137    {@link #OTP_PASSWORD_AUTHENTICATION_METHOD}.
     138  */
     139  public static AuthenticationMethod getAuthenticationMethod()
     140  {
     141    AuthenticationMethod am = OTP_PASSWORD_AUTHENTICATION_METHOD;
     142    if ("otp-only".equals(getConfig().get("login-method")))
     143    {
     144      am = OTP_ONLY_AUTHENTICATION_METHOD;
     145    }
     146    return am;
     147  }
     148
    133149
    134150}
  • extensions/net.sf.basedb.otp/trunk/src/net/sf/basedb/otp/OtpLoginFormFactory.java

    r4863 r4918  
    55import net.sf.basedb.clients.web.extensions.login.LoginFormAction;
    66import net.sf.basedb.clients.web.extensions.login.LoginFormBean;
     7import net.sf.basedb.core.authentication.AuthenticationMethod;
    78import net.sf.basedb.util.extensions.InvokationContext;
    89
     
    1819 
    1920  private final boolean hasConfig;
     21  private final AuthenticationMethod authMethod;
    2022  private final LoginFormBean loginFormOptional;
    2123  private final LoginFormBean loginFormRequired;
     
    2527  {
    2628    hasConfig = Otp.getConfig() != null;
     29    authMethod = Otp.getAuthenticationMethod();
     30   
     31    FieldInfo otpOrPasswordField = new FieldInfo("OTP or password", true);
     32    otpOrPasswordField.setStyle("width: 10em;");
     33    otpOrPasswordField.setTooltip("Use your device to generate a 6-digit passcode (or use the regular password)");
     34
     35    FieldInfo otpFieldRequired = new FieldInfo("One-time passcode", false);
     36    otpFieldRequired.setClazz("requried");
     37    otpFieldRequired.setStyle("width: 10em;");
     38    otpFieldRequired.setTooltip("Use your device to generate a 6-digit code (required)");
     39
     40    FieldInfo otpFieldOptional = new FieldInfo("One-time passcode", false);
     41    otpFieldOptional.setClazz("optional");
     42    otpFieldOptional.setStyle("width: 10em;");
     43    otpFieldOptional.setTooltip("Use your device to generate a 6-digit code (optional)");
     44   
     45    String helpTextWithConfigLink = "<p style=\"margin-top: 0.5em;\">"
     46        + "<b>Note!</b> If you have not configured your account for OTP you can do it "
     47        + "<span class=\"link auto-init\" data-auto-init=\"setup-otp\">here</span>.";
    2748   
    2849    loginFormOptional = new LoginFormBean();
    2950    loginFormOptional.setRememberLastLogin(true);
    30     loginFormOptional.setHelp(
     51    loginFormOptional.setLoginField(FieldInfo.DEFAULT_LOGIN);
     52    if (authMethod == Otp.OTP_ONLY_AUTHENTICATION_METHOD)
     53    {
     54      loginFormOptional.setHelp(
    3155        "If you have set-up your account for one-time passwords (OTP), use your device to generate a "
    3256        + "6-digit passcode. Enter your username in the <b>Login</b> field and the code in the <b>OTP or password</b> field. "
    33         + "<p style=\"margin-top: 0.5em;\">"
    34         + "<b>Note!</b> If you have not configured your account for OTP you can do it <span class=\"link auto-init\" data-auto-init=\"setup-otp\">here</span>.");
    35  
    36     FieldInfo otpFieldOptional = new FieldInfo("OTP or password", true);
    37     otpFieldOptional.setStyle("width: 10em;");
    38     otpFieldOptional.setTooltip("Use your device to generate a 6-digit passcode (or use the regular password)");
    39 
    40     loginFormOptional.setLoginField(FieldInfo.DEFAULT_LOGIN);
    41     loginFormOptional.setPasswordField(otpFieldOptional);
     57        + helpTextWithConfigLink);
     58      loginFormOptional.setPasswordField(otpOrPasswordField);
     59    }
     60    else
     61    {
     62      loginFormOptional.setHelp(
     63        "If you have set-up your account for one-time passwords (OTP), use your device to generate a "
     64        + "6-digit passcode. Enter your username in the <b>Login</b> field, your regular password in "
     65        + "the <b>Password</b> field and the code in the <b>One-time passcode</b> field. "
     66        + helpTextWithConfigLink);
     67      loginFormOptional.setPasswordField(FieldInfo.DEFAULT_PASSWORD);
     68      loginFormOptional.setExtraField(otpFieldOptional);
     69    }
    4270
    4371    loginFormRequired = new LoginFormBean();
    4472    loginFormRequired.setRememberLastLogin(true);
    45     loginFormRequired.setHelp(
     73    loginFormRequired.setLoginField(FieldInfo.DEFAULT_LOGIN);
     74    if (authMethod == Otp.OTP_ONLY_AUTHENTICATION_METHOD)
     75    {
     76      loginFormRequired.setHelp(
    4677        "A one-time passcode (OTP) is required to login. Enter your username in the <b>Login</b> field. "
    4778        + "Use your device to generate a 6-digit code and enter it in the <b>One-time passcode</b> field. "
    48         + "<p style=\"margin-top: 0.5em;\">"
    49         + "<b>Note!</b> If you have not configured your account for OTP you can do it <span class=\"link auto-init\" data-auto-init=\"setup-otp\">here</span>.");
    50  
    51     FieldInfo otpFieldRequired = new FieldInfo("One-time passcode", false);
    52     otpFieldRequired.setStyle("width: 10em;");
    53     otpFieldRequired.setTooltip("Use your device to generate a 6-digit code");
    54 
    55     loginFormRequired.setLoginField(FieldInfo.DEFAULT_LOGIN);
    56     loginFormRequired.setPasswordField(otpFieldRequired);
     79        + helpTextWithConfigLink);
     80      loginFormRequired.setPasswordField(otpFieldRequired);
     81    }
     82    else
     83    {
     84      loginFormRequired.setHelp(
     85        "A one-time passcode (OTP) is required to login. Enter your username in the <b>Login</b> field and your "
     86        + "regular password in the <b>Password</b> field. "
     87        + "Use your device to generate a 6-digit code and enter it in the <b>One-time passcode</b> field. "
     88        + helpTextWithConfigLink);
     89      loginFormRequired.setPasswordField(FieldInfo.DEFAULT_PASSWORD);
     90      loginFormRequired.setExtraField(otpFieldRequired);
     91    }
    5792  }
    5893
Note: See TracChangeset for help on using the changeset viewer.