**だから、SASL/GSS API を介してこれを行う方法があると思います。インターネット上でこれの素晴らしい例がどこにも見られない理由について、私は混乱しています。ただし、他の人の助けになることを期待して、作成したものの例を投稿します...または、誰かがここで何か役立つことをするという私の妄想を修正できることを願っています.
サンプル サーバー コード:
TServerSocket serverTransport = new TServerSocket(7911); // new server on port 7911
HelloWorldService.Processor<Iface> processor = new HelloWorldService.Processer<Iface>(new ThriftServerImpl()); // This is my thrift implementation for my server
Map<String, String> saslProperties = new HashMap<String, String>(); // need a map for properties
saslProperties.put(Sasl.QOP, "true");
saslProperties.put(Sasl.QOP, "auth-conf"); // authorization and confidentiality
TSaslServerTransport.Factory saslTransportFactory = new TSaslServerTransport.Factory(); // Creating the server definition
saslTransportFactory.addServerDefinition(
"GSSAPI", // tell SASL to use GSSAPI, which supports Kerberos
"myserviceprincipal", // base kerberos principal name - myprincipal/my.server.com@MY.REALM
"my.server.com", // kerberos principal server - myprincipal/my.server.com@MY.REALM
saslProps, // Properties set, above
new SaslRpcServer.SaslGssCallbackHandler())); // I don't know what this really does... but I stole it from Hadoop and it works.. so there.
Tserver server = new TThreadPoolServer(newTThreadPoolSErver.Args(serverTransport).transportFactory(saslTrasnportFactory).processor(processor));
server.serve(); // Thrift server start
サンプル クライアント コード
TTransport transport = new TSocket("my.server.com", 7911); // client to connect to server and port
saslProperties.put(Sasl.QOP, "true");
saslProperties.put(Sasl.QOP, "auth-conf"); // authorization and confidentiality
TTransport saslTransport = new TSaslTransport(
"GSSAPI", // tell SASL to use GSSAPI, which supports Kerberos
null, // authorizationid - null
"myserviceprincipal", // base kerberos principal name - myprincipal/my.client.com@MY.REALM
"my.server.com", // kerberos principal server - myprincipal/my.server.com@MY.REALM
saslProps, // Properties set, above
null, // callback handler - null
transport); // underlying transport
TProtocol protocol = new TBinaryProtocol(saslTransport); // set up our new Thrift protocol
HelloWorldService.Client client = new HelloWorldService.Client(protocol); // Setup our thrift client
saslTransport.open();
String response = client.hello("Hi There"); // send message
System.out.println("response = " + response);
transport.close();
その他の考慮事項:
* クライアントとサーバーの両方でいくつかの Java プロパティを設定しました。
- java.security.krb5.realm = MY.REALM // レルム名
- java.security.krb5.kdc = my.kdc.com // kdc サーバー
- javax.security.auth.useSubjectCredsOnly = false // JAAS による取得を許可TGT。
- java.security.auth.login.config = /etc/myapp/conf/jaas.conf - 必要な jaas ファイル
- sun.security.krb5.debug = true // 問題の診断に役立ちます。
* 上記で指定した jaas.conf ファイルには、2 つのエントリが必要です (サーバーごとに 1 つだけかもしれません...)。この情報をどこから収集したか思い出せません..しかし、ここに私のファイルがあります:
com.sun.security.jgss.initiate {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
keyTab="/etc/myapp/conf/myapp.keytab"
useTicketCache=true
principal="myuserprincipal"
debug=true;
};
com.sun.security.jgss.accept {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
keyTab="/etc/myapp/conf/myapp.keytab"
useTicketCache=false
principal="myserviceprincipal/my.server.com"
debug=true;
};
(考慮事項に戻る....)
* 「auth-conf」の Sasl.QOP があるにもかかわらず.. 送信される最初の (?) メッセージは暗号化されていません。多分これはただの握手か何かです。残りのメッセージは暗号化されているように見えますが、この最初のメッセージは「ピアによって暗号化が実行されませんでした」という醜いメッセージをコンソールに出力します。そのメッセージを受信しないのは良いことです。なぜなら、それは将来の悲しみの原因となるからです (正当であろうとなかろうと)。
とにかく、これが誰かに役立つことを願っています...または、代わりに私を助けるいくつかの改善を引き起こすことができます. :) これを行うのに 2 ~ 3 日を費やしたことが信じられませんが、ほんの少量のコードしか得られませんでした。
読んでくれてありがとう。