Class HikariCredentialsUpdater
- All Implemented Interfaces:
UpdatableCredential<String>,com.zaxxer.hikari.HikariCredentialsProvider
This class implements both UpdatableCredential and HikariCredentialsProvider
interfaces, serving as a bridge between the credential rotation system and HikariCP's
built-in credential provider mechanism. It receives credential change notifications from the
CredentialsProviderService and provides those
credentials to HikariCP when new connections are created.
How It Works
- HikariCP is configured to use this class as its
HikariCredentialsProvider - When HikariCP needs credentials for a new connection, it calls
getCredentials() - When credentials are rotated,
setCredential(String, String)is called - The updater stores the new credentials and triggers soft eviction of existing connections
- Soft eviction marks connections for closure after they are returned to the pool
- New connections use the updated credentials from
getCredentials()
Thread Safety
This class is thread-safe. The Credentials object is immutable and is replaced
atomically when credentials are updated. The soft eviction operation is thread-safe as
implemented by HikariCP.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionHikariCredentialsUpdater(String username, String password) Creates a new credentials updater with the specified initial credentials. -
Method Summary
Modifier and TypeMethodDescriptioncom.zaxxer.hikari.util.CredentialsProvides the current credentials to HikariCP for new connection creation.voidsetCredential(String username, String credential) Updates the stored credentials and soft-evicts existing connections.voidsetDataSource(com.zaxxer.hikari.HikariDataSource dataSource) Sets the HikariCP DataSource reference for connection eviction.
-
Constructor Details
-
HikariCredentialsUpdater
Creates a new credentials updater with the specified initial credentials.- Parameters:
username- the initial database usernamepassword- the initial database password
-
-
Method Details
-
setDataSource
public void setDataSource(com.zaxxer.hikari.HikariDataSource dataSource) Sets the HikariCP DataSource reference for connection eviction.This method is called after the DataSource is created to enable soft eviction of connections when credentials are rotated. The circular dependency (DataSource needs credentials provider, credentials provider needs DataSource for eviction) is resolved by injecting the DataSource after creation.
- Parameters:
dataSource- the HikariCP DataSource to manage
-
setCredential
Updates the stored credentials and soft-evicts existing connections.This method atomically replaces the stored credentials with new ones, then triggers a soft eviction of all existing connections in the pool. Soft eviction marks connections for closure after they are returned to the pool, allowing in-flight transactions to complete while ensuring new checkouts get fresh connections with the updated credentials.
- Specified by:
setCredentialin interfaceUpdatableCredential<String>- Parameters:
username- the new database usernamecredential- the new database password
-
getCredentials
public com.zaxxer.hikari.util.Credentials getCredentials()Provides the current credentials to HikariCP for new connection creation.This method is called by HikariCP's connection factory when creating new connections. It returns the most recently set credentials.
- Specified by:
getCredentialsin interfacecom.zaxxer.hikari.HikariCredentialsProvider- Returns:
- the current credentials for database connections
-