2

我在我的代码中使用以下代码来启用 ldap 上的 tls。

import javax.naming.ldap.*;

 // Open an LDAP association
 LdapContext ctx = new InitialLdapContext();

 // Perform a StartTLS extended operation
 StartTlsResponse tls =
     (StartTlsResponse) ctx.extendedOperation(new StartTlsRequest());

 // Open a TLS connection (over the existing LDAP association) and get details
 // of the negotiated TLS session: cipher suite, peer certificate, ...
 SSLSession session = tls.negotiate();

 // ... use ctx to perform protected LDAP operations

 // Close the TLS connection (revert back to the underlying LDAP association)
 tls.close();

 // ... use ctx to perform unprotected LDAP operations

 // Close the LDAP association
 ctx.close;

我的问题是因为 StartTLSResponse 类是抽象类,它的协商和关闭方法是抽象的。我需要实现这个方法还是简单地使用上面的代码就可以了。

因为我从 http://docs.oracle.com/javase/7/docs/api/javax/naming/ldap/StartTlsResponse.html#close%28%29得到代码

4

1 回答 1

2

因为 StartTLSResponse 类是抽象类,它的方法如协商和关闭是抽象的。我需要实现这些方法吗

不,你会得到一个已经这样做的类的具体实例。

或者简单地使用上面的代码就可以了。

该代码有效。我昨天试过了。

于 2013-09-18T10:21:11.570 回答