Search in sources :

Example 1 with AddRequest

use of com.unboundid.ldap.sdk.AddRequest in project cas by apereo.

the class LdapTestUtils method createLdapEntries.

/**
     * Creates the given LDAP entries.
     *
     * @param connection Open LDAP connection used to connect to directory.
     * @param entries    Collection of LDAP entries.
     * @throws Exception On LDAP errors.
     */
public static void createLdapEntries(final LDAPConnection connection, final Collection<LdapEntry> entries) throws Exception {
    try {
        for (final LdapEntry entry : entries) {
            final Collection<Attribute> attrs = new ArrayList<>(entry.getAttributeNames().length);
            attrs.addAll(entry.getAttributes().stream().map(a -> new Attribute(a.getName(), a.getStringValues())).collect(Collectors.toList()));
            final AddRequest ad = new AddRequest(entry.getDn(), attrs);
            connection.add(ad);
        }
    } catch (final Exception e) {
        LOGGER.warn(e.getLocalizedMessage());
    }
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) Attribute(com.unboundid.ldap.sdk.Attribute) LdapAttribute(org.ldaptive.LdapAttribute) ArrayList(java.util.ArrayList) LdapEntry(org.ldaptive.LdapEntry) IOException(java.io.IOException)

Aggregations

AddRequest (com.unboundid.ldap.sdk.AddRequest)1 Attribute (com.unboundid.ldap.sdk.Attribute)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LdapAttribute (org.ldaptive.LdapAttribute)1 LdapEntry (org.ldaptive.LdapEntry)1