带有 username/password C++ 身份验证的 Thrift sasl

Thrift sasl with username/password authentication for C++

我一直在尝试为我使用 Apache Thrift 的项目增加安全性。在 C# 中,有一个 class TSASLClientTransport 接受参数 TSocket、用户名和密码。同样,我需要一个 cpp class 以便我可以在 C++ 中实现相同的功能。

我遇到了这个任务 https://issues.apache.org/jira/browse/THRIFT-1667,它仍处于打开状态。不过,此任务中有可用的补丁。使用此补丁程序,我导入了 TsaslTransport class,但我找不到在此处提供 username/password 的方法。如果可能的话,任何人都可以分享这方面的任何例子。

或者有没有一种方法可以使用 C++ 在 thrift 中提供简单的 username/password 身份验证?

这里可以用Cyrus-SASL吗?

非常感谢任何帮助。

经过一些调查,我找到了一个可行的解决方案。我用过cyrus-sasl project along with the patch from Apache THRIFT

首先在安全集群中创建一个带有 Hive 服务的 TTransport 运行。

boost::shared_ptr<TTransport> socket(new TSocket("hive_host", hive_port));
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));

创建回调数组以从客户端中的 &simple 获取用户名和从 &getsecret 获取密码。

  static sasl_callback_t callbacks[] ={
           {
            SASL_CB_USER, (sasl_callback_ft)&simple, NULL 
           }, {
            SASL_CB_AUTHNAME, (sasl_callback_ft)&simple, NULL 
           }, {
            SASL_CB_PASS, (sasl_callback_ft)&getsecret, NULL
           }, {
            SASL_CB_LIST_END, NULL, NULL
           }
};

使用 saslimpl.cpp 中的 libSaslClient 选择机制和服务。这将初始化客户端。并在 TSASLTransport 中使用此客户端打开连接并与服务器通信。

map<string, string> props; 
sasl::libSaslClient libSaslClient("PLAIN", "", "ldap", "host", props, callbacks);
boost::shared_ptr<TSaslTransport> tsaslTransport(new TSaslTransport(&libSaslClient, transport));
tsaslTransport->open();
tsaslTransport->close();

成功打开后,您将能够与具有正确用户名和密码的安全集群进行通信。