Put Msg with diferent user "User Indentifier"

Asked by Javier MT

Hi,
We are testing APIMQ Python, all goes well, but we want to put a MSG with different user (User Identifier) that is running Python, for example if running with "user123", i want to appear "userTest", both are in the group "mqm" and have full authority.
My sample are:

import pymqi
import CMQC
qmgr = pymqi.QueueManager(None)
qmgr.connectTCPClient('QMLNX', pymqi.cd(), 'CHANNEL', '127.0.0.1(1414)')
od = pymqi.od()
od.ObjectName = "QLOCAL1"

od.UserIdentifier = "userTest"

putq = pymqi.Queue(qmgr)
putq.open(od, CMQC.MQOO_OUTPUT | CMQC.MQOO_FAIL_IF_QUIESCING)
putq.put('Hello from Python/other USER ')
putq.close()
qmgr.disconnect()

the user that appears is that of "user123", trying... https://answers.launchpad.net/pymqi/+question/102012 but is the same

any help is appreciated,
Tnks Javier

Question information

Language:
English Edit question
Status:
Needs information
For:
PyMQI Edit question
Assignee:
Dariusz Suchojad Edit question
Last query:
Last reply:
Revision history for this message
webmario (w3bmario) said :
#1
Revision history for this message
Dariusz Suchojad (dsuch) said :
#2

Hi there Javier!

Could you please have a look at the example webmario linked to? The deal is that you need to set both open and put options, i.e. setting MQOO_SET_ALL_CONTEXT and MQPMO_SET_ALL_CONTEXT here along with an MD is the crucial thing.

webmario - cheers!

Revision history for this message
Javier MT (jmontenegro10) said :
#3

Hi dsuch,

Well, maybe I did not explain ( customer requirements LOL ), I need establishing the connection with the QM with another user, then applies (same for Q = 113081)

  qmgr.connectTCPClient ('QMLNX' pymqi.cd (), 'CHANNEL', '127 .0.0.1 (1414) ')

user that appears on the channel status (MCA User ID) is "user123" I need "userTest", so in Java sample program is very simple, only need to set

      MQEnvironment.userID = "userTest"; and it work

In my example Python ( modify with Q = 113081 ) the user is set when is the PUTMSG on the line
     queue.put(message, md, pmo)

Thanks in advance

JavierMT

Revision history for this message
Dariusz Suchojad (dsuch) said :
#4

> MQEnvironment.userID = "userTest"

Hmm.. I'm not sure how setting the MQEnvironment's userID works on Java end but it wouldn't be much surprised if it was using the MQOO_SET_ALL_CONTEXT and MQPMO_SET_ALL_CONTEXT attributes under the hood.

So if your question is whether there is a direct way for doing exactly the same as in Java, like if there's MQEnvironment in PyMQI, then the answer is that there isn't any such thing.

My question though is whether you've tried https://answers.launchpad.net/pymqi/+question/113081 and it's not working for you?

Cheers!

Revision history for this message
Javier MT (jmontenegro10) said :
#5

Ok,
I try the 113081 and 50% works for me, because the connection is always set to the user running the Python process, if the Python process run under user is configured in the group mqm works well... and the only change that is applied is :

     md.UserIdentifier = 'userTest'

if the process Python run with "user123" (not in mqm group) and tell to connect with "userTest" the result is

LNXT410:~$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymqi
>>> import CMQC
>>> mq_port = '1414'
>>> mq_host = '10.1.2.95'
>>> mq_manager = 'A104Z35M'
>>> mq_channel = 'CON.A104Z35M'
>>> mq_queue = 'SYSTEM.DEFAULT.LOCAL.QUEUE'
>>>
>>> message = 'Test message from Python'
>>> #message desriptor
... md = pymqi.md()
>>> md.MsgType = 8
>>> md.Persistence = 0
>>> md.Format = 'MQSTR'
>>> md.UserIdentifier = 'userTest'
>>>
>>> conn_info = "%s(%s)" % (mq_host, mq_port)
>>>
>>> cd = pymqi.cd()
>>> cd.UserIdentifier = 'userTest'
>>> cd.MCAUserIdentifier = 'userTest'
>>> cd.RemoteUserIdentifier = 'userTest'
>>> cd.MCASecurityId='userTestpw'
>>>
>>> qmgr = pymqi.QueueManager(None)
>>> qmgr.connectTCPClient(mq_manager, cd, mq_channel, conn_info)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pymqi.py", line 1245, in connectTCPClient
    self.connectWithOptions(name, cd)
  File "/usr/local/lib/python2.7/dist-packages/pymqi.py", line 1226, in connectWithOptions
    raise MQMIError(rv[1], rv[2])
