Hi guys!

I have been trying to add an entry via java without success...
The message I get is: strongAuthRequired - 8
Using Apache Directory Studio with the same credentials I can
add/remove/change and entry.

I have attached a picture with my connection information in Apache
Directory Studio.
and my Java code.

Thanks is advance
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.ldap.connection;

import java.io.IOException;
import java.util.Iterator;
import org.apache.directory.api.ldap.model.cursor.EntryCursor;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.message.AddRequest;
import org.apache.directory.api.ldap.model.message.AddRequestImpl;
import org.apache.directory.api.ldap.model.message.AddResponse;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.message.SearchScope;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapConnectionConfig;
import org.apache.directory.ldap.client.api.LdapNetworkConnection;

/**
 *
 * @author fmattos
 */
public class SandBox {

    private static LdapConnection conn = null;

    public static void main(String[] args) {

        try {

            SandBox sandBox = new SandBox();
            sandBox.initConnection();
            
            
            Entry entry = new DefaultEntry("ou=customer_service,ou=employees,dc=mycompany,dc=com",
                                           "objectClass: inetOrgPerson",
                                           "objectClass: organizationalPerson",
                                           "objectClass: person",
                                           "objectClass: top",
                                           "cn: Test Api-T",
                                           "sn: Api-T",
                                           "givenName: Test",
                                           "uid: tapit",
                                           "mail: [email protected]",
                                           "userPassword: password");
                    
            sandBox.addEntry(entry);
            
            //sandBox.search();
            
        } catch (LdapException le) {
            le.printStackTrace(System.out);
        } catch (IOException ioe) {
            ioe.printStackTrace(System.out);
        } finally {

            if (conn != null) {
                try {
                    conn.close();
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                }

            }
        }
    }

    public static void initConnection() throws LdapException, IOException {

        if (conn == null) {
            LdapConnectionConfig connectionConfig = new LdapConnectionConfig();
            connectionConfig.setLdapHost("myip");
            connectionConfig.setLdapPort(389);
            connectionConfig.setName("cn=Manager,dc=mycompany,dc=com");
            connectionConfig.setCredentials("mypass");
            conn = new LdapNetworkConnection(connectionConfig);
            conn.connect();
        }

    }

    public void search() throws LdapException {

        if (conn != null && conn.isConnected()) {

            EntryCursor cursor = conn.search("ou=employees,dc=mycompany,dc=com", "(objectclass=*)", SearchScope.SUBTREE);
            Iterator<Entry> it = cursor.iterator();
            while (it.hasNext()) {
                Entry entry = it.next();
                System.out.println(entry);
            }
        }
    }
    
    
    public void addEntry(Entry entry) throws LdapException{
        
        AddRequest addRequest = new AddRequestImpl();
        addRequest.setEntry(entry);
        
        AddResponse response = conn.add( addRequest );
        if(ResultCodeEnum.SUCCESS.equals(response.getLdapResult().getResultCode())){
            System.out.println("Success!!");
        }else{
            System.out.println(response.getLdapResult().getResultCode().getMessage() +" - "+ response.getLdapResult().getResultCode().getValue());
        }
        
        
      
    }

}

Reply via email to