Compare Operation

Determines if an entry contains a specific attribute and value. An LDAP attribute may contain sensitive information which a client is not allowed to read, but is allowed to compare. Note that compare only uses a single attribute value, but the LdapAttribute object may contain more than one value. This implementation only uses the first value, all other values are ignored.

Compares the mail: dfisher@ldaptive.org attribute on the entry uid=dfisher,ou=people,dc=ldaptive,dc=org

Connection conn = DefaultConnectionFactory.getConnection("ldap://directory.ldaptive.org");
try {
  conn.open();
  CompareOperation compare = new CompareOperation(conn);
  boolean success = compare.execute(
    new CompareRequest(
    "uid=dfisher,ou=people,dc=ldaptive,dc=org", new LdapAttribute("mail", "dfisher@ldaptive.org"))).getResult();
  // do something useful with the result
} finally {
 conn.close();
}