Bug 45458 - Point to Point JMS in combination with authentication
Point to Point JMS in combination with authentication
Status: RESOLVED FIXED
Product: JMeter
Classification: Unclassified
Component: Main
2.3.2
PC Windows XP
: P2 normal (vote)
: ---
Assigned To: JMeter issues mailing list
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2008-07-22 07:38 UTC by Ronald van de Kuil
Modified: 2008-11-06 16:20 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ronald van de Kuil 2008-07-22 07:38:21 UTC
sebb <sebbaz@gmail.com> 

The JMS Publisher and Subscriber sampler GUIs both have
Username/Password fields which are used by the samplers; however for
some reason the JMS Point to Point GUI does not.

I've no idea why that is so - perhaps it was an oversight.

I suggest someone creates a Bugzilla issue asking for these fields to
be added to the GUI and the sampler. [Unfortunately the GUI is already
very full, but I guess that can be rearranged a bit]

Note RKU:

  I have got the authentication working with IBM MQSeries using the JMS
  Point to Point sampler.

  I modified the code as follows:

  In the class org.apache.jmeter.protocol.jms.sampler.JMSSampler I have
  added 2 methods:

    /**
     * RKU: get us the user
     *
     * @param context
     * @return
     * @throws NamingException
     */
    private String getUser(Context context) throws NamingException{
            Hashtable env = context.getEnvironment();
            return (String) env.get("java.naming.security.principal");
    }

    /**
     * RKU: get us the password
     *
     * @param context
     * @return
     * @throws NamingException
     */
    private String getPassword(Context context) throws NamingException{
            Hashtable env = context.getEnvironment();
            return (String) env.get("java.naming.security.credentials");
    }

In the same class I have replaced the line that creates the queue connection in the method threadStarted() of the same class:

if (null != getUser(context) && null != getPassword(context)){
     System.out.println("explicit user and password");
     connection = factory.createQueueConnection(
                          getUser(context), 
                          getPassword(context));
}else{
     System.out.println("without explicit authentication");
     connection = factory.createQueueConnection();
}

Perhaps IBM MQSeries uses different properties for the user and the password but I am not very knowledgeable in this area.

The following link suggests that the used properties are correct for MQ series:
http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/how-to-connect-to-mqseries/doc/how-to-connect-to-mqseries.html#env

If anyone wants to reproduce this then you should know the following:

- use the com.sun.jndi.fscontext.RefFSContextFactory class as initial
context factory with a url to the JNDI repository;
- use IBM JMSAdmin tool to create a JNDI mapping between your JMS world
and the MQ world in your JNDI repository;

And of course you will have to add the ibm mq jars to the lib directory of jmeter.

JAR	         Obtained via
mail.jar	 jmeter site
activation.jar	 jmeter site
com.ibm.mq.jar	 MQ installation
com.ibm.mqjms.jar	MQ installation
connector.jar	 MQ installation
dhbcore.jar	 MQ installation
fscontext.jar	 MQ installation
jms.jar	         MQ installation
jta.jar	         MQ installation
providerutil.jar MQ installation
mqcontext.jar	 support pac ME01
com.ibm.mq.pcf-6.0.3.jar support pac MS0B
Comment 1 Sebb 2008-07-22 09:56:23 UTC
Are there any circumstances where the properties need to be set differently for the context compared to values used in the QueueConnection?

If not, then the solution seems OK, otherwise perhaps the GUI needs separate fields for them.

Comment 2 Ronald van de Kuil 2008-07-23 02:37:22 UTC
I am not really sure. The properties java.naming.security.principal and java.naming.security.credentials are intended for a vendor neutral approach for specifying a user and a password as far as I know. 

A safer solution would probably be to add a user and password textfield to the panel and call factory.createQueueConnection with an explicit user and password when the textfields have filled. This would also be more user friendly.


Comment 3 Ronald van de Kuil 2008-08-04 01:49:59 UTC
The code suggested on 2008-07-22 07:38 works for the RequestOnly sampler.

For the RequestResponse sampler I had to change the receiver as well.

I made the following changes:

In the class org.apache.jmeter.protocol.jms.sampler.Receiver I modified the 2 of its methods as follows:

private Receiver(QueueConnectionFactory factory, Queue receiveQueue, String aUser, String aPassword) throws JMSException {
		
if (null != aUser && null != aPassword) {
	log.info("creating receiver WITH authorisation credentials");
	conn = factory.createQueueConnection(aUser, aPassword);
}else{
	log.info("creating receiver without authorisation credentials");
	conn = factory.createQueueConnection();	
}
		
session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = session.createReceiver(receiveQueue);
log.debug("Receiver - ctor. Starting connection now");
conn.start();
log.info("Receiver - ctor. Connection to messaging system established");
}

public static synchronized Receiver createReceiver(QueueConnectionFactory factory, Queue receiveQueue, String aUser, String aPassword)
	throws JMSException {
// if (receiver == null) {
  Receiver receiver = new Receiver(factory, receiveQueue, aUser, aPassword);
  Thread thread = new Thread(receiver);
  thread.start();
// }
return receiver;
}

In short, I added the user name and password and logic to use it.

In the org.apache.jmeter.protocol.jms.sampler.JMSSampler class I made the following change in the method threadStarted()

if (!useTemporyQueue()) {
	receiveQueue = (Queue) context.lookup(getReceiveQueue());
	receiverThread = Receiver.createReceiver(factory, receiveQueue, getUser(context), getPassword(context));
}

This works for us here, we tested it this morning.
Comment 4 Sebb 2008-11-06 16:20:54 UTC
Thanks for the patches.

I've committed the changes to SVN:

URL: http://svn.apache.org/viewvc?rev=712018&view=rev
Log:
Bug 45458 - Point to Point JMS in combination with authentication

so the code will be in nightly builds after r712018.

Just in case the changes cause a problem, users can set the property:

JMSSampler.useSecurity.properties=false