Long Zhang
Long Zhang

Reputation: 51

How to pass authentication info when using Messsage Service Client for .net to connect to IBM WMQ

We are developing a console application using c# to access IBM WMQ. We are using IBM Message Service Client for .net (XMS) and WebSphere MQ Client. Here are the code example:

            XMSFactoryFactory xff = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
            IConnectionFactory cf = xff.CreateConnectionFactory();
            cf.SetStringProperty(XMSC.WMQ_HOST_NAME, "host");
            cf.SetIntProperty(XMSC.WMQ_PORT, 1445);
            cf.SetStringProperty(XMSC.WMQ_CHANNEL, "channel");
            cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
            cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "queueManager");
            cf.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);
            cf.SetStringProperty(XMSC.USERID, @"userid");
            cf.SetStringProperty(XMSC.PASSWORD, @"");

            IConnection conn = cf.CreateConnection();
            conn.ExceptionListener = new ExceptionListener(OnXMSExceptionReceived);
            Console.WriteLine("connection created");
            ISession sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge);

We kept getting the following error: CWSMQ0044E: The user is not authorized to connect to the queue manager. The application has tried to connect to a queue manager without authorization. Ensure th at appropriate authority exists on the queue manager for this user.

But we have no problem to access the same MQ using spring integration. here is the settings for spring integration:

<bean id="connectionFactoryWBI" class="com.ibm.mq.jms.MQQueueConnectionFactory">
    <property name="hostName" value="${hostName}" />
    <property name="port" value="${port}" />
    <property name="queueManager" value="${queueManager}" />
    <property name="channel" value="${channel}" />
    <property name="transportType" value="1" />
</bean>

<bean id="connectionFactoryWBIWithCredentials" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
    <property name="targetConnectionFactory" ref="connectionFactoryWBI" />
    <property name="username" value="${username}" />
</bean>

I am new to XMS and .net, do not know how to pass the authentication info for connecting to MQ. any recommendations are highly welcome!

Upvotes: 3

Views: 4122

Answers (1)

Shashi
Shashi

Reputation: 15273

XMS .NET and MQ JMS clients work little different. When connecting to queue manager, XMS .NET first sends the currently logged in Windows user id and then sends the application specified user id. If these two user ids are same, then connection is created. But if they are different then you will get CWSMQ0044E error. This is basically MQ Reason code 2035, MQRC_NOT_AUTHORIZED. However in case of MQ JMS, only the application specified user id is sent, Windows user id is not sent. Hence you don't see the error.

There are number of ways to address the issue you are seeing when using XMS .NET:
1) Use a MQ Server side Security Exit.
2) Channel Authentication Records (Available from MQ v7.1 onwards)

This issue has been discussed here.

Upvotes: 3

Related Questions