Class WebAuthnJDBCAcceleratorImpl

All Implemented Interfaces:
WebAuthnJDBCAccelerator, WebAuthnJDBCQueryAccelerator, WebAuthnJDBCReadAllAccelerator, Component, DestructableComponent, IdentifiableComponent, IdentifiedComponent, InitializableComponent

public final class WebAuthnJDBCAcceleratorImpl extends AbstractIdentifiableInitializableComponent implements WebAuthnJDBCQueryAccelerator, WebAuthnJDBCReadAllAccelerator
Implementation of a WebAuthnJDBCQueryAccelerator and WebAuthnJDBCReadAllAccelerator that uses specialized queries to lookup credentials by userHandle and credentialId. The default queries require databases that support SQL/JSON and JSON_TABLE.
Since:
1.3.0
  • Field Details

  • Constructor Details

    • WebAuthnJDBCAcceleratorImpl

      public WebAuthnJDBCAcceleratorImpl()
      Constructor.

      Set the defaults so that they can be over-ridden by Spring.

  • Method Details

    • setLocalLocking

      public void setLocalLocking(boolean what)
      Will we do thread level locking or delegate to the Database?
      Parameters:
      what - do we want to lock locally?
    • setRetryableErrors

      public void setRetryableErrors(@Nonnull @NonnullElements List<String> errors)
      What errors do we retry?
      Parameters:
      errors - what to set.
    • setTransactionRetries

      public void setTransactionRetries(@Positive int count)
      Parameters:
      count - how many time to try before we bail.
    • getTransactionRetries

      protected int getTransactionRetries()
      Get the number of transaction retries.
      Returns:
      the transaction retries before we bail.
    • setTransactionIsolation

      public void setTransactionIsolation(int what)
      Set the parameter that will be passed to Connection.setTransactionIsolation(int).
      Parameters:
      what - the value to set
    • setQueryRecordsByUserHandleSQL

      public void setQueryRecordsByUserHandleSQL(String what)
      Set the SQL needed to query for credential registrations by their userHandle.
      Parameters:
      what - The queryRecordsByUserHandleSQL to set.
    • setQueryRecordsByCredentialIdSQL

      public void setQueryRecordsByCredentialIdSQL(String what)
      Set the SQL needed to query for credential registrations by their credentialId.
      Parameters:
      what - The queryRecordsByCredentialIdSQL to set.
    • setReadAllByContextSQL

      public void setReadAllByContextSQL(@Nonnull @NotEmpty String what)
      SQL to read all contexts.
      Parameters:
      what - the SQL to set.
    • setDataSource

      public void setDataSource(@Nonnull DataSource source)
      Set the DataSource.
      Parameters:
      source - the datasource to set.
    • queryByUserHandle

      @Unmodifiable @NonnullElements @NotLive public <T> List<StorageRecord<Set<T>>> queryByUserHandle(String context, String userHandle) throws IOException
      Queries the underlying data source for credentials associated with the given userHandle.

      Implementations may retrieve data from a JSON field (e.g., a "value" column), requiring JSON querying capabilities in the underlying RDBMS.

      Specified by:
      queryByUserHandle in interface WebAuthnJDBCQueryAccelerator
      Type Parameters:
      T - the storage record type
      Parameters:
      context - the context
      userHandle - the userHandle to query for
      Returns:
      a list of credentials that are a match for the given userHandle
      Throws:
      IOException - on error
    • queryByCredentialId

      @Unmodifiable @NonnullElements @NotLive public <T> List<StorageRecord<Set<T>>> queryByCredentialId(String context, String credentialId) throws IOException
      Queries the underlying data source for credentials associated with the given credentialId.

      Implementations may retrieve data from a JSON field (e.g., a "value" column), requiring JSON querying capabilities in the underlying RDBMS.

      Specified by:
      queryByCredentialId in interface WebAuthnJDBCQueryAccelerator
      Type Parameters:
      T - the storage record type
      Parameters:
      context - the context
      credentialId - the credentialId to query for
      Returns:
      a list of credentials that are a match for the given userHandle
      Throws:
      IOException - on error
    • readAll

      @Nonnull @NonnullElements @NotLive public <T> List<StorageRecord<T>> readAll(@Nonnull @NotEmpty String context) throws IOException
      Read all credential records in a single query from a given context.
      Specified by:
      readAll in interface WebAuthnJDBCReadAllAccelerator
      Type Parameters:
      T - the storage record record type
      Parameters:
      context - a storage context label
      Returns:
      all found credential records.
      Throws:
      IOException - on error
    • query

      @Nonnull private <T> List<StorageRecord<T>> query(@Nonnull @NotEmpty String sql, @Nullable @NonnullElements String[] parameters) throws IOException
      Execute the given SQL over the established connection and return the results. It is required that all SQL statements return the version, expires, and value columns, in that order.
      Type Parameters:
      T - the storage record type
      Parameters:
      sql - the SQL to execute
      parameters - the parameters to bind to the SQL statement
      Returns:
      the results of executing the given query,
      Throws:
      IOException - on error
    • getExpires

      @Nullable protected static Long getExpires(@Nonnull ResultSet results, int columm) throws SQLException
      Return the value of expires in the supplied column of the supplied ResultSet.
      Parameters:
      results - the results whose current row we want to inspect
      columm - the column
      Returns:
      the expiration (converting an SQL null into a null)
      Throws:
      SQLException - if the results interrogation fails