/** * Verify that the entry identified by {@code dn} has an attribute named {@code attributeName}. * * @param dn The distinguished name. * @param attributeName The attribute name. * @return {@code true} if an entry identified by {@code dn} exists and has an attributed named * {@code attributeName}. Otherwise, {@code false} is returned. */ public boolean verifyDNHasAttribute(final String dn, final String attributeName) { try { final SearchResultEntry entry = connection.getEntry(dn, attributeName); return entry != null && entry.hasAttribute(attributeName); } catch (final LDAPException e) { throw new DirectoryTesterException("Error communicating with LDAP directory server", e); } }
/** * Verify that the entry identified by {@code dn} has an attribute named {@code attributeName} with * the attribute value(s) {@code attributeName}. * * @param dn The distinguished name. * @param attributeName The attribute name. * @param attributeValue The attribute value(s). * @return {@code true} if an antry identified by {@code dn} exists with an an attribute named {@code attributeName} * that has value(s) {@code attributeValue}. Otherwise, {@code false} is returned. */ public boolean verifyDNHasAttributeValue(final String dn, final String attributeName, final String... attributeValue) { try { final SearchResultEntry entry = connection.getEntry(dn, attributeName); if (entry != null && entry.hasAttribute(attributeName)) { final Set<String> expectedValues = new HashSet<String>(Arrays.asList(attributeValue)); final Set<String> actualValues = new HashSet<String>(Arrays.asList(entry.getAttributeValues(attributeName))); if (actualValues.containsAll(expectedValues)) { actualValues.removeAll(expectedValues); if (actualValues.size() == 0) { return true; } } } } catch (final LDAPException e) { throw new DirectoryTesterException("Error communicating with LDAP directory server", e); } return false; }
/** * Verify that the entry identified by {@code dn} is of type {@code objectclass}. * * @param dn The distinguished name. * @param objectclass The type name. * @return {@code true} if an entry identified by {@code dn} exists and has attribute named {@code objectclass}. * Otherwise, {@code false} is returned. */ public boolean verifyDNIsA(final String dn, final String objectclass) { try { final SearchResultEntry entry = connection.getEntry(dn, "objectclass"); return entry != null && entry.hasAttribute("objectclass") && arrayContains(entry.getAttributeValues("objectclass"), objectclass); } catch (final LDAPException e) { throw new DirectoryTesterException("Error communicating with LDAP directory server", e); } }