View Single Post
Old 04-08-2005, 11:35 AM   #1 (permalink)
j.gohel
Code Monkey
 
Join Date: Apr 2005
Posts: 68
j.gohel is on a distinguished road
how the servlet will integrate the LDAP code

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
How to integate this code into the servlet????

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::::::::::::::::::





Code:
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); } }
Regards
Jignesh
__________________
j.gohel is offline   Reply With Quote