2005-04-08 15:27:20
Adding the entries to the LDAP problem
Hello all,
I have a code that adds the entries to the LDAP directory server and this code is in JAVA
But this code does compile but when i run it it gives Runtime error as
::::: Invalid credentials::::::
The server is running when the code is run. for this do i need to specify certain schema in the .CONF file or anything else
The server I am using is OpenLDAP for Windows and Netscape directory SDK for JAVA
plz tell me about some another server available for LDAP support(free version) with JAVA (For Windows)
Plz tell me about the server and other information about LDAP Directory server so that i could find support for it easily
The code is as below::::::::::::::::::
import netscape.ldap.*;
import java.util.*;
public class Add {
public static void main( String[] args )
{
/* Specify the DN we're adding */
//String nickname = rock.nickname;
String dn = "uid=ac" ;
/* Specify the attributes of the entry */
String objectclass_values[] = { "top",
"person",
"organizationalPerson",
"inetOrgPerson" };
LDAPAttributeSet attrs = new LDAPAttributeSet();
LDAPAttribute attr = new LDAPAttribute( "objectclass" );
for( int i = 0; i < objectclass_values.length; i++ ) {
attr.addValue( objectclass_values[i] );
}
attrs.add( attr );
attrs.add( new LDAPAttribute( "uid", "wbjensen" ) );
/* Create an entry with this DN and these attributes */
LDAPEntry myEntry = new LDAPEntry( dn, attrs );
LDAPConnection ld = null;
int status = -1;
try {
ld = new LDAPConnection();
/* Connect to server */
String MY_HOST = "localhost";
int MY_PORT = 389;
ld.connect( MY_HOST, MY_PORT );
/* Authenticate to the server as directory manager */
String MGR_DN = "dc=monarch,dc=com";
String MGR_PW = "ali";
ld.authenticate( MGR_DN, MGR_PW );
System.out.println("Entry established");
/* Now add the entry to the directory */
ld.add( myEntry );
System.out.println( "Entry added" );
System.out.println("Entry established1111");
}
catch( LDAPException e ) {
if ( e.getLDAPResultCode() == LDAPException.ENTRY_ALREADY_EXISTS )
System.out.println( "Error: Entry already present" );
else
System.out.println( "Error: " + e.toString()+"AA che error" );
}
/* Done, so disconnect */
if ( (ld != null) && ld.isConnected() ) {
try {
ld.disconnect();
} catch ( LDAPException e ) {
System.out.println( "Error: " + e.toString() );
}
}
System.exit(status);
}
}