/** * Processes the provided modify request. * * @param modifyRequest The modify request to be processed. It must not be * {@code null}. * * @return The result of processing the modify operation. * * @throws LDAPException If the server rejects the modify request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult modify(final ReadOnlyModifyRequest modifyRequest) throws LDAPException { return modify((ModifyRequest) modifyRequest); }
/** * Processes the provided modify request. * * @param modifyRequest The modify request to be processed. It must not be * {@code null}. * * @return The result of processing the modify operation. * * @throws LDAPException If the server rejects the modify request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult modify(final ReadOnlyModifyRequest modifyRequest) throws LDAPException { return modify((ModifyRequest) modifyRequest); }
@Override protected LDAPResult run() throws Exception { return getConnection().modify(dn, mods); } }
/** * Applies the provided set of modifications to the specified entry. * * @param dn The DN of the entry to modify. It must not be {@code null}. * @param mods The set of modifications to apply to the target entry. It * must not be {@code null} or empty. * * @return The result of processing the modify operation. * * @throws LDAPException If the server rejects the modify request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult modify(final String dn, final Modification... mods) throws LDAPException { ensureNotNull(dn, mods); return modify(new ModifyRequest(dn, mods)); }
/** * Applies the provided set of modifications to the specified entry. * * @param dn The DN of the entry to modify. It must not be {@code null}. * @param mods The set of modifications to apply to the target entry. It * must not be {@code null} or empty. * * @return The result of processing the modify operation. * * @throws LDAPException If the server rejects the modify request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult modify(final String dn, final Modification... mods) throws LDAPException { ensureNotNull(dn, mods); return modify(new ModifyRequest(dn, mods)); }
/** * Applies the provided modification to the specified entry. * * @param dn The DN of the entry to modify. It must not be {@code null}. * @param mod The modification to apply to the target entry. It must not * be {@code null}. * * @return The result of processing the modify operation. * * @throws LDAPException If the server rejects the modify request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult modify(final String dn, final Modification mod) throws LDAPException { ensureNotNull(dn, mod); return modify(new ModifyRequest(dn, mod)); }
/** * Applies the provided set of modifications to the specified entry. * * @param dn The DN of the entry to modify. It must not be {@code null}. * @param mods The set of modifications to apply to the target entry. It * must not be {@code null} or empty. * * @return The result of processing the modify operation. * * @throws LDAPException If the server rejects the modify request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult modify(final String dn, final List<Modification> mods) throws LDAPException { ensureNotNull(dn, mods); return modify(new ModifyRequest(dn, mods)); }
/** * Applies the provided modification to the specified entry. * * @param dn The DN of the entry to modify. It must not be {@code null}. * @param mod The modification to apply to the target entry. It must not * be {@code null}. * * @return The result of processing the modify operation. * * @throws LDAPException If the server rejects the modify request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult modify(final String dn, final Modification mod) throws LDAPException { ensureNotNull(dn, mod); return modify(new ModifyRequest(dn, mod)); }
/** * Applies the provided set of modifications to the specified entry. * * @param dn The DN of the entry to modify. It must not be {@code null}. * @param mods The set of modifications to apply to the target entry. It * must not be {@code null} or empty. * * @return The result of processing the modify operation. * * @throws LDAPException If the server rejects the modify request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult modify(final String dn, final List<Modification> mods) throws LDAPException { ensureNotNull(dn, mods); return modify(new ModifyRequest(dn, mods)); }
/** * Processes a modify request from the provided LDIF representation of the * changes. * * @param ldifModificationLines The lines that comprise an LDIF * representation of a modify change record. * It must not be {@code null} or empty. * * @return The result of processing the modify operation. * * @throws LDIFException If the provided set of lines cannot be parsed as an * LDIF modify change record. * * @throws LDAPException If the server rejects the modify request, or if a * problem is encountered while sending the request or * reading the response. * */ public LDAPResult modify(final String... ldifModificationLines) throws LDIFException, LDAPException { ensureNotNull(ldifModificationLines); return modify(new ModifyRequest(ldifModificationLines)); }
/** * Processes a modify request from the provided LDIF representation of the * changes. * * @param ldifModificationLines The lines that comprise an LDIF * representation of a modify change record. * It must not be {@code null} or empty. * * @return The result of processing the modify operation. * * @throws LDIFException If the provided set of lines cannot be parsed as an * LDIF modify change record. * * @throws LDAPException If the server rejects the modify request, or if a * problem is encountered while sending the request or * reading the response. * */ public LDAPResult modify(final String... ldifModificationLines) throws LDIFException, LDAPException { ensureNotNull(ldifModificationLines); return modify(new ModifyRequest(ldifModificationLines)); }
/** * Submits a request to cancel the task with the specified task ID. Note that * some tasks may not support being canceled. Further, for tasks that do * support being canceled it may take time for the cancel request to be * processed and for the task to actually be canceled. * * @param taskID The task ID of the task to be canceled. * @param connection The connection to the Directory Server in which to * perform the operation. * * @throws LDAPException If a problem occurs while communicating with the * Directory Server. */ public static void cancelTask(final String taskID, final LDAPConnection connection) throws LDAPException { // Note: we should use the CANCELED_BEFORE_STARTING state when we want to // cancel a task regardless of whether it's pending or running. If the // task is running, the server will convert it to STOPPED_BY_ADMINISTRATOR. final Modification mod = new Modification(ModificationType.REPLACE, Task.ATTR_TASK_STATE, TaskState.CANCELED_BEFORE_STARTING.getName()); connection.modify(getTaskDN(taskID), mod); }
@Override public void updateAccount(LdapAccount account) throws LdapSystemException { try (LDAPConnection conn = ldapPool.getConnection()) { String entryDN = getAccountDN(account.getSubject()); List<Modification> mods = new ArrayList<>(); if (account.getPassword() != null) { mods.add(new Modification(REPLACE, "userPassword", account.getPassword())); } mods.add(new Modification(REPLACE, "givenName", account.getGivenName())); mods.add(new Modification(REPLACE, "sn", account.getFamilyName())); mods.add(new Modification(REPLACE, "cn", account.getName())); mods.add(new Modification(REPLACE, "mail", account.getEmails().toArray(new String[0]))); conn.modify(new ModifyRequest(entryDN, mods)); } catch (LDAPException e) { throw new LdapSystemException(e); } }
@Override public void removeGroupMember(String accountDN, String groupName) throws LdapSystemException { try (LDAPConnection conn = ldapPool.getConnection()) { LdapGroup group = getGroup(groupName, conn); if (group == null || !group.getMembersDn().contains(accountDN)) { log.info("Nothing to do. Account {} is not member of group {}", accountDN, groupName); } else { Modification mod = new Modification(DELETE, config.getLdapGroupsMemberAttr(), accountDN); conn.modify(new ModifyRequest(group.getDn(), mod)); log.info("Remove membership {} from {}", accountDN, group.getName()); if (group.getMembersDn().size() == 1) { log.info("Removing group {}", group.getName()); conn.delete(group.getDn()); } } } catch (LDAPException e) { throw new LdapSystemException(e); } }
try modifyResult = ldapConnection.modify(modifyRequest);
@Override public void addGroupMember(String accountDN, String groupName) throws LdapSystemException { try (LDAPConnection conn = ldapPool.getConnection()) { LdapGroup group = getGroup(groupName, conn); if (group != null && group.getMembersDn().contains(accountDN)) { log.info("Nothing to do. Account {} is already member of group {}", accountDN, group.getName()); } else { if (group == null) { log.debug("Creating group {}", groupName); DN groupDN = new DN(new RDN(GROUP_NAME_ATTR, groupName), new DN(config.getLdapGroupsBaseDN())); Entry groupEntry = new Entry(groupDN); groupEntry.addAttribute("objectClass", config.getLdapGroupsObjectClass()); groupEntry.addAttribute(config.getLdapGroupsMemberAttr(), accountDN); conn.add(groupEntry); log.info("Group {} added", groupDN); } else { Modification mod = new Modification(ADD, config.getLdapGroupsMemberAttr(), accountDN); conn.modify(new ModifyRequest(group.getDn(), mod)); log.info("Added membership {} to {}", accountDN, group.getName()); } } } catch (LDAPException e) { throw new LdapSystemException(e); } }
final LDAPResult result = conn.modify(modifyRequest); setResponseControls(result);
@Override public LdapGroup createOrUpdateGroup(LdapGroup group) throws LdapSystemException { try (LDAPConnection conn = ldapPool.getConnection()) { LdapGroup current = getGroup(group.getName(), conn); if (current != null) { Modification[] mods = new Modification[]{ new Modification(REPLACE, GROUP_DESC_ATTR, group.getDescription()), new Modification(REPLACE, config.getLdapGroupsMemberAttr(), group.getMembersDn().toArray(new String[0])) }; conn.modify(current.getDn(), mods); current.setDescription(group.getDescription()); current.setMembersDn(group.getMembersDn()); } else { String dn = getGroupDN(group.getName()); Entry entry = new Entry(dn); entry.setAttribute(GROUP_NAME_ATTR, group.getName()); entry.setAttribute(GROUP_DESC_ATTR, group.getDescription()); entry.setAttribute(config.getLdapGroupsMemberAttr(), group.getMembersDn()); entry.setAttribute("objectClass", config.getLdapGroupsObjectClass()); conn.add(entry); current = new LdapGroup(dn, group.getName(), group.getDescription(), group.getMembersDn()); } return current; } catch (LDAPException e) { throw new LdapSystemException(e); } }