pymqi.MQMIError: MQI Error. Comp: 2, Reason 2035: FAILED: MQRC_NOT_AUTHORIZED

the user "userTest" have Full Access, is in the mqm group and can do anything; If you look all variables relate to MCA & USER on the pymqi.cd() are placed.... but without result

any help is appreciated, Tnks

Revision history for this message
Dariusz Suchojad (dsuch) said :
#6

OK Javier,

I'll have a look at how Java implements the MQEnvironment.userID trick. I've never had to replicate it on Python side - or even use it in Java - so I'm not sure how to do it off the top of my head.

But just to be sure, can you please confirm that what's below is correct:

- there are two users, user123 and userTest
- user123 isn't part of the mqm group on the host the queue manager is running on
- userTest is part of the mqm group on the host the queue manager is running on
- Java processes run as the user123 yet setting the MQEnvironment.userID to userTest makes MQ happy

Is that correct?

Revision history for this message
Dariusz Suchojad (dsuch) said :
#7

Alright, here's some more information.

According to IBM's docs the value of MQEnvironment.userID goes straight to the MQCSP struct's Userid field. The deal is that:

- PyMQI doesn't support MQCSP yet
- MQCSP has no Userid field though it has the CSPUserIdPtr one which sounds similar

I'll work on adding the MQCSP to PyMQI now, let's see how it pans out. I'll keep you posted on the progress.

Revision history for this message
Javier MT (jmontenegro10) said :
#8

thanks for follow-up

>>>- there are two users, user123 and userTest = Yes
>>>- user123 isn't part of the mqm group on the host the queue manager is running on = Yes
>>>- userTest is part of the mqm group on the host the queue manager is running on = Yes
>>>- Java processes run as the user123 yet setting the MQEnvironment.userID to userTest makes MQ happy = Yes

Is that correct? Is that correct? yes

Tnks !

Revision history for this message
Dariusz Suchojad (dsuch) said :
#9

Hm hm hm.. so I've been working on it at https://code.launchpad.net/~dsuch/pymqi/mqcsp but then I read what RogerLacroix had to say about it http://www.mqseries.net/phpBB2/viewtopic.php?p=169793#169793 and I'm not that sure that it's the correct way to handle it.

Can we please meet on IRC tomorrow evening (Dec 7 2011) and discuss all the details? I would really like to understand what this Java app does. Let's say at 9 PM UTC?

The channel is #pymqi on Freenode network.

Revision history for this message
webmario (w3bmario) said :
#10

if it helps, I quote the following information from the MQ infocenter about MQEnvironment

"MQEnvironment contains static fields that control the environment in which an MQQueueManager object (and its corresponding connection to WebSphere® MQ) is constructed. As values set in MQEnvironment class take effect when the MQQueueManager constructor is called, you must set the values in the MQEnvironment class before you construct a MQQueueManager object."

http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/index.jsp?topic=%2Fcom.ibm.mq.csqzaw.doc%2Fuj12320_.htm

"The ID used to identify the WebSphere MQ client. It is equivalent to the WebSphere MQ environment variable MQ_USER_ID."

http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=%2Fcom.ibm.mq.javadoc.doc%2FWMQJavaClasses%2Fcom%2Fibm%2Fmq%2FMQEnvironment.html

Sample:

MQEnvironment.hostname = "localhost";
MQEnvironment.channel = "CH.TEST";
MQEnvironment.port = 1414;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES);
MQEnvironment.userID = "user1";

