經過一番調查,我找到了一個工作解決方案。我已經使用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();
成功打開後,您將能夠使用給定正確用戶名和密碼的安全羣集進行通信。