在ApacheDS 2.0.0中,有一些API发生了变化。下面是一些主要的变化:
DirectoryService
类的startup()
和shutdown()
方法,现在改为使用LdapServer
类的start()
和stop()
方法。// 以前的方式
DirectoryService service = new DefaultDirectoryService();
service.startup();
// do something
service.shutdown();
// 现在的方式
LdapServer server = new LdapServer();
server.start();
// do something
server.stop();
DirectoryService
类的getAdminSession()
方法已经被移除。现在可以使用LdapNetworkConnection
类的bind()
方法来获取管理员会话。// 以前的方式
DirectoryService service = new DefaultDirectoryService();
service.startup();
CoreSession adminSession = service.getAdminSession();
// do something
service.shutdown();
// 现在的方式
LdapServer server = new LdapServer();
server.start();
LdapConnection connection = new LdapNetworkConnection("localhost", 10389);
connection.bind("uid=admin,ou=system", "secret");
// do something
server.stop();
Entry
类的addAttributeValue()
方法已经被移除。现在可以使用Attribute
类的add()
方法来添加属性值。// 以前的方式
Entry entry = new DefaultEntry();
entry.addAttributeValue("cn", "John Doe");
entry.addAttributeValue("cn", "Jane Doe");
// 现在的方式
Entry entry = new DefaultEntry();
entry.addAttribute(new DefaultAttribute("cn", "John Doe", "Jane Doe"));
这些是ApacheDS 2.0.0中的一些API变化。注意,在使用新的API之前,请确保阅读官方文档以了解更多详情和最新的改动。