|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.datasource.DelegatingDataSource org.springframework.jdbc.datasource.UserCredentialsDataSourceAdapter
public class UserCredentialsDataSourceAdapter
An adapter for a target DataSource, applying the given user credentials to
every standard getConnection()
call, that is, 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 the DataSource without
passing in username and password on every 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</value></property> </bean> <bean id="myDataSource" class="org.springframework.jdbc.datasource.UserCredentialsDataSourceAdapter"> <property name="targetDataSource"><ref bean="myTargetDataSource"/></property> <property name="username"><value>myusername</value></property> <property name="password"><value>mypassword</value></property> </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
a particular target DataSource requires it.
getConnection()
Constructor Summary | |
---|---|
UserCredentialsDataSourceAdapter()
|
Method Summary | |
---|---|
protected Connection |
doGetConnection(String username,
String password)
This implementation delegates to the getConnection(username, password)
method of the target DataSource, passing in the specified user credentials. |
Connection |
getConnection()
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) else. |
void |
removeCredentialsFromCurrentThread()
Remove any user credentials for this proxy from the current thread. |
void |
setCredentialsForCurrentThread(String username,
String password)
Set user credententials for this proxy and the current thread. |
void |
setPassword(String password)
Set the password that this adapter should use for retrieving Connections. |
void |
setUsername(String username)
Set the username that this adapter should use for retrieving Connections. |
Methods inherited from class org.springframework.jdbc.datasource.DelegatingDataSource |
---|
afterPropertiesSet, getConnection, getLoginTimeout, getLogWriter, getTargetDataSource, setLoginTimeout, setLogWriter, setTargetDataSource |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UserCredentialsDataSourceAdapter()
Method Detail |
---|
public void setUsername(String username)
public void setPassword(String password)
public void setCredentialsForCurrentThread(String username, String password)
getConnection()
calls on this DataSource proxy.
This will override any statically specified user credentials, that is, values of the "username" and "password" bean properties.
username
- the username to applypassword
- the password to applyremoveCredentialsFromCurrentThread()
public void removeCredentialsFromCurrentThread()
public final Connection getConnection() throws SQLException
getConnection
in interface DataSource
getConnection
in class DelegatingDataSource
SQLException
doGetConnection(java.lang.String, java.lang.String)
protected Connection doGetConnection(String username, String password) throws SQLException
getConnection(username, password)
method of the target DataSource, passing in the specified user credentials.
If the specified username is empty, it will simply delegate to the standard
getConnection()
method of the target DataSource.
username
- the username to usepassword
- the password to use
SQLException
DataSource.getConnection(String, String)
,
DataSource.getConnection()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |