Class SecurityEventStore

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

public final class SecurityEventStore extends Object
The security events kept for ServerAdmin (CC-SIGNIN-RECORDS-AND-SECURITY-LOG, order 556): one row per event SecurityEventLog was given - a sign-in, a sign-in refused, a second factor that failed, a recovery code used, a policy changed, a break-glass reset - with the session's user, application, device, client address and place. The server log holds the same events as lines; the table is what ServerAdmin lists and filters.

The table IZS.SECURITY_EVENTS is created here when it is absent, as DeviceTokenStore creates its own. Where it cannot be created the store is unavailable: the events still reach the server log, nothing is kept, and nothing that logged an event is affected. A deleted user's rows stay, their uid set to NULL and the user's name kept, until the purge: an audit line does not vanish with its account. Rows are deleted by the daily purge (purge(int)) after $signIn.signInRecordDays days.

SQL-92, Derby, PostgreSQL and MySQL. Thread-safe: every method takes its own connection.

Author:
Christopher Mindus
  • Constructor Details

    • SecurityEventStore

      public SecurityEventStore(ConnectionSource connections)
      Constructs the store on the system clock.
      Parameters:
      connections - The connection source, in the server DBUtilities::getPooledConnection.
    • SecurityEventStore

      public SecurityEventStore(ConnectionSource connections, LongSupplier clock)
      Constructs the store on a clock.
      Parameters:
      connections - The connection source.
      clock - The clock: epoch milliseconds.
  • Method Details

    • ensureSchema

      public boolean ensureSchema() throws SQLException
      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 event. The texts are cut to their columns; the identifier is made here when the event's is zero.
      Parameters:
      ev - The event.
      Returns:
      The event as written (its identifier set), null when the store is unavailable.
      Throws:
      NullPointerException - If the event, its severity, kind or text is null.
      SQLException - For SQL errors.
    • purge

      public int purge(int days) throws SQLException
      Deletes the events older than a number of days: the daily purge.
      Parameters:
      days - The days kept, positive.
      Returns:
      The number of rows deleted.
      Throws:
      IllegalArgumentException - If days is not positive.
      SQLException - For SQL errors.
    • list

      public List<SecurityEventStore.Event> list(Long uid, SecuritySeverity atLeast, int limit) throws SQLException
      Lists events, the newest first; those of one time value - two servers' events, see SecurityEventLog.stamp() - by identifier.
      Parameters:
      uid - The user whose events, null for every user's.
      atLeast - The least severity listed, null for every severity.
      limit - The most rows, positive.
      Returns:
      The events, possibly none; none when the store is unavailable.
      Throws:
      SQLException - For SQL errors.