How to authenticate a connection
For whatever reason, it seems to be not very common to require authentication for messaging servers, but JMS supports authentication, of course. Just pass username and password to createConnection:
// Example with ActiveMQ ConnectionFactory
ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection con = factory.createConnection("username", "password");
When you use JMS in an application server, you will usually configure the authentication in the server.