import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPAttributeSet;
import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPException;
import java.io.UnsupportedEncodingException;
public class AddEntry
{
public static void main( String[] args )
{
if (args.length != 4) {
System.err.println("Usage: java AddEntry <host name> <login dn>"
+ " <password> <container>");
System.err.println("Example: java AddEntry Acme.com"
+ " \"cn=admin,o=Acme\" secret \"ou=Sales,o=Acme\"");
System.exit(1);
}
int ldapPort = LDAPConnection.DEFAULT_PORT;
int ldapVersion = LDAPConnection.LDAP_V3;
String ldapHost = args[0];
String loginDN = args[1];
String password = args[2];
String containerName = args[3];
LDAPConnection lc = new LDAPConnection();
LDAPAttribute attribute = null;
LDAPAttributeSet attributeSet = new LDAPAttributeSet();
attributeSet.add( new LDAPAttribute(
"objectclass", new String("inetOrgPerson")));
attributeSet.add( new LDAPAttribute("cn",
new String[]{"James Smith", "Jim Smith", "Jimmy Smith"}));
attributeSet.add( new LDAPAttribute("givenname",
new String[]{"James", "Jim", "Jimmy" }));
attributeSet.add( new LDAPAttribute("sn", new String("Smith")));
attributeSet.add( new LDAPAttribute("telephonenumber",
new String("1 801 555 1212")));
attributeSet.add( new LDAPAttribute("mail",
new String("JSmith@Acme.com")));
attributeSet.add( new LDAPAttribute("userpassword",
new String("newpassword")));
String dn = "cn=JSmith," + containerName;
LDAPEntry newEntry = new LDAPEntry( dn, attributeSet );
try {
lc.connect( ldapHost, ldapPort );
lc.bind( ldapVersion, loginDN, password.getBytes("UTF8") );
lc.add( newEntry );
System.out.println( "\nAdded object: " + dn + " successfully." );
lc.disconnect();
}
catch( LDAPException e ) {
System.out.println( "Error: " + e.toString());
}
catch( UnsupportedEncodingException e ) {
System.out.println( "Error: " + e.toString() );
}
System.exit(0);
}
}