Class UserCredentialsConnectionFactoryAdapter
- All Implemented Interfaces:
- ConnectionFactory,- QueueConnectionFactory,- TopicConnectionFactory,- InitializingBean
ConnectionFactory, applying the
 given user credentials to every standard methods that can also be used with
 authentication, this  createConnection() and createContext(). In
 other words, it is implicitly invoking createConnection(username, password) or
 createContext(username, password)} on the target. All other methods simply
 delegate to the corresponding methods of the target ConnectionFactory.
 Can be used to proxy a target JNDI ConnectionFactory that does not have user
 credentials configured. Client code can work with the ConnectionFactory without
 passing in username and password on every createConnection() and
 createContext() call.
 
In the following example, client code can simply transparently work with the preconfigured "myConnectionFactory", implicitly accessing "myTargetConnectionFactory" with the specified user credentials.
<bean id="myTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jms/mycf"/> </bean> <bean id="myConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"> <property name="targetConnectionFactory" ref="myTargetConnectionFactory"/> <property name="username" value="myusername"/> <property name="password" value="mypassword"/> </bean>
If the "username" is empty, this proxy will simply delegate to the standard
 createConnection() or createContext() method of the target
 ConnectionFactory. This can be used to keep a UserCredentialsConnectionFactoryAdapter
 bean definition just for the option of implicitly passing in user credentials
 if the particular target ConnectionFactory requires it.
 
As of Spring Framework 5, this class delegates JMS 2.0 JMSContext
 calls and therefore requires the JMS 2.0 API to be present at runtime.
 It may nevertheless run against a JMS 1.1 driver (bound to the JMS 2.0 API)
 as long as no actual JMS 2.0 calls are triggered by the application's setup.
