merveotesi
merveotesi

Reputation: 2193

Empty/Null Attribute Value

I have some objectClasses and dc and ou attributes and their values, in an entry in LDAP. I try to read ou attribute but i cant get it with below code. I can get dc value correctly. I know i must control if it is null, but why might "ou" be null despite of taking place in LDAP.

NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
           try
                {   
                    while (answer.hasMore())
                    {
                        SearchResult sr = (SearchResult) answer.next();
                        OrganizationPojo organizationPojo = new OrganizationPojo();
                        organizationPojo.setOrgDc((String)sr.getAttributes().get("dc").get());
                        organizationPojo.setOrgOu((String)sr.getAttributes().get("ou").get());

Upvotes: 0

Views: 1226

Answers (2)

merveotesi
merveotesi

Reputation: 2193

ctx = new InitialDirContext(env);
           String[] attrIDs = { "dc", "objectClass","ou" };

           SearchControls ctls = new SearchControls();
           ctls.setReturningAttributes(attrIDs);

           String filter = "(&(dc=*) (objectClass=organizationalUnit) (ou=*))";

           NamingEnumeration answer = ctx.search(dn, filter, ctls);

attrIds must contain "ou".

Upvotes: 0

jwilleke
jwilleke

Reputation: 11056

The dc value may not be available on an OU. Likewise the ou value may not be available on a DC.

-jim

Upvotes: 1

Related Questions