title: authenticate connection to activeMQ with username/password
body: <p>I have an application running ok sending messages to activemq. I'm using spring.net and Nmstemplate to connect to broker.
  xml configuration file in general is:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;object id="ActiveMqConnectionFactory" 
          type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ"&gt;
  &lt;/object&gt;
  
  &lt;object id="ConnectionFactory"
          type="Spring.Messaging.Nms.Connections.CachingConnectionFactory, Spring.Messaging.Nms"&gt;
    &lt;constructor-arg index="0" ref="ActiveMqConnectionFactory"/&gt;
    &lt;property name="SessionCacheSize" value="10"/&gt;
  &lt;/object&gt;
  
  &lt;object id="NmsTemplate" 
          type="Spring.Messaging.Nms.Core.NmsTemplate, Spring.Messaging.Nms"&gt;
    &lt;constructor-arg index="0" ref="ConnectionFactory"/&gt;
    &lt;property name="MessageConverter" ref="SimpleMessageConverter"/&gt;
  &lt;/object&gt;
  
  &lt;object id="SimpleMessageConverter" 
          type="Spring.Messaging.Nms.Support.Converter.SimpleMessageConverter, Spring.Messaging.Nms"&gt;
  &lt;/object&gt;
  </code></pre>
  
  <p>Until everything is working find sending message with NmsTemplate.ConvertAndSend();
  The problem is that I want to secure connection using username/password.
  I setup credentials in activemq configuration file and now I need to supply this credentials in code but I dont find where !!
  I tried with:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;object id="ActiveMqConnectionFactory" type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ"&gt;
    &lt;property name="UserName" value="usertest"/&gt;
    &lt;property name="Password" value="passwordtest"/&gt;
  &lt;/object&gt;
  </code></pre>
  
  <p>But when sending I get "Connection already closed" exception, and the same setting credentials in code.</p>
  
  <p>So, anyone have a good example or hint in how to setup username/password to send message to secured activemq broker?</p>