经过一番调查,我找到了一个工作解决方案。我已经使用cyrus-sasl项目以及来自Apache THRIFT的补丁。
首先创建TTransport,并在安全集群中运行配置单元服务。
boost::shared_ptr<TTransport> socket(new TSocket("hive_host", hive_port));
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
创建回调数组从客户端& 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();
成功打开后,您将能够使用给定正确用户名和密码的安全群集进行通信。