2

我在运行 Windows Server 2003 的虚拟机上安装了 IBM 的 WebSphere MQ 版本 6 的服务器端,该虚拟机位于 Vista 桌面上。桌面已安装客户端。

我有一个小测试程序(来自他们的代码示例),它将消息放入队列并再次将其取出。该程序在直接使用服务器绑定在服务器上运行时有效。但是,我无法通过客户端绑定从客户端工作。

我得到的错误是 CompCode 2, Reason 2035,这是一个授权失败。

我怀疑这与程序默认在我的用户下运行的事实有关,该用户位于虚拟机不知道(并且无法访问)的域上。

我已经在我想连接的虚拟机上设置了一个本地用户(用户:websphere,密码:websphere),但我不清楚如何让这一切正常工作。我有我在下面使用的代码,并且我在通道和端点上尝试了各种安全出口设置组合,但我无法摆脱 2035。

有人有这方面的经验吗?帮助将不胜感激!

代码:

using System;
using System.Collections;

using IBM.WMQ;

class MQSample
{
    // The type of connection to use, this can be:-
    // MQC.TRANSPORT_MQSERIES_BINDINGS for a server connection.
    // MQC.TRANSPORT_MQSERIES_CLIENT for a non-XA client connection
    // MQC.TRANSPORT_MQSERIES_XACLIENT for an XA client connection
    // MQC.TRANSPORT_MQSERIES_MANAGED for a managed client connection
    const String connectionType = MQC.TRANSPORT_MQSERIES_CLIENT;

    // Define the name of the queue manager to use (applies to all connections)
    const String qManager = "QM_vm_win2003";

    // Define the name of your host connection (applies to client connections only)
    const String hostName = "vm-win2003";

    // Define the name of the channel to use (applies to client connections only)
    const String channel = "S_vm_win2003";

    /// <summary>
    /// Initialise the connection properties for the connection type requested
    /// </summary>
    /// <param name="connectionType">One of the MQC.TRANSPORT_MQSERIES_ values</param>
    static Hashtable init(String connectionType)
    {
        Hashtable connectionProperties = new Hashtable();

        // Add the connection type
        connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);

        // Set up the rest of the connection properties, based on the
        // connection type requested
        switch (connectionType)
        {
            case MQC.TRANSPORT_MQSERIES_BINDINGS:
                break;
            case MQC.TRANSPORT_MQSERIES_CLIENT:
                connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
                connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
                connectionProperties.Add(MQC.USER_ID_PROPERTY, "websphere");
                connectionProperties.Add(MQC.PASSWORD_PROPERTY, "websphere");
                break;
        }

        return connectionProperties;
    }

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static int Main(string[] args)
    {
        try
        {
            Hashtable connectionProperties = init(connectionType);

            // Create a connection to the queue manager using the connection
            // properties just defined
            MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);

            // Set up the options on the queue we wish to open
            int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;

            // Now specify the queue that we wish to open,and the open options
            MQQueue system_default_local_queue =
              qMgr.AccessQueue("clq_default_vm_sql2000", openOptions);

            // Define a WebSphere MQ message, writing some text in UTF format
            MQMessage hello_world = new MQMessage();
            hello_world.WriteUTF("Hello World!");

            // Specify the message options
            MQPutMessageOptions pmo = new MQPutMessageOptions(); 
            // accept the defaults,
            // same as MQPMO_DEFAULT

            // Put the message on the queue
            system_default_local_queue.Put(hello_world, pmo);

            // Get the message back again

            // First define a WebSphere MQ message buffer to receive the message
            MQMessage retrievedMessage = new MQMessage();
            retrievedMessage.MessageId = hello_world.MessageId;

            // Set the get message options
            MQGetMessageOptions gmo = new MQGetMessageOptions(); //accept the defaults
            //same as MQGMO_DEFAULT

            // Get the message off the queue
            system_default_local_queue.Get(retrievedMessage, gmo);

            // Prove we have the message by displaying the UTF message text
            String msgText = retrievedMessage.ReadUTF();
            Console.WriteLine("The message is: {0}", msgText);

            // Close the queue
            system_default_local_queue.Close();

            // Disconnect from the queue manager
            qMgr.Disconnect();
        }

        //If an error has occurred in the above,try to identify what went wrong.

        //Was it a WebSphere MQ error?
        catch (MQException ex)
        {
            Console.WriteLine("A WebSphere MQ error occurred: {0}", ex.ToString());
        }

        catch (System.Exception ex)
        {
            Console.WriteLine("A System error occurred: {0}", ex.ToString());
        }

        Console.ReadLine();
        return 0;
    }//end of start
}//end of sample
4

2 回答 2

2

对于 Windows 到 Windows 的连接,WMQ 将传递 SID 以及“短 ID”,在本例中为“websphere”。这比使用仅使用短 ID 的非 Windows WMQ 获得的授权要好一些。问题是非 Windows 服务器上的某个人可以使用短 ID“websphere”进行连接,并且由于没有 SID,WMQ 会像认为Windows 帐户一样接受连接。

解决这个问题的两种方法。在 QMgr 主机上,您可以运行 setmqaut 命令来授权您实际用于连接的 SID。VM必须能够查询 Windows 帐户所在的域,并且 setmqaut 命令必须使用 -p user@domain 语法。

或者,您可以在通道的 MCAUSER 中使用本地定义的 ID,例如

ALTER CHL(频道名称) CHLTYPE(SVRCONN) MCAUSER('webaphere@vm')

...其中 'vm' 是虚拟机的名称,并且您已使用 setmqaut 命令或将其放入 mqm 或管理员组来授权该帐户。

请记住,这用于测试!任何具有空白或管理 MCAUSER 的通道不仅可以管理 WMQ,还可以在底层主机服务器上执行任意命令。在现实世界中,您将创建可以访问队列和 QMgr 但不能访问管理的帐户,并将这些帐户放入所有 MCAUSER 值中,然后为所有 SYSTEM.DEF 和 SYSTEM.AUTO 通道设置 MCAUSER('nobody') .

在我的网站 t-rob.net 的 MQ 和链接页面上可以找到更多关于此的信息。另外,请查看:

评论行:T.Rob Wyatt:关于 WebSphere MQ 安全性你不知道的事

评论行:T.Rob Wyatt:WebSphere MQ 安全性升温

于 2009-11-19T15:05:00.070 回答
-1

我曾经有同样的问题。解决方案,我们需要将用户窗口帐户分配给MQA组或管理员组。然后,将window账户的用户名添加到频道中的MCA用户。

希望这可以帮助

于 2010-08-11T05:07:32.143 回答