Class FailedSignInNotifier

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

public final class FailedSignInNotifier extends Object
Mails a user about the failed attempts to sign in to the account (CC-SIGNIN-FAILED-ATTEMPTS, order 561), in two regimes:
  • Throttled - an attempt refused at the password on an ordinary account, when the user has the mail on (IZS-FailedSignInMail): the first attempt is mailed at once (FailedSignInMails.Kind.NOTICE); the attempts that follow within the interval ($signIn.failedSignInMailMinutes, 5 by default) are collected and mailed in ONE mail when the interval has passed (FailedSignInMails.Kind.BATCH), each with its time, address and place; a stream of attempts gives one mail per interval.
  • Every time - an attempt that got past the password (the second factor, a passkey, a recovery code, a policy or the license refused it: whoever tried KNEW the password), and every attempt on a sensitive account (an administrator, a user a strong policy binds): a FailedSignInMails.Kind.WARNING at once, whatever the setting, with a cap of $signIn.failedSignInWarningsPerHour (10 by default) per user and hour; the attempts past the cap are held and listed in ONE FailedSignInMails.Kind.SUMMARY when the hour frees.
A mail goes to the user's registered address ONLY when it is verified (AccountEmailChange.isVerified(BasicUserInfo)), never to an address the attempt supplied, and never to the placeholder of the installed administrator. The sign-in link is the server's configured external URL, never the origin of the failing client's session.

The state is the table. What was mailed and when is written into the rows (FailedSignInStore.markMailed(List, String, long)); the interval and the cap are computed from the rows, so a restart of the server loses no pending batch: runDue() reads the users with a mail due (FailedSignInStore.pendingUsers()) and mails what has become due, when the notifier's thread first runs after the start (the clean-up round of UserAuthentication starts it) or at the next failed attempt, whichever is first.

Nothing here throws to its caller or reaches the failing client: a mail that cannot go is logged WARNING once a minute. One INFO line per mail names its kind and the user, the address masked.

Author:
Christopher Mindus
  • Constructor Details

    • FailedSignInNotifier

      public FailedSignInNotifier(FailedSignInStore store, LongSupplier clock, LongFunction<BasicUserInfo> users, Supplier<MailSender> sender, AccountEmailChange.IMailStep deliver, IntSupplier intervalMinutes, IntSupplier warningsPerHour, Supplier<String> signInURL)
      Constructs a notifier: the tests' constructor. No thread is started; the tests call runDue() themselves.
      Parameters:
      store - The store.
      clock - The clock: epoch milliseconds.
      users - The users by ID, null for one that is gone.
      sender - The mail sender, null for none configured.
      deliver - The delivery step: Mail::queue in the server.
      intervalMinutes - The interval of the throttled mails in minutes.
      warningsPerHour - The cap of the warning mails per user and hour.
      signInURL - The sign-in link of the mails, null for none.
  • Method Details

    • getInstance

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

      public FailedSignInStore getStore()
      Gets the store.
      Returns:
      The store.
    • start

      public void start()
      Starts the thread that mails what becomes due, once; nothing when it runs already.
    • onAttempt

      public void onAttempt(FailedSignInStore.Attempt a, BasicUserInfo user, boolean wanted)
      Takes a written attempt: mails it now, holds it for a batch or a summary, or marks it as not mailed. Never throws.

      The lock. The attempt that LOCKS the account (AccountHold: the 15th failed sign-in, and every failed one after a lock) is mailed at once whatever the setting, the interval and the cap say - the user cannot sign in until the lock ends, and a lock comes at most once in 30 minutes - and every mail written while the account is locked says so first, with the time the lock ends (send; CC-FIX-SIGNIN-HOLD-FOLLOWUP). An attempt refused BECAUSE of the lock never comes here: it is no failed sign-in (UserAuthenticationUIImpl).

      Parameters:
      a - The attempt, as written (its identifier set).
      user - The user, null when it cannot be read (nothing is mailed then).
      wanted - Whether the user has the throttled mail on; the urgent attempts go whatever it says.
    • runDue

      public long runDue()
      Mails what has become due for every user with attempts held: the batch of an interval that has passed, the summary of a cap that has freed. Called by the thread, and by the tests.
      Returns:
      When the next mail is due, epoch milliseconds; Long.MAX_VALUE when nothing is held.
    • onLock

      public void onLock(FailedSignInMails.LockPath path, FailedSignInStore.Attempt told, BasicUserInfo user)
      Mails the owner of an account that a wrong password locked it, on a path that keeps no failed sign-in (FailedSignInMails.LockPath: a change of the password, a signed-in session asked for its password again, the Push API's sign-in): ONE mail, at once, whatever the user's mail setting, the interval and the cap - as the attempt that locks an account at the sign-in is mailed (onAttempt(FailedSignInStore.Attempt, BasicUserInfo, boolean)), which this path has none of. Nothing is written to the store: the wrong password is no failed sign-in of the user's list. Not mailed, with one INFO line, when the account has no verified address or is not locked any more. Never throws.
      Parameters:
      path - The path.
      told - The wrong password, as an attempt that is not kept: its time, address, place, device, application.
      user - The user, null when it cannot be read (nothing is mailed then).