Class FailedSignInRecorder

java.lang.Object
com.iizix.server.user.FailedSignInRecorder

public final class FailedSignInRecorder extends Object
Records the failed attempts to sign in to a known account (CC-SIGNIN-FAILED-ATTEMPTS, order 561) and tells the user about them: the one entry point of the sign-in code (UserAuthenticationUIImpl) for a refusal that named an existing user - at the password, at the second factor, at a passkey, at a recovery code, by a policy or by the license.

Nothing of this is in the sign-in's path. onFailure(IClientSessionGyro, UserInfoBase, FailedSignInStep, boolean, boolean, String) starts a virtual thread and returns; the thread resolves the client address and its place (ClientPlace), writes one row of IZS.FAILED_SIGNINS (FailedSignInStore), writes the WARNING line of an attempt that got past the password or hit a sensitive account, and hands the attempt to the FailedSignInNotifier, which decides about the mail. A failure anywhere is logged at most once a minute and ends there. The answer to the failing client is what it was: nothing says that a mail went, or that the password was right.

What is "almost signed in" and "sensitive". The caller says: afterPassword when the password was accepted before the step failed, sensitive for a member of the Administrators group (ServerAdmin's users are its members) and for a user a strong sign-in policy binds. Either makes the attempt urgent: a WARNING in the server log and a mail every time, no throttle (within the hourly cap).

The two settings of the account are user details (IBasicUserInfoDetailNames.DETAIL_FailedSignInMail, IBasicUserInfoDetailNames.DETAIL_FailedSignInClear); the mail's default is on for a sensitive account and off otherwise (isMailWanted(UserInfoBase, boolean)), the clearing at a sign-in is off by default.

Author:
Christopher Mindus
  • Field Details

  • Constructor Details

    • FailedSignInRecorder

      public FailedSignInRecorder(FailedSignInStore store, Executor executor, FailedSignInNotifier notifier)
      Constructs a recorder on a store, an executor and a notifier: the tests' constructor.
      Parameters:
      store - The store.
      executor - Where the capture runs; Runnable::run runs it in the caller.
      notifier - The notifier, on the same store.
  • Method Details

    • getInstance

      public static FailedSignInRecorder getInstance()
      Gets the server's recorder.
      Returns:
      The instance.
    • getStore

      public FailedSignInStore getStore()
      Gets the store.
      Returns:
      The store, for the lists and the purge.
    • onServerRound

      public void onServerRound()
      Called at every clean-up round of the server: starts the notifier's thread once the server is started and its database is ready, so that a batch or a summary held when the server stopped goes out (FailedSignInNotifier.runDue()). Without a started server (the tests' JVM) nothing is started.
    • isMailWanted

      public static boolean isMailWanted(UserInfoBase user, boolean sensitive)
      Checks if a user is mailed about the throttled failed sign-ins: the detail IZS-FailedSignInMail when set (on/off), else the default - on for a sensitive account, off otherwise.
      Parameters:
      user - The user.
      sensitive - Whether the account is a sensitive one.
      Returns:
      true when the mail is on.
    • isAutoClear

      public static boolean isAutoClear(UserInfoBase user)
      Checks if a user has the list cleared at every successful sign-in: the detail IZS-FailedSignInClear is on.
      Parameters:
      user - The user.
      Returns:
      true when the list is cleared at a sign-in.
    • setMailWanted

      public static void setMailWanted(Connection conn, BasicUserInfo user, boolean wanted) throws SQLException
      Writes the mail setting of a user, inside the caller's transaction.
      Parameters:
      conn - The connection of the caller's transaction.
      user - The user.
      wanted - true for on, false for off.
      Throws:
      SQLException - For SQL errors.
    • setAutoClear

      public static void setAutoClear(Connection conn, BasicUserInfo user, boolean on) throws SQLException
      Writes the clearing setting of a user, inside the caller's transaction: the detail is on, or deleted for off.
      Parameters:
      conn - The connection of the caller's transaction.
      user - The user.
      on - true to clear the list at every sign-in.
      Throws:
      SQLException - For SQL errors.
    • onFailure

      public void onFailure(IClientSessionGyro clientGyro, UserInfoBase user, FailedSignInStep step, boolean afterPassword, boolean sensitive, String reason)
      Called when a sign-in to a known account was refused: starts the capture and returns. The caller has answered, or is about to answer, the failing client exactly as before.
      Parameters:
      clientGyro - The client session the attempt came from, null for none.
      user - The account, with its basic user information.
      step - The step that failed.
      afterPassword - true when the password was accepted before the step failed.
      sensitive - true for a sensitive account (an administrator, a user a strong policy binds).
      reason - The reason, for the log line, null for none; never a secret.
    • onSignedIn

      public void onSignedIn(UserInfoBase user)
      Called when a user has signed in: clears the list when the user chose so. Off the path, on the executor.
      Parameters:
      user - The user, with its basic user information.
    • list

      public List<FailedSignInStore.Attempt> list(long uid)
      Lists the attempts of a user, the most recent first, for the account page and ServerAdmin.
      Parameters:
      uid - The user.
      Returns:
      The attempts, at most LIST_LIMIT; none when the store is unavailable or failed (logged).
    • infos

      public FailedSignInInfo[] infos(long uid)
      Lists the attempts of a user as the SignIn module gets them.
      Parameters:
      uid - The user.
      Returns:
      The information, the most recent first.
    • clear

      public int clear(long uid)
      Clears the attempts of a user: the user's or an administrator's "Clear".
      Parameters:
      uid - The user.
      Returns:
      The rows deleted, -1 when the store failed (logged).
    • purge

      public int purge(int days)
      Deletes the attempts older than the days kept: the daily purge, with the sign-in records.
      Parameters:
      days - The days kept.
      Returns:
      The rows deleted, 0 when the store is unavailable or the purge failed (logged).
    • onLockStarted

      public void onLockStarted(FailedSignInMails.LockPath path, UserAuthenticationInfo info, IClientSessionGyro clientGyro, InetAddress address)
      Called when a wrong password started a lock of an account on a path that keeps no failed sign-in for it (LockEvents.startWithoutAttempt(FailedSignInMails.LockPath, UserAuthenticationInfo, IClientSessionGyro)): starts the telling and returns. Off the path, as onFailure(IClientSessionGyro, UserInfoBase, FailedSignInStep, boolean, boolean, String): the thread resolves the client address and its place, logs the security event of a path that has no client session (the Push API; a path with a session has logged it), writes one WARNING line and has the owner mailed (FailedSignInNotifier.onLock(FailedSignInMails.LockPath, FailedSignInStore.Attempt, BasicUserInfo)). NOTHING is written to IZS.FAILED_SIGNINS (order 561, FA-D-6).
      Parameters:
      path - The path.
      info - The answer of the password check that started the lock.
      clientGyro - The client session the wrong password came from, null for none.
      address - The client address when there is no client session, null when unknown.