public class JDBCPersistentIdStoreEx extends AbstractInitializableComponent implements PersistentIdStoreEx
The general DDL for the database 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.| Modifier and Type | Field and Description |
|---|---|
private String |
attachSQL
Parameterized update statement used to attach an alias to an ID.
|
private String |
creationTimeColumn
Name of the creation time column.
|
private DataSource |
dataSource
JDBC data source for retrieving connections.
|
private String |
deactivateSQL
Parameterized update statement used to deactivate an ID.
|
private String |
deactivationTimeColumn
Name of the deactivation time column.
|
private String |
deleteSQL
Parameterized delete statement used to clear dummy rows after verification.
|
private String |
getByIssuedSelectSQL
Parameterized select query for lookup by issued value.
|
private String |
getBySourceSelectSQL
Parameterized select query for lookup by source ID.
|
private String |
insertSQL
Parameterized insert statement used to insert a new record.
|
private String |
issuerColumn
Name of the issuer entityID column.
|
private org.slf4j.Logger |
log
Class logger.
|
private String |
peerProvidedIdColumn
Name of recipient-attached alias column.
|
private String |
persistentIdColumn
Name of the persistent ID column.
|
private String |
principalNameColumn
Name of the principal name column.
|
private long |
queryTimeout
Timeout of SQL queries in milliseconds.
|
private String |
recipientColumn
Name of the recipient entityID column.
|
private Collection<String> |
retryableErrors
Error messages that signal a transaction should be retried.
|
private String |
sourceIdColumn
Name of the source ID column.
|
private String |
tableName
Name of the database table.
|
private int |
transactionRetry
Number of times to retry a transaction if it rolls back.
|
private boolean |
verifyDatabase
Whether to fail if the database cannot be verified.
|
| Constructor and Description |
|---|
JDBCPersistentIdStoreEx()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attach(String nameQualifier,
String spNameQualifier,
String persistentId,
String spProvidedId)
Attach an SPProvidedID value to an existing entry.
|
private List<PersistentIdEntry> |
buildIdentifierEntries(ResultSet resultSet)
Builds a list of
PersistentIdEntrys from a result set. |
void |
deactivate(String nameQualifier,
String spNameQualifier,
String persistentId,
DateTime deactivation)
Deactivate/revoke a persistent ID.
|
protected void |
doInitialize() |
PersistentIdEntry |
getByIssuedValue(String nameQualifier,
String spNameQualifier,
String persistentId)
Get the
PersistentIdEntry for a previously issued ID triple. |
PersistentIdEntry |
getBySourceValue(String nameQualifier,
String spNameQualifier,
String sourceId,
String principal,
boolean allowCreate,
ComputedPersistentIdGenerationStrategy computedIdStrategy)
Get the
PersistentIdEntry for a given subject and audience, creating one if allowable
and necessary. |
private Connection |
getConnection(boolean autoCommit)
Obtain a connection from the data source.
|
DataSource |
getDataSource()
Get the source datasource used to communicate with the database.
|
private String |
getLogPrefix()
Return a string which is to be prepended to all log messages.
|
long |
getQueryTimeout()
Get the SQL query timeout.
|
Collection<String> |
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.
|
int |
getTransactionRetries()
Get the number of retries to attempt for a failed transaction.
|
boolean |
getVerifyDatabase()
Get whether to allow startup if the database cannot be verified.
|
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 |
setDeactivationTimeColumn(String name)
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 |
setGetByIssuedSelectSQL(String sql)
Set the SELECT statement used to lookup records by issued value.
|
void |
setGetBySourceSelectSQL(String sql)
Set the SELECT statement used to lookup records by source ID.
|
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 |
setPeerEntityColumn(String name)
Set the name of the recipient entityID column.
|
void |
setPeerProvidedIdColumn(String name)
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(long 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 |
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(PersistentIdEntry entry,
Connection dbConn)
Store a record containing the values from the input object.
|
private void |
verifyDatabase()
Check the database and the presence of a uniqueness constraint.
|
destroy, doDestroy, initialize, isDestroyed, isInitialized@Nonnull private final org.slf4j.Logger log
@NonnullAfterInit private DataSource dataSource
@Duration @NonNegative private long queryTimeout
@NonNegative private int transactionRetry
@Nonnull @NonnullElements private Collection<String> retryableErrors
private boolean verifyDatabase
@Nonnull @NotEmpty private String recipientColumn
@Nonnull @NotEmpty private String principalNameColumn
@Nonnull @NotEmpty private String persistentIdColumn
@Nonnull @NotEmpty private String peerProvidedIdColumn
@Nonnull @NotEmpty private String creationTimeColumn
@Nonnull @NotEmpty private String deactivationTimeColumn
@NonnullAfterInit private String getByIssuedSelectSQL
@NonnullAfterInit private String getBySourceSelectSQL
@NonnullAfterInit private String insertSQL
@NonnullAfterInit private String deactivateSQL
@NonnullAfterInit private String attachSQL
@NonnullAfterInit private String deleteSQL
@NonnullAfterInit public DataSource getDataSource()
public void setDataSource(@Nonnull DataSource source)
source - the data source;@NonNegative @Duration public long getQueryTimeout()
@Duration public void setQueryTimeout(@Duration@NonNegative long timeout)
timeout - the timeout to set in millisecondspublic int getTransactionRetries()
public void setTransactionRetries(@NonNegative int retries)
retries - the number of retries@Nonnull @NonnullElements public Collection<String> getRetryableErrors()
public void setRetryableErrors(@Nullable@NonnullElements Collection<String> errors)
errors - retryable messagespublic boolean getVerifyDatabase()
public void setVerifyDatabase(boolean flag)
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.
flag - flag to setpublic void setTableName(@Nonnull@NotEmpty String name)
name - table namepublic void setLocalEntityColumn(@Nonnull@NotEmpty String name)
name - name of issuer columnpublic void setPeerEntityColumn(@Nonnull@NotEmpty String name)
name - name of recipient columnpublic void setPrincipalNameColumn(@Nonnull@NotEmpty String name)
name - name of principal name columnpublic void setSourceIdColumn(@Nonnull@NotEmpty String name)
name - name of source ID columnpublic void setPersistentIdColumn(@Nonnull@NotEmpty String name)
name - name of the persistent ID columnpublic void setPeerProvidedIdColumn(@Nonnull@NotEmpty String name)
name - name of peer-provided ID columnpublic void setCreateTimeColumn(@Nonnull@NotEmpty String name)
name - name of creation time columnpublic void setDeactivationTimeColumn(@Nonnull@NotEmpty String name)
name - name of deactivation time columnpublic void setGetByIssuedSelectSQL(@Nonnull@NotEmpty String sql)
sql - statement text, which must contain three parameters (NameQualifier, SPNameQualifier, value)public void setGetBySourceSelectSQL(@Nonnull@NotEmpty String sql)
sql - statement text, which must contain six parameters
(NameQualifier, SPNameQualifier, source ID, NameQualifier, SPNameQualifier, source ID)public void setInsertSQL(@Nonnull@NotEmpty String sql)
sql - statement text, which must contain 8 parameters
(NameQualifier, SPNameQualifier, value, principal, source ID, SPProvidedID, creation time, deactivation time)public void setDeactivateSQL(@Nonnull@NotEmpty String sql)
sql - statement text, which must contain four parameters
(deactivation TS, NameQualifier, SPNameQualifier, value)public void setAttachSQL(@Nonnull@NotEmpty String sql)
sql - statement text, which must contain four parameters
(SPProvidedID, NameQualifier, SPNameQualifier, value)public void setDeleteSQL(@Nonnull@NotEmpty String sql)
sql - statement text, which must contain one parameter (NameQualifier)protected void doInitialize()
throws ComponentInitializationException
doInitialize in class AbstractInitializableComponentComponentInitializationException@Nullable public PersistentIdEntry getByIssuedValue(@Nonnull@NotEmpty String nameQualifier, @Nonnull@NotEmpty String spNameQualifier, @Nonnull@NotEmpty String persistentId) throws IOException
PersistentIdEntry for a previously issued ID triple.getByIssuedValue in interface PersistentIdStoreExnameQualifier - the NameQualifier valuespNameQualifier - the SPNameQualifier valuepersistentId - the persistent ID valuePersistentIdEntry for the given inputs or null if none existsIOException - if an error occurs accessing the store@Nullable public PersistentIdEntry getBySourceValue(@Nonnull@NotEmpty String nameQualifier, @Nonnull@NotEmpty String spNameQualifier, @Nonnull@NotEmpty String sourceId, @Nonnull@NotEmpty String principal, boolean allowCreate, @Nullable ComputedPersistentIdGenerationStrategy computedIdStrategy) throws IOException
PersistentIdEntry for a given subject and audience, creating one if allowable
and necessary.getBySourceValue in interface PersistentIdStoreExnameQualifier - the NameQualifier valuespNameQualifier - the SPNameQualifier valuesourceId - source attribute underlying the persistent IDprincipal - principal name of subject (may or may not be the same as the sourceId)allowCreate - whether it's permissible to establish/issue a new identifiercomputedIdStrategy - optional source of initial computed IDs for compatibilty with that mechanismPersistentIdEntry for the given inputs, or null if none exists and allowCreate is falseIOException - if an error occurs accessing the storepublic void deactivate(@Nonnull@NotEmpty String nameQualifier, @Nonnull@NotEmpty String spNameQualifier, @Nonnull@NotEmpty String persistentId, @Nullable DateTime deactivation) throws IOException
deactivate in interface PersistentIdStoreExnameQualifier - the NameQualifier valuespNameQualifier - the SPNameQualifier valuepersistentId - ID to deactivatedeactivation - deactivation time (if null the current time is used)IOException - if there is an error updating the storepublic void attach(@Nonnull@NotEmpty String nameQualifier, @Nonnull@NotEmpty String spNameQualifier, @Nonnull@NotEmpty String persistentId, @Nonnull@NotEmpty String spProvidedId) throws IOException
attach in interface PersistentIdStoreExnameQualifier - the NameQualifier valuespNameQualifier - the SPNameQualifier valuepersistentId - ID to deactivatespProvidedId - the value to attachIOException - if there is an error updating the storevoid store(@Nonnull PersistentIdEntry entry, @Nonnull Connection dbConn) throws SQLException
entry - new object to storedbConn - connection to obtain a statement from.SQLException - if an error occurs@Nonnull private Connection getConnection(boolean autoCommit) throws SQLException
The caller must close the connection.
autoCommit - auto-commit setting to apply to the connectionSQLException - if an error occursprivate void verifyDatabase()
throws SQLException
SQLException - if the database cannot be verified@Nonnull @NonnullElements @Live private List<PersistentIdEntry> buildIdentifierEntries(@Nonnull ResultSet resultSet) throws SQLException
PersistentIdEntrys from a result set.resultSet - the result setPersistentIdEntrysSQLException - thrown if there is a problem reading the information from the databaseCopyright © 1999–2017 Shibboleth Consortium. All rights reserved.