import com.novell.ldap.*;
import java.io.UnsupportedEncodingException;
public class CompareAttrs
{
public static void main( String[] args )
{
if (args.length != 4) {
System.err.println("Usage: java CompareAttrs <host name> <login dn> "
+ "<password> <compare dn> ");
System.err.println("Example: java CompareAttrs Acme.com \"cn=Admin,"
+ "o=Acme\" secret\n \"cn=JSmith,ou=Sales,o=Acme\"");
System.exit(1);
}
int ldapPort = LDAPConnection.DEFAULT_PORT;
int ldapVersion = LDAPConnection.LDAP_V3;;
boolean compareResults = false;
String ldapHost = args[0];
String loginDN = args[1];
String password = args[2];
String dn = args[3];
LDAPConnection lc = new LDAPConnection();
LDAPAttribute attr = null;
try {
lc.connect( ldapHost, ldapPort );
lc.bind( ldapVersion, loginDN, password.getBytes("UTF8") );
attr =new LDAPAttribute( "objectclass", "inetOrgPerson" );
if ( compareResults = lc.compare(dn, attr))
System.out.println("\t" + (attr.getStringValues()).nextElement()
+ " is contained in the " + attr.getName() + " attribute." );
else
System.out.println("\t" + (attr.getStringValues()).nextElement()
+ " is not contained in the " + attr.getName() + " attribute." );
attr = new LDAPAttribute( "sn", "Bunny" );
if ( compareResults = lc.compare(dn, attr))
System.out.println("\t" + (attr.getStringValues()).nextElement()
+ " is contained in the " + attr.getName() + " attribute." );
else
System.out.println("\t" + (attr.getStringValues()).nextElement()
+ " is not contained in the " + attr.getName() + " attribute." );
lc.disconnect();
}
catch( LDAPException e ) {
System.out.println( "Error: " + e.toString() );
}
catch( UnsupportedEncodingException e ) {
System.out.println( "Error: " + e.toString() );
}
System.exit(0);
}
}