java take out cn from dn 1

java take out cn from dn

String dn = "CN=Jimmy Blooptoop,OU=Someplace,OU=Employees,DC=Bloopsoft-Inc";
LdapName ln = new LdapName(dn);

for(Rdn rdn : ln.getRdns()) {
    if(rdn.getType().equalsIgnoreCase("CN")) {
        System.err.println("CN is: " + rdn.getValue());
        break;
    }
}

Here is what the above code is Doing:
1. Create a new LdapName object from the DN string.
2. Loop through the Rdn objects in the LdapName object.
3. If the Rdn type is “CN”, print the value.

The output of the above code is:
CN is: Jimmy Blooptoop

Similar Posts