** 그래서 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/[email protected]
"my.server.com", // kerberos principal server - myprincipal/[email protected]
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/[email protected]
"my.server.com", // kerberos principal server - myprincipal/[email protected]
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();
다른 condsiderations : 나는 클라이언트와 서버 모두에 대한 몇 가지 자바 속성을 설정 *
.
-인가, java.security.krb5.realm = MY.REALM // 영역 이름
- java.security.krb5.kdc의 = my.kdc.com // KDC 서버
- javax.security.auth.useSubjectCredsOnly를 = 거짓 // JAAS가 TGT를 얻도록 허용.
- java.security.auth.login.config = /etc/myapp/conf/jaas.conf - 필수 jaas 파일
- sun.security.krb5.debug = true // 문제 진단에 도움이됩니다.
* 위에서 지정한 jaas.conf 파일에는 두 개의 항목이 있어야합니다 (서버 당 하나만 가능할 수도 있음). 내가 여기에 내가이 정보를 수집 위치를 기억 ..하지만 할 수없는 것은 내 파일입니다
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;
};
(고려 다시 ....)
* "인증-의 conf"의 Sasl.QOP가 있더라도 .. 전송 된 첫 번째 (?) 메시지는 암호화되지 않습니다. 어쩌면 이것은 단지 악수 일뿐일 수도 있습니다. 나머지 메시지는 암호화 된 것처럼 보이지만 처음에는 "피어에 의해 암호화가 수행되지 않았습니다"라는 콘솔에 추악한 메시지가 인쇄됩니다. 그 메시지를 듣지 않는 것이 좋을 것입니다. 그 메시지가 도로 아래로 슬픔을 불러 일으킬 것입니다.
어쨌든, 이것이 도움이 되었기를 바랍니다 ... 또는 대안으로 나를 도울 수있는 몇 가지 개선 사항을 유발할 수 있습니다. :)이 일을 2 ~ 3 일 동안 보내고 있다고 믿기 어려워요. 코드를 조금 밖에 만들지 못했지만 시작했을 때 Kerberos 나 Thrift를 잘 알지 못했습니다.
읽어 주셔서 감사합니다.
Hadoop이 (가)이 작업을 수행 한 것처럼 보입니다. – Wanderer