Class JDBCPairwiseIdStore
- All Implemented Interfaces:
DurablePairwiseIdStore
,PairwiseIdStore
,Component
,DestructableComponent
,InitializableComponent
The general DDL for the database, which is unchanged for compatibility, is:
CREATE TABLE shibpid ( localEntity VARCHAR(255) NOT NULL, peerEntity VARCHAR(255) NOT NULL, persistentId VARCHAR(50) NOT NULL, principalName VARCHAR(50) NOT NULL, localId VARCHAR(50) NOT NULL, peerProvidedId VARCHAR(50) NULL, creationDate TIMESTAMP NOT NULL, deactivationDate TIMESTAMP NULL, PRIMARY KEY (localEntity, peerEntity, persistentId) );.
The first three columns should be defined as the primary key of the table, and the other columns should be indexed.
- Since:
- 4.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
A Class to encapsulate aConnection
protected by an optional read/write lock. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
Parameterized update statement used to attach an alias to an ID.private String
Name of the creation time column.private DataSource
JDBC data source for retrieving connections.private String
Parameterized update statement used to deactivate an ID.private String
Name of the deactivation time column.private String
Parameterized delete statement used to clear dummy rows after verification.private String
Parameterized select query for lookup by issued value.private String
Parameterized select query for lookup by source ID.private PairwiseIdStore
Optional hook for obtaining initial values from a primary store, usually a computed algorithm.private String
Parameterized insert statement used to insert a new record.private String
Name of the issuer entityID column.private final org.slf4j.Logger
Class logger.private String
Name of recipient-attached alias column.private String
Name of the persistent ID column.private String
Name of the principal name column.private Duration
Timeout of SQL queries.private ReadWriteLock
If non-null we doing local locking.private String
Name of the recipient entityID column.private Collection<String>
Error messages that signal a transaction should be retried.private String
Name of the source ID column.private String
Name of the database table.private int
What transaction isolation do we want?private int
Number of times to retry a transaction if it rolls back.private boolean
Whether to fail if the database cannot be verified. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
attach
(PairwiseId pid) Attach a peer-supplied alias to a pairwise ID.private List<PairwiseId>
buildIdentifierEntries
(ResultSet resultSet) Build a list ofPairwiseId
objects from a result set.void
deactivate
(PairwiseId pid) Deactivate/revoke a pairwise ID.protected void
Populate the underlying principal/source fields for the input object based on the supplied values.getBySourceValue
(PairwiseId pid, boolean allowCreate) Populate the pairwise ID field for the input object based on the supplied values.Get the source datasource used to communicate with the database.Get a store to use to produce the first value for a given issuer/recipient pair.Get the SQL query timeout.Get the error messages to check for classifying a driver error as retryable, generally indicating a lock violation or duplicate insert that signifies a broken database.Gets the table name.int
Get the number of retries to attempt for a failed transaction.boolean
Get whether to allow startup if the database cannot be verified.boolean
Do we do thread level locking or delegate to the Database?void
setAttachSQL
(String sql) Set the UPDATE statement used to attach an SPProvidedID to an issued value.void
setCreateTimeColumn
(String name) Set the name of the creation time column.void
setDataSource
(DataSource source) Get the source datasource used to communicate with the database.void
setDeactivateSQL
(String sql) Set the UPDATE statement used to deactivate issued values.void
Set the name of the deactivation time column.void
setDeleteSQL
(String sql) Set the DELETE statement used to clear dummy row(s) created during verification.void
Set the SELECT statement used to lookup records by issued value.void
Set the SELECT statement used to lookup records by source ID.void
Set a store to use to produce the first value for a given issuer/recipient pair.void
setInsertSQL
(String sql) Set the INSERT statement used to insert new records.void
setLocalEntityColumn
(String name) Set the name of the issuer entityID column.void
setLocalLocking
(boolean what) Will we do thread level locking or delegate to the Database?void
setPeerEntityColumn
(String name) Set the name of the recipient entityID column.void
Set the name of the peer-provided ID column.void
setPersistentIdColumn
(String name) Set the name of the persistent ID column.void
setPrincipalNameColumn
(String name) Set the name of the principal name column.void
setQueryTimeout
(Duration timeout) Set the SQL query timeout.void
setRetryableErrors
(Collection<String> errors) Set the error messages to check for classifying a driver error as retryable, generally indicating a lock violation or duplicate insert that signifies a broken database.void
setSourceIdColumn
(String name) Set the name of the source ID column.void
setTableName
(String name) Set the table name.void
setTransactionIsolation
(int what) Set the parameter that will be passed toConnection.setTransactionIsolation(int)
.void
setTransactionRetries
(int retries) Set the number of retries to attempt for a failed transaction.void
setVerifyDatabase
(boolean flag) Set whether to allow startup if the database cannot be verified.(package private) void
store
(PairwiseId entry, JDBCPairwiseIdStore.ConnectionWithLock dbConn) Store a record containing the values from the input object.private void
Check the database and the presence of a uniqueness constraint.Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, initialize, isDestroyed, isInitialized
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
dataSource
JDBC data source for retrieving connections. -
queryTimeout
Timeout of SQL queries. -
transactionRetry
Number of times to retry a transaction if it rolls back. -
transactionIsolation
private int transactionIsolationWhat transaction isolation do we want? -
retryableErrors
Error messages that signal a transaction should be retried. -
readWriteLock
If non-null we doing local locking. -
verifyDatabase
private boolean verifyDatabaseWhether to fail if the database cannot be verified. -
tableName
Name of the database table. -
issuerColumn
Name of the issuer entityID column. -
recipientColumn
Name of the recipient entityID column. -
principalNameColumn
Name of the principal name column. -
sourceIdColumn
Name of the source ID column. -
persistentIdColumn
Name of the persistent ID column. -
peerProvidedIdColumn
Name of recipient-attached alias column. -
creationTimeColumn
Name of the creation time column. -
deactivationTimeColumn
Name of the deactivation time column. -
getByIssuedSelectSQL
Parameterized select query for lookup by issued value. -
getBySourceSelectSQL
Parameterized select query for lookup by source ID. -
insertSQL
Parameterized insert statement used to insert a new record. -
deactivateSQL
Parameterized update statement used to deactivate an ID. -
attachSQL
Parameterized update statement used to attach an alias to an ID. -
deleteSQL
Parameterized delete statement used to clear dummy rows after verification. -
initialValueStore
Optional hook for obtaining initial values from a primary store, usually a computed algorithm.
-
-
Constructor Details
-
JDBCPairwiseIdStore
public JDBCPairwiseIdStore()Constructor.
-
-
Method Details
-
getDataSource
Get the source datasource used to communicate with the database.- Returns:
- the data source;
-
setDataSource
Get the source datasource used to communicate with the database.- Parameters:
source
- the data source;
-
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?
-
isLocalLocking
public boolean isLocalLocking()Do we do thread level locking or delegate to the Database?- Returns:
- do we lock locally?
-
setTransactionIsolation
public void setTransactionIsolation(int what) Set the parameter that will be passed toConnection.setTransactionIsolation(int)
.- Parameters:
what
- the value to set
-
getQueryTimeout
Get the SQL query timeout.- Returns:
- the timeout
-
setQueryTimeout
Set the SQL query timeout. Defaults to 5s.- Parameters:
timeout
- the timeout to set
-
getTransactionRetries
public int getTransactionRetries()Get the number of retries to attempt for a failed transaction.- Returns:
- number of retries
-
setTransactionRetries
Set the number of retries to attempt for a failed transaction. Defaults to 3.- Parameters:
retries
- the number of retries
-
getRetryableErrors
Get the error messages to check for classifying a driver error as retryable, generally indicating a lock violation or duplicate insert that signifies a broken database.- Returns:
- retryable messages
-
setRetryableErrors
Set the error messages to check for classifying a driver error as retryable, generally indicating a lock violation or duplicate insert that signifies a broken database.- Parameters:
errors
- retryable messages
-
getVerifyDatabase
public boolean getVerifyDatabase()Get whether to allow startup if the database cannot be verified.- Returns:
- whether to allow startup if the database cannot be verified
-
setVerifyDatabase
public void setVerifyDatabase(boolean flag) Set whether to allow startup if the database cannot be verified.Verification consists not only of a liveness check, but the successful insertion of a dummy row, a failure to insert a duplicate, and then deletion of the row.
- Parameters:
flag
- flag to set
-
getTableName
Gets the table name.- Returns:
- table name
- Since:
- 4.1.0
-
setTableName
Set the table name.- Parameters:
name
- table name
-
setLocalEntityColumn
Set the name of the issuer entityID column.- Parameters:
name
- name of issuer column
-
setPeerEntityColumn
Set the name of the recipient entityID column.- Parameters:
name
- name of recipient column
-
setPrincipalNameColumn
Set the name of the principal name column.- Parameters:
name
- name of principal name column
-
setSourceIdColumn
Set the name of the source ID column.- Parameters:
name
- name of source ID column
-
setPersistentIdColumn
Set the name of the persistent ID column.- Parameters:
name
- name of the persistent ID column
-
setPeerProvidedIdColumn
Set the name of the peer-provided ID column.- Parameters:
name
- name of peer-provided ID column
-
setCreateTimeColumn
Set the name of the creation time column.- Parameters:
name
- name of creation time column
-
setDeactivationTimeColumn
Set the name of the deactivation time column.- Parameters:
name
- name of deactivation time column
-
setGetByIssuedSelectSQL
Set the SELECT statement used to lookup records by issued value.- Parameters:
sql
- statement text, which must contain three parameters (NameQualifier, SPNameQualifier, value)
-
setGetBySourceSelectSQL
Set the SELECT statement used to lookup records by source ID.- Parameters:
sql
- statement text, which must contain six parameters (NameQualifier, SPNameQualifier, source ID, NameQualifier, SPNameQualifier, source ID)
-
setInsertSQL
Set the INSERT statement used to insert new records.- Parameters:
sql
- statement text, which must contain 8 parameters (NameQualifier, SPNameQualifier, value, principal, source ID, SPProvidedID, creation time, deactivation time)
-
setDeactivateSQL
Set the UPDATE statement used to deactivate issued values.- Parameters:
sql
- statement text, which must contain four parameters (deactivation TS, NameQualifier, SPNameQualifier, value)
-
setAttachSQL
Set the UPDATE statement used to attach an SPProvidedID to an issued value.- Parameters:
sql
- statement text, which must contain four parameters (SPProvidedID, NameQualifier, SPNameQualifier, value)
-
setDeleteSQL
Set the DELETE statement used to clear dummy row(s) created during verification.- Parameters:
sql
- statement text, which must contain one parameter (NameQualifier)
-
getInitialValueStore
Get a store to use to produce the first value for a given issuer/recipient pair.- Returns:
- initial value source
-
setInitialValueStore
Set a store to use to produce the first value for a given issuer/recipient pair.This is typically used to draw the "first" (often only) value for a given pairwise relationship from an algorithm instead of a random value requiring storage to know.
- Parameters:
store
- initial value source
-
doInitialize
- Overrides:
doInitialize
in classAbstractInitializableComponent
- Throws:
ComponentInitializationException
-
getBySourceValue
@Nullable public PairwiseId getBySourceValue(@Nonnull PairwiseId pid, boolean allowCreate) throws IOException Populate the pairwise ID field for the input object based on the supplied values.The input object must contain values for issuer and recipient entityIDs and the principal name, and the pairwise ID will be populated as applicable on output.
The object returned, if non-null, may be, but does not have to be, the same physical object used as input. The original input object should not be referenced further.
- Specified by:
getBySourceValue
in interfacePairwiseIdStore
- Parameters:
pid
- object to populateallowCreate
- true iff the caller is authorizing the issuance of a new identifier- Returns:
- object for the given inputs or null if none exists
- Throws:
IOException
- if an error occurs accessing the store
-
getByIssuedValue
Populate the underlying principal/source fields for the input object based on the supplied values.The input object must contain values for issuer and recipient entityIDs and the pairwiseId itself, and the rest of the fields will be populated as applicable on output.
The object returned, if non-null, will at least contain the principal name and source system ID. It may be, but does not have to be, the same physical object used as input. The original input object should not be referenced further.
- Specified by:
getByIssuedValue
in interfaceDurablePairwiseIdStore
- Parameters:
pid
- object to populate- Returns:
- object for the given inputs or null if none exists
- Throws:
IOException
- if an error occurs accessing the store
-
deactivate
Deactivate/revoke a pairwise ID.If the object's deactivation time field is null, then the current time is used.
- Specified by:
deactivate
in interfaceDurablePairwiseIdStore
- Parameters:
pid
- the object to deactivate/revoke- Throws:
IOException
- if there is an error updating the store
-
attach
Attach a peer-supplied alias to a pairwise ID.- Specified by:
attach
in interfaceDurablePairwiseIdStore
- Parameters:
pid
- the object to update in storage- Throws:
IOException
- if there is an error updating the store
-
store
void store(@Nonnull PairwiseId entry, @Nonnull JDBCPairwiseIdStore.ConnectionWithLock dbConn) throws SQLException Store a record containing the values from the input object.- Parameters:
entry
- new object to storedbConn
- connection to obtain a statement from.- Throws:
SQLException
- if an error occurs
-
verifyDatabase
Check the database and the presence of a uniqueness constraint.- Throws:
SQLException
- if the database cannot be verified
-
buildIdentifierEntries
@Nonnull @NonnullElements @Live private List<PairwiseId> buildIdentifierEntries(@Nonnull ResultSet resultSet) throws SQLException Build a list ofPairwiseId
objects from a result set.- Parameters:
resultSet
- the result set- Returns:
- list of
PairwiseId
objects - Throws:
SQLException
- thrown if there is a problem reading the information from the database
-