gpt4 book ai didi

java - (opendj-ldap-sdk-2.6.0) 绑定(bind)方法参数-密码字符[ ]

转载 作者:行者123 更新时间:2023-12-02 10:27:00 25 4
gpt4 key购买 nike

我正在使用 opendj-ldap-sdk-2.6.0 jar 库来搜索 LDAP 条目。我正在按照指南进行操作。(https://backstage.forgerock.com/docs/opendj/2.6/dev-guide/#chap-using-the-sdk)

源代码:

import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.LDAPConnectionFactory;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.ldap.responses.SearchResultReference;
import org.forgerock.opendj.ldif.ConnectionEntryReader;
import org.forgerock.opendj.ldif.LDIFEntryWriter;

public class Test {

public static void main(String[] args) {

final LDIFEntryWriter writer = new LDIFEntryWriter(System.out);
Connection connection = null;

try {
final LDAPConnectionFactory factory = new LDAPConnectionFactory("localhost",389);

connection = factory.getConnection();
connection.bind("cn = Directory Mangager", password );
// password is just an example of the password.

final ConnectionEntryReader reader = connection.search("dc=example,dc=com", SearchScope.WHOLE_SUBTREE,"(uid=bjensen)","*");
while (reader.hasNext()) {
if(reader.isEntry()) {
final SearchResultEntry entry = reader.readEntry();
writer.writeComment("Search result entry:" + entry.getName().toString());
writer.writeEntry(entry);
} else {
final SearchResultReference ref = reader.readReference();
writer.writeComment("Search result reference:" + ref.getURIs().toString());
}
}
writer.flush();
} catch (final Exception e) {
System.err.println(e.getMessage());
} finally {
if (connection !=null) {
connection.close();
}
}
}

connection.bind("cn = Directory Mangager", password );

我在密码下的这一行看到一条红线,因为参数必须是“char []”。
我在下面捕获了 Bind 方法。

enter image description here

如果我的密码是1234,如何将其更改为char[]类型?

最佳答案

您错过了来自工厂的获取连接的调用。

  connection = factory.getConnection();
connection.bind("cn = Directory Mangager", password );

关于java - (opendj-ldap-sdk-2.6.0) 绑定(bind)方法参数-密码字符[ ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53880689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com