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

(opendj-ldap-sdk-2.6.0) bind method parameter - password char [ ]

我正在使用 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 方法。

如果我的密码是1234,怎么改成char[]类型?

您错过了来自工厂的电话以获取连接。

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

我明白了。

connection.bind("cn=Directory Manager", "yourpassword".toCharArray() );

您可以使用 toCharArray()

另外,正如上面Ludovic Poitou所说,你需要使用
connection = factory.getConnection(); 使用 bind 方法。 该指南说如果您不使用匿名搜索,请使用 bind 方法,但您必须同时使用它们。 (我误解了指南)