MQQueueManager qMgr = new MQQueueManager("QM01");
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue qName = qMgr.accessQueue("QTEST",openOptions, null, null,null);
MQMessage mqMsg = new MQMessage();
mqMsg.format = MQC.MQFMT_STRING;
mqMsg.writeString("MQ message");
MQPutMessageOptions pmo = new MQPutMessageOptions();
qName.put(mqMsg, pmo);
qName.close();
qMgr.disconnect();

Revision history for this message
Dariusz Suchojad (dsuch) said :
#11

That's certainly helpful webmario :-) I've somehow missed the part regarding MQ_USER_ID.

So Javier, could you please first try using this environment variable? Prior to our IRC session? Maybe it is some way to make it work without changing anything on PyMQI end.

Revision history for this message
Javier MT (jmontenegro10) said :
#12

hi DSuch,

setting the environment variable MQ_USER_ID to OS for user = 'userTest' and... without result ... same error 2035, and going beyond .... i try get the environment variable Python for verification ...

>>> print os.environ['MQ_USER_ID']
userTest

is well...

 ... setting for USER, USERNAME for change this environment variable

>>> os.environ['USER'] = 'userTest'
>>> print os.environ['USER']
userTest
>>> print os.environ['USERNAME']
userTest
>>> os.environ['USERNAME'] = 'userTest'
>>> print os.environ['USERNAME']
userTest

and after testing the same sample Python for MQ , same problem, 2035...

I'll try testing like RogerLacroix comments...I'll keep posted the progress.

Revision history for this message
Javier MT (jmontenegro10) said :
#13

Hi DSuch

We still have the same problem, trying & trying, but stell same problem with the user....

Currently you are working on the case ?

Really thanks for your collaboration on this problem

Kind regards

Javier

Revision history for this message
Dariusz Suchojad (dsuch) said :
#14

> Currently you are working on the case ?

Hm, you said you were going to try out Roger's suggestions so I haven't worked on it, no. But I will now and will keep you posted.

Cheers!

Revision history for this message
Dariusz Suchojad (dsuch) said :
#15

OK Javier,

I've just spent about 5 hours on decompiling and tracing various things and I still have no definite answer. Here's what I've dug up so far:

- There's no MQCSP involved at all when using the MQEnvironment.userID trick - I've confirmed it under the com.ibm.mq.commonservices trace. It seems as though Java was setting only MQCD's UserIdentifier and RemoteUserIdentifier fields yet doing the same in PyMQI doesn't make any difference.

- There's some method called 'authenticate' buried down there in com.ibm.mq.jmqi classes and it looks like if it's being called when MQEnvironment.userID is in use. This is where it gets unclear, I've no clue what it really does. Comparing the Java trace with the one produced by strmqtrc/dspmqtrc does indeed signal some sort of an authentication step being performed by MQ's own /build/p701_P/src/lib/exits/oam/amqzfubx.c

- The point above and the scarcity of any documentation on this subject make me wonder if the MQEnvironment.userID thing isn't some sort of a Java-specific hack that will hard to properly implement in PyMQI (which is C from MQ's standpoint).

That all said, I'd like you to open a PMR with IBM pointing them to this very comment I'm writing right now.

The question is - how a C application can simulate the steps performed by Java classes when a user sets MQEnvironment.userID to a non-null, non-empty value. I'd really like to see a C program doing these things.

Cheers!

Revision history for this message
Dariusz Suchojad (dsuch) said :
#16

Just for the future reference, another user asked about the very same thing and in PMR 47647,999,866 IBM answered that there is no way this can be done in C.

Hence, I'm sorry to say it, but it's not possible to do it in Python with PyMQI either.

To anyone interested in the feature - please contact IBM and say you need it, eventually it will be added.

Revision history for this message
Javier MT (jmontenegro10) said :
#17

Hi, first to all, wow, 1 year and months later and you tracking ! Exc ! Exc.

And, I will reference. Curious Case. Curious IBM that do not have this feature from the begin.

Tnks.

Can you help with this problem?

Provide an answer of your own, or ask Javier MT for more information if necessary.

To post a message you must log in.