Search code examples
javaldapopenldapopendjforgerock

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


I'm using opendj-ldap-sdk-2.6.0 jar library to search LDAP entry. I am following the guide. (https://backstage.forgerock.com/docs/opendj/2.6/dev-guide/#chap-using-the-sdk)

source code :

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 );

I'm getting a red line at this line under password because the parameter has to be 'char []'.
I captured Bind method in the below.

enter image description here

If my password is 1234, how can I change that into char [] type?


Solution

  • You're missing a call from factory to obtain a connection.

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