spring-framework / org.springframework.jms.connection / UserCredentialsConnectionFactoryAdapter

UserCredentialsConnectionFactoryAdapter

open class UserCredentialsConnectionFactoryAdapter : ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, InitializingBean

An adapter for a target JMS javax.jms.ConnectionFactory, applying the given user credentials to every standard createConnection() call, that is, implicitly invoking createConnection(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() 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() 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.

Author
Juergen Hoeller

Since
1.2

See Also
#createConnection#createQueueConnection#createTopicConnection

Constructors

<init>

UserCredentialsConnectionFactoryAdapter()

An adapter for a target JMS javax.jms.ConnectionFactory, applying the given user credentials to every standard createConnection() call, that is, implicitly invoking createConnection(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() 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() 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.

Functions

afterPropertiesSet

open fun afterPropertiesSet(): Unit

createConnection

fun createConnection(): Connection

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.

open fun createConnection(username: String, password: String): Connection

Delegate the call straight to the target ConnectionFactory.

createContext

open fun createContext(): JMSContext
open fun createContext(userName: String, password: String): JMSContext
open fun createContext(userName: String, password: String, sessionMode: Int): JMSContext
open fun createContext(sessionMode: Int): JMSContext

createQueueConnection

fun createQueueConnection(): QueueConnection

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.

open fun createQueueConnection(username: String, password: String): QueueConnection

Delegate the call straight to the target QueueConnectionFactory.

createTopicConnection

fun createTopicConnection(): TopicConnection

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.

open fun createTopicConnection(username: String, password: String): TopicConnection

Delegate the call straight to the target TopicConnectionFactory.

removeCredentialsFromCurrentThread

open fun removeCredentialsFromCurrentThread(): Unit

Remove any user credentials for this proxy from the current thread. Statically specified user credentials apply again afterwards.

setCredentialsForCurrentThread

open fun setCredentialsForCurrentThread(username: String, password: String): Unit

Set user credententials for this proxy and the current thread. The given username and password will be applied to all subsequent createConnection() calls on this ConnectionFactory proxy.

This will override any statically specified user credentials, that is, values of the "username" and "password" bean properties.

setPassword

open fun setPassword(password: String): Unit

Set the password that this adapter should use for retrieving Connections. Default is no specific password.

setTargetConnectionFactory

open fun setTargetConnectionFactory(targetConnectionFactory: ConnectionFactory): Unit

Set the target ConnectionFactory that this ConnectionFactory should delegate to.

setUsername

open fun setUsername(username: String): Unit

Set the username that this adapter should use for retrieving Connections. Default is no specific user.