/** * Retrieves the entry with the specified DN. All user attributes will be * requested in the entry to return. * * @param dn The DN of the entry to retrieve. It must not be {@code null}. * * @return The requested entry, or {@code null} if the target entry does not * exist or no entry was returned (e.g., if the authenticated user * does not have permission to read the target entry). * * @throws LDAPException If a problem occurs while sending the request or * reading the response. */ public SearchResultEntry getEntry(final String dn) throws LDAPException { return getEntry(dn, (String[]) null); }
/** * Retrieves the entry with the specified DN. All user attributes will be * requested in the entry to return. * * @param dn The DN of the entry to retrieve. It must not be {@code null}. * * @return The requested entry, or {@code null} if the target entry does not * exist or no entry was returned (e.g., if the authenticated user * does not have permission to read the target entry). * * @throws LDAPException If a problem occurs while sending the request or * reading the response. */ public SearchResultEntry getEntry(final String dn) throws LDAPException { return getEntry(dn, (String[]) null); }
/** * Verify that an entry identified by {@code dn} exists. * * @param dn The distinguished name. * @return {@code true} if an entry identified by {@code dn} exists. Otherwise, {@code false} is returned. */ public boolean verifyDNExists(final String dn) { try { final SearchResultEntry entry = connection.getEntry(dn); return entry != null; } 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}. * * @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; }
@Override public void removeGroup(String groupName) throws LdapSystemException { try (LDAPConnection conn = ldapPool.getConnection()) { String groupDN = getGroupDN(groupName); SearchResultEntry entry = conn.getEntry(groupDN, GROUP_NAME_ATTR); if (entry != null) { conn.delete(groupDN); } } catch (LDAPException e) { throw new LdapSystemException(e); } }
/** * 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); } }
private void creatOrgUnits(LDAPConnection conn) throws LDAPException { String peopleDn = config.getLdapUserBaseDN(); if (conn.getEntry(peopleDn) == null) { Entry entry = new Entry(peopleDn); entry.addAttribute("objectClass", "top"); entry.addAttribute("objectClass", "organizationalUnit"); conn.add(entry); } String groupDn = config.getLdapGroupsBaseDN(); if (conn.getEntry(groupDn) == null) { Entry entry = new Entry(groupDn); entry.addAttribute("objectClass", "top"); entry.addAttribute("objectClass", "organizationalUnit"); conn.add(entry); } }
final Entry taskEntry = connection.getEntry(getTaskDN(taskID)); if (taskEntry == null)
/** * Schedules a new instance of the provided task in the Directory Server. * * @param task The task to be scheduled. * @param connection The connection to the Directory Server in which the * task is to be scheduled. * * @return A {@code Task} object representing the task that was scheduled and * re-read from the server. * * @throws LDAPException If a problem occurs while communicating with the * Directory Server, or if it rejects the task. * * @throws TaskException If the entry read back from the server after the * task was created could not be parsed as a task. */ public static Task scheduleTask(final Task task, final LDAPConnection connection) throws LDAPException, TaskException { final Entry taskEntry = task.createTaskEntry(); connection.add(task.createTaskEntry()); final Entry newTaskEntry = connection.getEntry(taskEntry.getDN()); if (newTaskEntry == null) { // This should never happen. throw new LDAPException(ResultCode.NO_SUCH_OBJECT); } return Task.decodeTask(newTaskEntry); }