ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexIBM MQ API Supportcannot connect to MQ server when i try to impersonate a user

Post new topicReply to topic
cannot connect to MQ server when i try to impersonate a user View previous topic :: View next topic
Author Message
Madhura
PostPosted: Mon Sep 04, 2017 9:40 pm Post subject: cannot connect to MQ server when i try to impersonate a user Reply with quote

Newbie

Joined: 17 Aug 2017
Posts: 2

Hello All,

I am trying to connect to a IBM MQ queue manager using local user created on the system. this MQ queue server is in installed in a different machine but in same network. Server runs on a user called "admin" , i have created a local user with same credentials and trying to impersonate to connect. i can impersonate the user but not able to connect to the MQ server.

Now when I impersonate the user and try to connect I get below connection error. When I run visual studio as a different user (local user), it works but not when I use impersonation.

I am using Win server 2008 R2, IBM MQ client and Server versions are 8.0.0.6

Can anyone help with how to fix this issue?

code to connect IBM MQ Server :


using (new Tools.Impersonator("admin", "MNGNET384321d", "admin@1234"))
{
string userafter = WindowsIdentity.GetCurrent().Name;

MQQueueManager queueManager = null;

queueManager = new MQQueueManager(QueueManagerName, channelName, connectionName);

// queueManager = new MQQueueManager(QueueManagerName,props );


int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING;
queue = queueManager.AccessQueue(QueueName, openOptions);

int depth = queue.CurrentDepth;

queueMessage = new MQMessage();

queueMessage.Format = MQC.MQFMT_STRING;
queueGetMessageOptions = new MQGetMessageOptions();
queue.Get(queueMessage, queueGetMessageOptions);
strReturn =
queueMessage.ReadString(queueMessage.MessageLength);
queue.Close();


queueManager.Disconnect();
}



Impersonate code: I have added only main connection of impersonation

LogonUser(
userName,
domain,
password,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref token)


Error it throws -


System.TypeInitializationException was unhandled
HResult=-2146233036
Message=The type initializer for 'IBM.WMQ.MQQueueManager' threw an exception.
Source=amqmdnet
TypeName=IBM.WMQ.MQQueueManager
StackTrace:
at IBM.WMQ.MQQueueManager..ctor(String queueManagerName, String Channel, String ConnName)
at MQExample.MQTest.ConnectMQ(String strQueueManagerName, String strQueueName, String strChannelInfo) in D:\Adidas\MQExample\MQExample\MQExample\MQTest.cs:line 83
at MQExample.Form1.button1_Click(Object sender, EventArgs e) in D:\Adidas\MQExample\MQExample\MQExample\Form1.cs:line 33
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at MQExample.Program.Main() in D:\Adidas\MQExample\MQExample\MQExample\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
HResult=-2146232828
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at IBM.WMQ.CommonServices.CreateCommonServices()
at IBM.WMQ.CommonServices.TraceConstructor(String objectId, String sccsid)
at IBM.WMQ.Nmqi.NmqiEnvironment..ctor(NmqiPropertyHandler nmqiPropertyHandler)
at IBM.WMQ.Nmqi.NmqiFactory.GetInstance(NmqiPropertyHandler properties)
at IBM.WMQ.MQQueueManager..cctor()
InnerException:
HResult=-2146232828
Message=Exception has been thrown by the target of an invocation.
Source=amqmdnet
StackTrace:
at IBM.WMQ.MQCommonServices..ctor()
InnerException:
HResult=-2146233088
Message=Failed to load mqe.dll from folder C:\Program Files\IBM\WebSphere MQ\bin\
Source=amqmdnet
StackTrace:
at IBM.WMQ.Nmqi.NativeManager.InitializeNativeApis(String mode)
InnerException:
Back to top
View user's profile Send private message
zpat
PostPosted: Mon Sep 04, 2017 11:07 pm Post subject: Reply with quote

Jedi Council

Joined: 19 May 2001
Posts: 5576
Location: UK

I was under the impression that the MQ client (in more recent versions at least) overrode the connection id to make it the windows process id.

Also why are you opening a queue for both input and output? I can't think of a good reason for doing that.
_________________
Well, I don't think there is any question about it. It can only be attributable to human error. This sort of thing has cropped up before, and it has always been due to human error.
Back to top
View user's profile Send private message
Madhura
PostPosted: Tue Sep 05, 2017 12:53 am Post subject: Reply with quote

Newbie

Joined: 17 Aug 2017
Posts: 2

zpat wrote:
I was under the impression that the MQ client (in more recent versions at least) overrode the connection id to make it the windows process id.

Also why are you opening a queue for both input and output? I can't think of a good reason for doing that.



I cannot use connection user id to override because user has no password. Server MQ runs on the username which has no password

I am opening the queue over only here.

queueManager = new MQQueueManager(QueueManagerName, channelName, connectionName);
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Tue Sep 05, 2017 12:16 pm Post subject: Re: cannot connect to MQ server when i try to impersonate a Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3021
Location: London, ON Canada

Madhura wrote:
Message=Failed to load mqe.dll from folder C:\Program Files\IBM\WebSphere MQ\bin\

You need to set the MQ environment that the application is using. Use the setmqenv command.

Madhura wrote:
Code:
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING;
queue = queueManager.AccessQueue(QueueName, openOptions);

As zpat asked, why are you opening the queue for BOTH input and output? Your code is getting messages, so there is not point to the 'MQC.MQOO_OUTPUT' option.

Madhura wrote:
I am opening the queue over only here.
Code:
queueManager = new MQQueueManager(QueueManagerName, channelName, connectionName);

Oh boy, you don't know the difference between connecting to a queue manager and opening a queue?

I would strongly suggest you attend MQ Technical Conference later this month. There is an 'MQ Beginnings' track for people in your situation.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ API Supportcannot connect to MQ server when i try to impersonate a user
Jump to:



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.