- Since:
- 1.2
- Author:
- Juergen Hoeller, Stephane Nicoll
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.final ConnectionDetermine whether there are currently thread-bound credentials, using them if available, falling back to the statically specified username and password (i.e.createConnection(String username, String password) Delegate the call straight to the target ConnectionFactory.createContext(int sessionMode) createContext(String userName, String password) createContext(String userName, String password, int sessionMode) final QueueConnectionDetermine whether there are currently thread-bound credentials, using them if available, falling back to the statically specified username and password (i.e.createQueueConnection(String username, String password) Delegate the call straight to the target QueueConnectionFactory.final TopicConnectionDetermine whether there are currently thread-bound credentials, using them if available, falling back to the statically specified username and password (i.e.createTopicConnection(String username, String password) Delegate the call straight to the target TopicConnectionFactory.protected ConnectiondoCreateConnection(String username, String password) This implementation delegates to thecreateConnection(username, password)method of the target ConnectionFactory, passing in the specified user credentials.protected JMSContextdoCreateContext(String username, String password) protected JMSContextdoCreateContext(String username, String password, int sessionMode) protected QueueConnectiondoCreateQueueConnection(String username, String password) This implementation delegates to thecreateQueueConnection(username, password)method of the target QueueConnectionFactory, passing in the specified user credentials.protected TopicConnectiondoCreateTopicConnection(String username, String password) This implementation delegates to thecreateTopicConnection(username, password)method of the target TopicConnectionFactory, passing in the specified user credentials.voidRemove any user credentials for this proxy from the current thread.voidsetCredentialsForCurrentThread(String username, String password) Set user credentials for this proxy and the current thread.voidsetPassword(String password) Set the password that this adapter should use for retrieving Connections.voidsetTargetConnectionFactory(ConnectionFactory targetConnectionFactory) Set the target ConnectionFactory that this ConnectionFactory should delegate to.voidsetUsername(String username) Set the username that this adapter should use for retrieving Connections.
- 
Constructor Details- 
UserCredentialsConnectionFactoryAdapterpublic UserCredentialsConnectionFactoryAdapter()
 
- 
- 
Method Details- 
setTargetConnectionFactorySet the target ConnectionFactory that this ConnectionFactory should delegate to.
- 
setUsernameSet the username that this adapter should use for retrieving Connections. Default is no specific user.
- 
setPasswordSet the password that this adapter should use for retrieving Connections. Default is no specific password.
- 
afterPropertiesSetpublic void afterPropertiesSet()Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. - Specified by:
- afterPropertiesSetin interface- InitializingBean
 
- 
setCredentialsForCurrentThreadSet user credentials for this proxy and the current thread. The given username and password will be applied to all subsequentcreateConnection()calls on this ConnectionFactory proxy.This will override any statically specified user credentials, that is, values of the "username" and "password" bean properties. - Parameters:
- username- the username to apply
- password- the password to apply
- See Also:
 
- 
removeCredentialsFromCurrentThreadpublic void removeCredentialsFromCurrentThread()Remove any user credentials for this proxy from the current thread. Statically specified user credentials apply again afterwards.
- 
createConnectionDetermine 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.- Specified by:
- createConnectionin interface- ConnectionFactory
- Throws:
- JMSException
- See Also:
 
- 
createConnectionDelegate the call straight to the target ConnectionFactory.- Specified by:
- createConnectionin interface- ConnectionFactory
- Throws:
- JMSException
 
- 
doCreateConnectionprotected Connection doCreateConnection(@Nullable String username, @Nullable String password) throws JMSException This implementation delegates to thecreateConnection(username, password)method of the target ConnectionFactory, passing in the specified user credentials. If the specified username is empty, it will simply delegate to the standardcreateConnection()method of the target ConnectionFactory.- Parameters:
- username- the username to use
- password- the password to use
- Returns:
- the Connection
- Throws:
- JMSException
- See Also:
 
- 
createQueueConnectionDetermine 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.- Specified by:
- createQueueConnectionin interface- QueueConnectionFactory
- Throws:
- JMSException
- See Also:
 
- 
createQueueConnectionDelegate the call straight to the target QueueConnectionFactory.- Specified by:
- createQueueConnectionin interface- QueueConnectionFactory
- Throws:
- JMSException
 
- 
doCreateQueueConnectionprotected QueueConnection doCreateQueueConnection(@Nullable String username, @Nullable String password) throws JMSException This implementation delegates to thecreateQueueConnection(username, password)method of the target QueueConnectionFactory, passing in the specified user credentials. If the specified username is empty, it will simply delegate to the standardcreateQueueConnection()method of the target ConnectionFactory.- Parameters:
- username- the username to use
- password- the password to use
- Returns:
- the Connection
- Throws:
- JMSException
- See Also:
 
- 
createTopicConnectionDetermine 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.- Specified by:
- createTopicConnectionin interface- TopicConnectionFactory
- Throws:
- JMSException
- See Also:
 
- 
createTopicConnectionDelegate the call straight to the target TopicConnectionFactory.- Specified by:
- createTopicConnectionin interface- TopicConnectionFactory
- Throws:
- JMSException
 
- 
doCreateTopicConnectionprotected TopicConnection doCreateTopicConnection(@Nullable String username, @Nullable String password) throws JMSException This implementation delegates to thecreateTopicConnection(username, password)method of the target TopicConnectionFactory, passing in the specified user credentials. If the specified username is empty, it will simply delegate to the standardcreateTopicConnection()method of the target ConnectionFactory.- Parameters:
- username- the username to use
- password- the password to use
- Returns:
- the Connection
- Throws:
- JMSException
- See Also:
 
- 
createContext- Specified by:
- createContextin interface- ConnectionFactory
 
- 
doCreateContext
- 
createContext- Specified by:
- createContextin interface- ConnectionFactory
 
- 
createContext- Specified by:
- createContextin interface- ConnectionFactory
 
- 
createContext- Specified by:
- createContextin interface- ConnectionFactory
 
- 
doCreateContextprotected JMSContext doCreateContext(@Nullable String username, @Nullable String password, int sessionMode) 
 
-