title: Spring JmsTemplate + Security
body: <p>I've just refactored some code that published to a JMS topic to use Spring's JmsTemplate class and now I'm receiving an exception stating I'm not authenticated.</p>
  
  <p>Previously I created the factory, made a connection, then session etc as follows:</p>
  
  <pre><code>MQTopicConnectionFactory factory = new MQTopicConnectionFactory();
  factory.setQueueManager(qMgr);   
  factory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
  factory.setHostName(hostname);
  factory.setPort(listenerPort);
  factory.setChannel(channel);
  // setting username and password to be empty string ==&gt; no authentication
  connection = factory.createConnection("", "");   
  ...
  connection.start();
  </code></pre>
  
  <p>I don't see anywhere in the JmsTemplate to set the username and password to empty strings. My config looks like this:</p>
  
  <pre><code>&lt;bean id="jmsFactory" class="com.ibm.mq.jms.MQTopicConnectionFactory"&gt;
      &lt;property name="queueManager"&gt;
          &lt;value&gt;ACT01&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="hostName"&gt;
          &lt;value&gt;xx.xx.xx.xx&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="port"&gt;
          &lt;value&gt;15004&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="transportType"&gt;
          &lt;value&gt;1&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="channel"&gt;
          &lt;value&gt;CONDUCTOR.ACT01&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="impactJmsTemplate" class="org.springframework.jms.core.JmsTemplate"&gt;
      &lt;property name="connectionFactory"&gt;
          &lt;bean class="org.springframework.jms.connection.SingleConnectionFactory"&gt;
              &lt;property name="targetConnectionFactory"&gt;
                  &lt;ref local="jmsFactory" /&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>I have also tried wrapping the jmsFactory in a <code>UserCredentialsConnectionFactoryAdapter</code> object to no avail:</p>
  
  <pre><code>&lt;bean id="jmsConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"&gt;
      &lt;property name="targetConnectionFactory" ref="jmsFactory"/&gt;
      &lt;property name="username" value=""/&gt;
      &lt;property name="password" value=""/&gt;
  &lt;/bean&gt; 
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>Caused by: com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: The security authentication was not valid that was supplied for QueueManager 'LOROL' with connection mode 'Client' and host name 'xx.xx.xx.xx'. Please check if the supplied username and password are correct on the QueueManager you are connecting to
  at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:531)
  at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:219)
  at com.ibm.msg.client.wmq.internal.WMQConnection.&lt;init&gt;(WMQConnection.java:410)
  at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:7855)
  at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:7331)
  at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:276)
  at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6055)
  at com.ibm.mq.jms.MQTopicConnectionFactory.createTopicConnection(MQTopicConnectionFactory.java:114)
  at com.ibm.mq.jms.MQTopicConnectionFactory.createConnection(MQTopicConnectionFactory.java:197)
  at org.springframework.jms.connection.SingleConnectionFactory.doCreateConnection(SingleConnectionFactory.java:343)
  at org.springframework.jms.connection.SingleConnectionFactory.initConnection(SingleConnectionFactory.java:290)
  at org.springframework.jms.connection.SingleConnectionFactory.createConnection(SingleConnectionFactory.java:227)
  at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184)
  at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:461)
  ... 25 more
  Caused by: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2035' ('MQRC_NOT_AUTHORIZED').
  at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:206)
  ... 37 more
  </code></pre>