/** * Processes the provided add request. * * @param addRequest The add request to be processed. It must not be * {@code null}. * * @return The result of processing the add operation. * * @throws LDAPException If the server rejects the add request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult add(final ReadOnlyAddRequest addRequest) throws LDAPException { return add((AddRequest) addRequest); }
/** * Processes the provided add request. * * @param addRequest The add request to be processed. It must not be * {@code null}. * * @return The result of processing the add operation. * * @throws LDAPException If the server rejects the add request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult add(final ReadOnlyAddRequest addRequest) throws LDAPException { return add((AddRequest) addRequest); }
@Override protected LDAPResult run() throws Exception { return getConnection().add(entry); }
/** * Processes an add operation with the provided information. * * @param ldifLines The lines that comprise an LDIF representation of the * entry to add. It must not be empty or {@code null}. * * @return The result of processing the add operation. * * @throws LDIFException If the provided entry lines cannot be decoded as an * entry in LDIF form. * * @throws LDAPException If the server rejects the add request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult add(final String... ldifLines) throws LDIFException, LDAPException { return add(new AddRequest(ldifLines)); }
/** * Processes an add operation with the provided information. * * @param ldifLines The lines that comprise an LDIF representation of the * entry to add. It must not be empty or {@code null}. * * @return The result of processing the add operation. * * @throws LDIFException If the provided entry lines cannot be decoded as an * entry in LDIF form. * * @throws LDAPException If the server rejects the add request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult add(final String... ldifLines) throws LDIFException, LDAPException { return add(new AddRequest(ldifLines)); }
/** * Processes an add operation with the provided information. * * @param entry The entry to add. It must not be {@code null}. * * @return The result of processing the add operation. * * @throws LDAPException If the server rejects the add request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult add(final Entry entry) throws LDAPException { ensureNotNull(entry); return add(new AddRequest(entry)); }
/** * Processes an add operation with the provided information. * * @param entry The entry to add. It must not be {@code null}. * * @return The result of processing the add operation. * * @throws LDAPException If the server rejects the add request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult add(final Entry entry) throws LDAPException { ensureNotNull(entry); return add(new AddRequest(entry)); }
/** * Processes an add operation with the provided information. * * @param dn The DN of the entry to add. It must not be * {@code null}. * @param attributes The set of attributes to include in the entry to add. * It must not be {@code null}. * * @return The result of processing the add operation. * * @throws LDAPException If the server rejects the add request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult add(final String dn, final Attribute... attributes) throws LDAPException { ensureNotNull(dn, attributes); return add(new AddRequest(dn, attributes)); }
/** * Processes an add operation with the provided information. * * @param dn The DN of the entry to add. It must not be * {@code null}. * @param attributes The set of attributes to include in the entry to add. * It must not be {@code null}. * * @return The result of processing the add operation. * * @throws LDAPException If the server rejects the add request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult add(final String dn, final Collection<Attribute> attributes) throws LDAPException { ensureNotNull(dn, attributes); return add(new AddRequest(dn, attributes)); }
/** * Processes an add operation with the provided information. * * @param dn The DN of the entry to add. It must not be * {@code null}. * @param attributes The set of attributes to include in the entry to add. * It must not be {@code null}. * * @return The result of processing the add operation. * * @throws LDAPException If the server rejects the add request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult add(final String dn, final Attribute... attributes) throws LDAPException { ensureNotNull(dn, attributes); return add(new AddRequest(dn, attributes)); }
/** * Processes an add operation with the provided information. * * @param dn The DN of the entry to add. It must not be * {@code null}. * @param attributes The set of attributes to include in the entry to add. * It must not be {@code null}. * * @return The result of processing the add operation. * * @throws LDAPException If the server rejects the add request, or if a * problem is encountered while sending the request or * reading the response. */ public LDAPResult add(final String dn, final Collection<Attribute> attributes) throws LDAPException { ensureNotNull(dn, attributes); return add(new AddRequest(dn, attributes)); }
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); } }
private void insertTestUsers() throws LDAPException { LDAPConnection connection = null; try { connection = new LDAPConnection("localhost", 10389); // entry tim/sausages List<Attribute> addRequest = new ArrayList<>(); addRequest.add(new Attribute("objectClass", "top")); addRequest.add(new Attribute("objectClass", "person")); addRequest.add(new Attribute("objectClass", "organizationalPerson")); addRequest.add(new Attribute("objectClass", "inetOrgPerson")); addRequest.add(new Attribute("cn", "Tim Fox")); addRequest.add(new Attribute("sn", "Fox")); addRequest.add(new Attribute("mail", "tim@example.com")); addRequest.add(new Attribute("uid", "tim")); addRequest.add(new Attribute("userPassword", "{ssha}d0M5Z2qjOOCSCQInvZHgVAleCqU5I+ag9ZHXMw==")); connection.add("uid=tim,ou=users,dc=foo,dc=com", addRequest); } finally { if (connection != null) { connection.close(); } } }
private void insertTestUsers() throws LDAPException { LDAPConnection connection = null; try { connection = new LDAPConnection("localhost", 10389); // entry tim/sausages List<Attribute> addRequest = new ArrayList<Attribute>(); addRequest.add(new Attribute("objectClass", "top")); addRequest.add(new Attribute("objectClass", "person")); addRequest.add(new Attribute("objectClass", "organizationalPerson")); addRequest.add(new Attribute("objectClass", "inetOrgPerson")); addRequest.add(new Attribute("cn", "Tim Fox")); addRequest.add(new Attribute("sn", "Fox")); addRequest.add(new Attribute("mail", "tim@example.com")); addRequest.add(new Attribute("uid", "tim")); addRequest.add(new Attribute("userPassword", "{ssha}d0M5Z2qjOOCSCQInvZHgVAleCqU5I+ag9ZHXMw==")); connection.add("uid=tim,ou=users,dc=foo,dc=com", addRequest); } finally { if (connection != null) { connection.close(); } } }
/** * 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); }
/** * Adds the provided entry to the directory. * * @param entry The entry to be added. * @param constraints The constraints to use for the add operation. * * @throws LDAPException If a problem occurs while adding the entry. */ public void add(final LDAPEntry entry, final LDAPConstraints constraints) throws LDAPException { final AddRequest addRequest = new AddRequest(entry.toEntry()); update(addRequest, constraints); try { final LDAPResult result = conn.add(addRequest); setResponseControls(result); } catch (com.unboundid.ldap.sdk.LDAPException le) { debugException(le); setResponseControls(le); throw new LDAPException(le); } }
try addResult = ldapConnection.add(addRequest);
@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); } }
@Override public void createAccount(LdapAccount account) throws LdapSystemException { try (LDAPConnection conn = ldapPool.getConnection()) { String entryDN = getAccountDN(account); log.info("Creating user with DN {}", entryDN); Entry entry = new Entry(entryDN); entry.addAttribute("objectClass", "inetOrgPerson"); for (String email : account.getEmails()) { entry.addAttribute("mail", email); } entry.addAttribute("givenName", account.getGivenName()); entry.addAttribute("sn", account.getFamilyName()); entry.addAttribute("cn", account.getName()); entry.addAttribute("employeeNumber", account.getSubject()); entry.addAttribute("userPassword", account.getPassword()); entry.addAttribute("employeeType", account.getRole().toString()); conn.add(entry); } catch (LDAPException e) { throw new LdapSystemException(e); } }
@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); } }