javax.sql.DataSource , applying the specified
user credentials to every standard getConnection() call, implicitly
invoking getConnection(username, password) on the target.
All other methods simply delegate to the corresponding methods of the
target DataSource.
Can be used to proxy a target JNDI DataSource that does not have user
credentials configured. Client code can work with this DataSource as usual,
using the standard getConnection() call.
In the following example, client code can simply transparently work with the preconfigured "myDataSource", implicitly accessing "myTargetDataSource" with the specified user credentials.
<bean id="myTargetDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/myds"/> </bean> <bean id="myDataSource" class="org.springframework.jdbc.datasource.UserCredentialsDataSourceAdapter"> <property name="targetDataSource" ref="myTargetDataSource"/> <property name="username" value="myusername"/> <property name="password" value="mypassword"/> </bean>
If the "username" is empty, this proxy will simply delegate to the
standard getConnection() method of the target DataSource.
This can be used to keep a UserCredentialsDataSourceAdapter bean definition
just for the option of implicitly passing in user credentials if
the particular target DataSource requires it.
getConnection
| Modifier and Type | Class and Description |
|---|---|
| private static class | UserCredentialsDataSourceAdapter.JdbcUserCredentials
Inner class used as ThreadLocal value. |
| Modifier and Type | Field and Description |
|---|---|
| private String | |
| private String | |
| private String | |
| private final ThreadLocal | |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Connection | Returns: the Connectionthe username to use username, String the password to use password)This implementation delegates to the |
| public Connection | getConnection()
Overrides org. Implements javax. |
| public Connection | getConnection(String
the database user on whose behalf the connection is
being made username, String the user's password password)Overrides org. Implements javax. doGetConnection(String, String),
keeping the given user credentials as-is.
|
| public void | removeCredentialsFromCurrentThread()
Remove any user credentials for this proxy from the current thread. |
| public void | |
| public void | setCredentialsForCurrentThread(String
the username to apply username, String the password to apply password)Set user credentials for this proxy and the current thread. |
| public void | setPassword(String password)
Set the default user's password that this adapter should use for retrieving Connections. |
| public void | |
| public void | setUsername(String username)
Set the default username that this adapter should use for retrieving Connections. |
| catalog | back to summary |
|---|---|
| private String catalog
| |
| password | back to summary |
|---|---|
| private String password
| |
| schema | back to summary |
|---|---|
| private String schema
| |
| threadBoundCredentials | back to summary |
|---|---|
| private final ThreadLocal<UserCredentialsDataSourceAdapter. | |
| username | back to summary |
|---|---|
| private String username
| |
| UserCredentialsDataSourceAdapter | back to summary |
|---|---|
| public UserCredentialsDataSourceAdapter() | |
| doGetConnection | back to summary |
|---|---|
| protected Connection doGetConnection(String username, String password) throws SQLException This implementation delegates to the
| |
| getConnection | back to summary |
|---|---|
| public Connection getConnection() throws SQLException Overrides org. Implements javax. Determine whether there are currently thread-bound credentials, using them if available, falling back to the statically specified username and password (i.e. values of the bean properties) otherwise. Delegates to
| |
| getConnection | back to summary |
|---|---|
| public Connection getConnection(String username, String password) throws SQLException Overrides org. Implements javax. Simply delegates to
| |
| removeCredentialsFromCurrentThread | back to summary |
|---|---|
| public void removeCredentialsFromCurrentThread() Remove any user credentials for this proxy from the current thread. Statically specified user credentials apply again afterwards.
| |
| setCatalog | back to summary |
|---|---|
| public void setCatalog(String catalog) Specify a database catalog to be applied to each retrieved Connection.
| |
| setCredentialsForCurrentThread | back to summary |
|---|---|
| public void setCredentialsForCurrentThread(String username, String password) Set user credentials for this proxy and the current thread.
The given username and password will be applied to all subsequent
This will override any statically specified user credentials, that is, values of the "username" and "password" bean properties.
| |
| setPassword | back to summary |
|---|---|
| public void setPassword(String password) Set the default user's password that this adapter should use for retrieving Connections. Default is no specific password. Note that an explicitly specified username will always override any username/password specified at the DataSource level. | |
| setSchema | back to summary |
|---|---|
| public void setSchema(String schema) Specify a database schema to be applied to each retrieved Connection.
| |
| setUsername | back to summary |
|---|---|
| public void setUsername(String username) Set the default username that this adapter should use for retrieving Connections. Default is no specific user. Note that an explicitly specified username will always override any username/password specified at the DataSource level. | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String |
| password | back to summary |
|---|---|
| public final String password | |
| username | back to summary |
|---|---|
| public final String username | |
| JdbcUserCredentials | back to summary |
|---|---|
| public JdbcUserCredentials(String username, String password) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |