Class FailedSignInStore
SecurityEventStore) are the server's audit and stay; this table is the USER'S list: shown on the account page and in ServerAdmin's "Devices and security", cleared by the user, by an administrator, or at a successful sign-in when the user chose so, and gone with the user (cascade).The mail bookkeeping. mail_kind says what became of an attempt: NULL while a mail about it is still due (collected for a batch, or held past the hourly cap of the warning mails), MAIL_NOTICE when mailed at once, MAIL_BATCH when listed in a batched mail, MAIL_WARNING when mailed as a warning at once, MAIL_SUMMARY when listed in the summary that follows the cap, MAIL_NONE when no mail is wanted or possible. mailed_at is when. The throttle and the cap are computed from these columns (FailedSignInNotifier), so they survive a restart of the server: nothing about them is kept in memory only. urgent marks the attempts that are mailed every time (past the password, or on a sensitive account).
The table IZS.FAILED_SIGNINS is created here when it is absent, as DeviceTokenStore creates its own. Where it cannot be created the store is unavailable: nothing is kept and nothing is mailed, the log line of the attempt is written anyway, and the sign-in is as before. Rows go after $signIn.signInRecordDays days (purge(int)).
SQL-92, Derby, PostgreSQL and MySQL. Thread-safe: every method takes its own connection.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne attempt, as written and as read.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringWhat became of the mail about an attempt (mail_kind); NULL while a mail is due.static final StringWhat became of the mail about an attempt (mail_kind); NULL while a mail is due.static final StringWhat became of the mail about an attempt (mail_kind); NULL while a mail is due.static final StringWhat became of the mail about an attempt (mail_kind); NULL while a mail is due.static final StringWhat became of the mail about an attempt (mail_kind); NULL while a mail is due.Constructor Summary
ConstructorsConstructorDescriptionFailedSignInStore(ConnectionSource connections) Constructs the store on the system clock.FailedSignInStore(ConnectionSource connections, LongSupplier clock) Constructs the store on a clock.Method Summary
Modifier and TypeMethodDescriptionintclear(long uid) Deletes every attempt of a user: the user's "Clear", the administrator's, and the clearing at a successful sign-in.intcount(long uid) Counts the attempts of a user.booleanCreates the table when it is absent.longlastMailedAt(long uid, String... kinds) Gets when a user was last mailed with a mail of some kinds.list(long uid, int limit) Lists the attempts of a user, the newest first.mailedSince(long uid, long since, String... kinds) Lists when a user was mailed with a mail of some kinds AFTER a time, the oldest first: the cap of the warning mails is counted on it (a mail at exactly the time is outside the window, so a window that ends where a mail was sent frees the mail's slot).intmarkMailed(List<Long> ids, String mailKind, long mailedAt) Records what became of the mail about attempts: the kind and the time.pending(long uid, boolean urgent) Lists the attempts of a user about which a mail is still due, the oldest first.Lists the users about whom a mail is still due: after a restart, what the notifier takes up.intpurge(int days) Deletes the attempts older than a number of days: the daily purge.Writes an attempt.
Field Details
MAIL_NOTICE
What became of the mail about an attempt (mail_kind); NULL while a mail is due.- See Also:
MAIL_BATCH
What became of the mail about an attempt (mail_kind); NULL while a mail is due.- See Also:
MAIL_WARNING
What became of the mail about an attempt (mail_kind); NULL while a mail is due.- See Also:
MAIL_SUMMARY
What became of the mail about an attempt (mail_kind); NULL while a mail is due.- See Also:
MAIL_NONE
What became of the mail about an attempt (mail_kind); NULL while a mail is due.- See Also:
Constructor Details
FailedSignInStore
Constructs the store on the system clock.- Parameters:
connections- The connection source, in the serverDBUtilities::getPooledConnection.
FailedSignInStore
Constructs the store on a clock.- Parameters:
connections- The connection source.clock- The clock: epoch milliseconds.
Method Details
ensureSchema
Creates the table when it is absent.- Returns:
- true if the table was created here, false if it existed or another server made it.
- Throws:
SQLException- For SQL errors: the table is absent and cannot be created.
write
Writes an attempt. The texts are cut to their columns; the identifier is made here when the attempt's is zero.- Parameters:
a- The attempt.- Returns:
- The attempt as written (its identifier set), null when the store is unavailable.
- Throws:
NullPointerException- If the attempt or its step is null.SQLException- For SQL errors.
markMailed
Records what became of the mail about attempts: the kind and the time.- Parameters:
ids- The attempts.mailKind- One of the MAIL_ constants.mailedAt- When, epoch milliseconds; forMAIL_NONEthe time of the decision.- Returns:
- The rows updated, 0 when the store is unavailable.
- Throws:
SQLException- For SQL errors.
clear
Deletes every attempt of a user: the user's "Clear", the administrator's, and the clearing at a successful sign-in.- Parameters:
uid- The user.- Returns:
- The rows deleted, 0 when the store is unavailable.
- Throws:
SQLException- For SQL errors.
purge
Deletes the attempts older than a number of days: the daily purge.- Parameters:
days- The days kept, positive.- Returns:
- The number of rows deleted.
- Throws:
IllegalArgumentException- Ifdaysis not positive.SQLException- For SQL errors.
list
Lists the attempts of a user, the newest first.- Parameters:
uid- The user.limit- The most rows, positive.- Returns:
- The attempts, possibly none; none when the store is unavailable.
- Throws:
SQLException- For SQL errors.
pending
Lists the attempts of a user about which a mail is still due, the oldest first.- Parameters:
uid- The user.urgent- true for the attempts held past the cap of the warning mails, false for the attempts collected for a batch.- Returns:
- The attempts, possibly none; none when the store is unavailable.
- Throws:
SQLException- For SQL errors.
pendingUsers
Lists the users about whom a mail is still due: after a restart, what the notifier takes up.- Returns:
- The user IDs, possibly none; none when the store is unavailable.
- Throws:
SQLException- For SQL errors.
lastMailedAt
Gets when a user was last mailed with a mail of some kinds.- Parameters:
uid- The user.kinds- The MAIL_ constants looked at, at least one.- Returns:
- The time, epoch milliseconds;
Long.MIN_VALUEfor never, and when the store is unavailable. - Throws:
SQLException- For SQL errors.
mailedSince
Lists when a user was mailed with a mail of some kinds AFTER a time, the oldest first: the cap of the warning mails is counted on it (a mail at exactly the time is outside the window, so a window that ends where a mail was sent frees the mail's slot).- Parameters:
uid- The user.since- The time, epoch milliseconds; mails after it are listed.kinds- The MAIL_ constants looked at, at least one.- Returns:
- The times; none when the store is unavailable.
- Throws:
SQLException- For SQL errors.
count
Counts the attempts of a user.- Parameters:
uid- The user.- Returns:
- The count, 0 when the store is unavailable.
- Throws:
SQLException- For SQL errors.