1

所以我在 bluemix 上有一个安全网关。安全网关正在连接到我本地的 LDAP 服务。在安全网关中,我配置了双向 TLS。

现在,我正在使用 React\socket-client 进行连接,并且连接成功。我刚刚迷失了如何在 LDAP 中查询数据。总是无法连接到 LDAP 服务器。

$loop = React\EventLoop\Factory::create();
$tcpConnector = new React\SocketClient\TcpConnector($loop);
$dnsResolverFactory = new React\Dns\Resolver\Factory();
$dns = $dnsResolverFactory->createCached('8.8.8.8', $loop);

$dnsConnector = new React\SocketClient\DnsConnector($tcpConnector, $dns);
$secureConnector = new React\SocketClient\SecureConnector($dnsConnector, $loop, array(
    'verify_peer' => true,
    'verify_peer_name' => true,
    'allow_self_signed' => true,
    'cafile' => <CACERT>,
    'local_pk' => <PK_CERT>,
    'local_cert' => <LOCALCERT>
));

$secureConnector->create(<Secure Gateway Link>)->then(function(React\Stream\Stream $stream)
{
 //I'M CONNECTED HERE
//Secure gateway status is establishing connection and not closing
    $ldap_server = "ldap://0.0.0.0";
    $basedn = "<xxx>";
    $auth_user = "<xxx>";
    $auth_pass = "<xxx>";

    if (!($connect = @ldap_connect($ldap_server)))
    {
        throw new Exception("Cannot connect to LDAP");
    } else
    {
        try
        {
            //In order to avoid unable bind to server
            ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
            $bind = ldap_bind($connect, $auth_user, $auth_pass);

            if (!$bind)
            {
                if (ldap_get_option($connect, LDAP_OPT_DIAGNOSTIC_MESSAGE, $extended_error))
                {
                    throw new Exception("Error Binding to LDAP: $extended_error");;
                } else
                {
                    throw new Exception("Error Binding to LDAP: No additional information is available.");
                }

            } else
            {
                //connected to LDAP and do search
               //never goes here
            }
        } catch (Exception $exc)
        {
            $exc->getMessage();
            $stream->end();
        }
    }

}, function($err)
{
    echo $err . '<br>';
    die();
});

$loop->run();

我正在将https://developer.ibm.com/bluemix/2015/04/17/securing-destinations-tls-bluemix-secure-gateway/上的 nodejs 代码翻译 成这个代码......如果我可以使用另一个数据包我必须,我只是不知道该用什么。请帮我..

提前致谢

4

0 回答 0