Class WebAuthnJDBCAcceleratorImpl
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
net.shibboleth.idp.plugin.authn.webauthn.storage.impl.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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA Class to encapsulate aConnectionprotected by an optional read/write lock. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DataSourceThe Data Source.(package private) static final StringThe SQL to query for all records by credentialId.(package private) static final StringThe SQL to query for all records by userHandle.(package private) static final DurationDefault timeout of SQL queries.(package private) static final StringThe SQL to get all the records for a specific context.private final org.slf4j.LoggerClass logger.private StringThe SQL to query for records by credentialId.private StringThe SQL to query for records by userHandle.private final DurationTimeout of SQL queries.private StringThe SQL to get all the records for a specific context.private ReadWriteLockIf non-null we are doing local locking.private Collection<String>Error messages that signal a transaction should be retried.private intWhat transaction isolation do we want?private intHow many times do we try an operation before giving up? -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static LonggetExpires(ResultSet results, int columm) Return the value of expires in the supplied column of the suppliedResultSet.protected intGet the number of transaction retries.private <T> List<StorageRecord<T>>Execute the given SQL over the established connection and return the results.<T> List<StorageRecord<Set<T>>>queryByCredentialId(String context, String credentialId) Queries the underlying data source for credentials associated with the given credentialId.<T> List<StorageRecord<Set<T>>>queryByUserHandle(String context, String userHandle) Queries the underlying data source for credentials associated with the given userHandle.<T> List<StorageRecord<T>>Read all credential records in a single query from a given context.voidsetDataSource(DataSource source) Set theDataSource.voidsetLocalLocking(boolean what) Will we do thread level locking or delegate to the Database?voidSet the SQL needed to query for credential registrations by their credentialId.voidSet the SQL needed to query for credential registrations by their userHandle.voidsetReadAllByContextSQL(String what) SQL to read all contexts.voidsetRetryableErrors(List<String> errors) What errors do we retry?voidsetTransactionIsolation(int what) Set the parameter that will be passed toConnection.setTransactionIsolation(int).voidsetTransactionRetries(int count) settransactionRetries.Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
setIdMethods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
doInitialize, ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentExceptionMethods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, initialize, isDestroyed, isInitializedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.shibboleth.shared.component.IdentifiedComponent
getId
-
Field Details
-
DEFAULT_QUERY_BY_USERHANDLE_RECORD_SQL
The SQL to query for all records by userHandle.- See Also:
-
DEFAULT_QUERY_BY_CREDENTIALID_RECORD_SQL
The SQL to query for all records by credentialId.- See Also:
-
DEFAULT_READ_ALL_BY_CONTEXT_SQL
The SQL to get all the records for a specific context.- See Also:
-
DEFAULT_QUERY_TIMEOUT
Default timeout of SQL queries. -
log
@Nonnull private final org.slf4j.Logger logClass logger. -
transactionRetries
private int transactionRetriesHow many times do we try an operation before giving up? -
readWriteLock
If non-null we are doing local locking. -
retryableErrors
Error messages that signal a transaction should be retried. -
dataSource
The Data Source. -
transactionIsolation
private int transactionIsolationWhat transaction isolation do we want? -
queryTimeout
Timeout of SQL queries. -
queryRecordsByUserHandleSQL
The SQL to query for records by userHandle. Default: "SELECT version, expires, value FROM StorageRecords, JSON_TABLE(value,\'$[*]\' COLUMNS (uid text PATH \'$.userIdentity.id\')) AS cred WHERE context=? AND cred.uid=?" -
queryRecordsByCredentialIdSQL
The SQL to query for records by credentialId. Default: "SELECT version, expires, value FROM StorageRecords, JSON_TABLE(value,\'$[*]\' COLUMNS (cid text PATH \'$.credential.credentialId\')) AS cred WHERE context=? AND cred.cid=?" -
readAllByContextSQL
The SQL to get all the records for a specific context. Default: "SELECT version, expires, value FROM StorageRecords WHERE context=?"
-
-
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
What errors do we retry?- Parameters:
errors- what to set.
-
setTransactionRetries
settransactionRetries.- 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 toConnection.setTransactionIsolation(int).- Parameters:
what- the value to set
-
setQueryRecordsByUserHandleSQL
Set the SQL needed to query for credential registrations by their userHandle.- Parameters:
what- The queryRecordsByUserHandleSQL to set.
-
setQueryRecordsByCredentialIdSQL
Set the SQL needed to query for credential registrations by their credentialId.- Parameters:
what- The queryRecordsByCredentialIdSQL to set.
-
setReadAllByContextSQL
SQL to read all contexts.- Parameters:
what- the SQL to set.
-
setDataSource
Set theDataSource.- 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:
queryByUserHandlein interfaceWebAuthnJDBCQueryAccelerator- Type Parameters:
T- the storage record type- Parameters:
context- the contextuserHandle- 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:
queryByCredentialIdin interfaceWebAuthnJDBCQueryAccelerator- Type Parameters:
T- the storage record type- Parameters:
context- the contextcredentialId- 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:
readAllin interfaceWebAuthnJDBCReadAllAccelerator- 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 executeparameters- 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 suppliedResultSet.- Parameters:
results- the results whose current row we want to inspectcolumm- the column- Returns:
- the expiration (converting an SQL null into a null)
- Throws:
SQLException- if the results interrogation fails
-