jakarta.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.
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.
createConnection, createQueueConnection, createTopicConnection
| Modifier and Type | Class and Description |
|---|---|
| private static class | UserCredentialsConnectionFactoryAdapter.
Inner class used as ThreadLocal value. |
| Modifier and Type | Field and Description |
|---|---|
| private String | |
| private ConnectionFactory | |
| private final ThreadLocal | |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| public final Connection | createConnection()
Implements jakarta. 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. |
| public Connection | createConnection(String
the caller's user name username, String the caller's password password)Implements jakarta. Delegate the call straight to the target ConnectionFactory. |
| public JMSContext | createContext()
Implements jakarta. Creates a JMSContext with the default user identity and an unspecified sessionMode. |
| public JMSContext | createContext(String
the caller's user name userName, String the caller's password password)Implements jakarta. Creates a JMSContext with the specified user identity and an unspecified sessionMode. |
| public JMSContext | createContext(String
the caller's user name userName, String the caller's password password, int indicates which of four possible session modes will be used.
sessionMode)
Implements jakarta. Creates a JMSContext with the specified user identity and the specified session mode. |
| public JMSContext | createContext(int
indicates which of four possible session modes will be used.
sessionMode)
Implements jakarta. Creates a JMSContext with the default user identity and the specified session mode. |
| public final QueueConnection | createQueueConnection()
Implements jakarta. 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. |
| public QueueConnection | createQueueConnection(String
the caller's user name username, String the caller's password password)Implements jakarta. Delegate the call straight to the target QueueConnectionFactory. |
| public final TopicConnection | createTopicConnection()
Implements jakarta. 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. |
| public TopicConnection | createTopicConnection(String
the caller's user name username, String the caller's password password)Implements jakarta. Delegate the call straight to the target TopicConnectionFactory. |
| protected Connection | Returns: the Connectionthe username to use username, String the password to use password)This implementation delegates to the |
| protected QueueConnection | Returns: the Connectionthe username to use username, String the password to use password)This implementation delegates to the |
| protected TopicConnection | Returns: the Connectionthe username to use username, String the password to use password)This implementation delegates to the |
| private ConnectionFactory | |
| public void | removeCredentialsFromCurrentThread()
Remove any user credentials for this proxy from the current thread. |
| 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 password that this adapter should use for retrieving Connections. |
| public void | setTargetConnectionFactory(ConnectionFactory targetConnectionFactory)
Set the target ConnectionFactory that this ConnectionFactory should delegate to. |
| public void | setUsername(String username)
Set the username that this adapter should use for retrieving Connections. |
| password | back to summary |
|---|---|
| private String password
| |
| targetConnectionFactory | back to summary |
|---|---|
| private ConnectionFactory targetConnectionFactory
| |
| threadBoundCredentials | back to summary |
|---|---|
| private final ThreadLocal<UserCredentialsConnectionFactoryAdapter. | |
| username | back to summary |
|---|---|
| private String username
| |
| UserCredentialsConnectionFactoryAdapter | back to summary |
|---|---|
| public UserCredentialsConnectionFactoryAdapter() | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() Implements org. Doc from org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
| |
| createConnection | back to summary |
|---|---|
| public final Connection createConnection() throws JMSException Implements jakarta. 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.
| |
| createConnection | back to summary |
|---|---|
| public Connection createConnection(String username, String password) throws JMSException Implements jakarta. Delegate the call straight to the target ConnectionFactory.
| |
| createContext | back to summary |
|---|---|
| public JMSContext createContext() Implements jakarta. Doc from jakarta. Creates a JMSContext with the default user identity and an unspecified sessionMode. A connection and session are created for use by the new JMSContext. The connection is created in stopped mode but will be automatically started when a JMSConsumer is created. The behaviour of the session that is created depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the behaviour of the session also depends on whether or not there is an active JTA transaction in progress. In a Java SE environment or in the Jakarta EE application client container:
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
| |
| createContext | back to summary |
|---|---|
| public JMSContext createContext(String userName, String password) Implements jakarta. Doc from jakarta. Creates a JMSContext with the specified user identity and an unspecified sessionMode. A connection and session are created for use by the new JMSContext. The connection is created in stopped mode but will be automatically started when a JMSConsumer. The behaviour of the session that is created depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the behaviour of the session also depends on whether or not there is an active JTA transaction in progress. In a Java SE environment or in the Jakarta EE application client container:
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
| |
| createContext | back to summary |
|---|---|
| public JMSContext createContext(String userName, String password, int sessionMode) Implements jakarta. Doc from jakarta. Creates a JMSContext with the specified user identity and the specified session mode. A connection and session are created for use by the new JMSContext. The JMSContext is created in stopped mode but will be automatically started when a JMSConsumer is created.
The effect of setting the In a Java SE environment or in the Jakarta EE application client container:
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
| |
| createContext | back to summary |
|---|---|
| public JMSContext createContext(int sessionMode) Implements jakarta. Doc from jakarta. Creates a JMSContext with the default user identity and the specified session mode. A connection and session are created for use by the new JMSContext. The JMSContext is created in stopped mode but will be automatically started when a JMSConsumer is created.
The effect of setting the In a Java SE environment or in the Jakarta EE application client container:
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
| |
| createQueueConnection | back to summary |
|---|---|
| public final QueueConnection createQueueConnection() throws JMSException Implements jakarta. 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.
| |
| createQueueConnection | back to summary |
|---|---|
| public QueueConnection createQueueConnection(String username, String password) throws JMSException Implements jakarta. Delegate the call straight to the target QueueConnectionFactory.
| |
| createTopicConnection | back to summary |
|---|---|
| public final TopicConnection createTopicConnection() throws JMSException Implements jakarta. 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.
| |
| createTopicConnection | back to summary |
|---|---|
| public TopicConnection createTopicConnection(String username, String password) throws JMSException Implements jakarta. Delegate the call straight to the target TopicConnectionFactory.
| |
| doCreateConnection | back to summary |
|---|---|
| protected Connection doCreateConnection(String username, String password) throws JMSException This implementation delegates to the
| |
| doCreateQueueConnection | back to summary |
|---|---|
| protected QueueConnection doCreateQueueConnection(String username, String password) throws JMSException This implementation delegates to the
| |
| doCreateTopicConnection | back to summary |
|---|---|
| protected TopicConnection doCreateTopicConnection(String username, String password) throws JMSException This implementation delegates to the
| |
| obtainTargetConnectionFactory | back to summary |
|---|---|
| private ConnectionFactory obtainTargetConnectionFactory() | |
| 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.
| |
| 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 password that this adapter should use for retrieving Connections. Default is no specific password. | |
| setTargetConnectionFactory | back to summary |
|---|---|
| public void setTargetConnectionFactory(ConnectionFactory targetConnectionFactory) Set the target ConnectionFactory that this ConnectionFactory should delegate to. | |
| setUsername | back to summary |
|---|---|
| public void setUsername(String username) Set the username that this adapter should use for retrieving Connections. Default is no specific user. | |
| 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 | |
| JmsUserCredentials | back to summary |
|---|---|
| public JmsUserCredentials(String username, String password) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |