2.4 Compare Values - rukichen/GrailsGroovyLDAP GitHub Wiki

2.4.1 Comparing
There is a compare function implemented in the apache api. With connection.compare() you can compare Strings, Values or bytes[]. The other way to give the function a CompareRequest.

Simply define a Dn (String or Dn) , than give the name of the attribute you want to compare. The third is the value you want to be compared.

def dn = new Dn("cn=Charles Dickens,ou=Users,dc=example,dc=com")
if(connection.compare(dn, "telephoneNumber", "254-323-1920")){
    println "The Telephonenumber of " + dn.getRdn().getValue() + " is 254-323-1920"
}else{
    println "254-323-1920 is not the right number"
}

CompareRequest
For the request we use CompareRequestImpl() you set the Name, AttributeId and AssertionValue

def compareReq = new CompareRequestImpl()
compareReq.setName(dn)
compareReq.setAttributeId("uid")
compareReq.setAssertionValue("cdickens")

if(connection.compare(compareReq)){
    println "You found the right uid"
}else{
    println "The uid is wrong"
}