使用 Websphere MQ 6 授权

2024-03-04

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

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

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

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

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

有人有这方面的经验吗?非常感谢您的帮助!

Code:

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

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

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

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

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

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

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

有关此内容的更多信息,请访问我的网站 t-rob.net 的 MQ 和链接页面。另外,请查看:

评论行:T.Rob Wyatt:关于 WebSphere MQ 安全性,您所不知道的事情 http://www.ibm.com/developerworks/websphere/techjournal/0701_col_wyatt/0701_col_wyatt.html

评论行:T.Rob Wyatt:WebSphere MQ 安全性升温 http://www.ibm.com/developerworks/websphere/techjournal/0711_col_wyatt/0711_col_wyatt.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Websphere MQ 6 授权 的相关文章

随机推荐