Search in sources :

Example 6 with DN

use of com.unboundid.ldap.sdk.DN in project oxAuth by GluuFederation.

the class LdapUtils method createAnyFilterFromDnList.

/**
     * Creates any filter to load all objects represented by this dn list.
     *
     * @param p_filterAttributeName filter attribute name
     * @param p_dnList              dn list
     * @return filter
     */
public static Filter createAnyFilterFromDnList(String p_filterAttributeName, List<String> p_dnList) {
    try {
        if (p_dnList != null && !p_dnList.isEmpty()) {
            final StringBuilder sb = new StringBuilder("(|");
            for (String dn : p_dnList) {
                final DN dnObj = new DN(dn);
                final RDN rdn = dnObj.getRDN();
                if (rdn.getAttributeNames()[0].equals(p_filterAttributeName)) {
                    final String[] values = rdn.getAttributeValues();
                    if (values != null && values.length == 1) {
                        sb.append("(");
                        sb.append(p_filterAttributeName).append("=");
                        sb.append(values[0]);
                        sb.append(")");
                    }
                }
            }
            sb.append(")");
            final String filterAsString = sb.toString();
            log.trace("dnList: " + p_dnList + ", ldapFilter: " + filterAsString);
            return Filter.create(filterAsString);
        }
    } catch (LDAPException e) {
        log.trace(e.getMessage(), e);
    }
    return null;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) RDN(com.unboundid.ldap.sdk.RDN)

Example 7 with DN

use of com.unboundid.ldap.sdk.DN in project spring-boot by spring-projects.

the class EmbeddedLdapAutoConfigurationTests method testSetPartitionSuffix.

@Test
void testSetPartitionSuffix() {
    this.contextRunner.withPropertyValues("spring.ldap.embedded.base-dn:dc=spring,dc=org").run((context) -> {
        InMemoryDirectoryServer server = context.getBean(InMemoryDirectoryServer.class);
        assertThat(server.getBaseDNs()).containsExactly(new DN("dc=spring,dc=org"));
    });
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) DN(com.unboundid.ldap.sdk.DN) Test(org.junit.jupiter.api.Test)

Example 8 with DN

use of com.unboundid.ldap.sdk.DN in project jbpm by kiegroup.

the class LDAPBaseTest method startDirectoryServer.

@Before
public void startDirectoryServer() throws LDAPException {
    InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("default", PORT);
    InMemoryDirectoryServerConfig serverConfig = new InMemoryDirectoryServerConfig(new DN(BASE_DN));
    serverConfig.setListenerConfigs(listenerConfig);
    serverConfig.addAdditionalBindCredentials(USER_DN, PASSWORD);
    serverConfig.setSchema(null);
    server = new InMemoryDirectoryServer(serverConfig);
    server.importFromLDIF(false, "src/test/resources/ldap-config.ldif");
    server.startListening();
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) InMemoryListenerConfig(com.unboundid.ldap.listener.InMemoryListenerConfig) DN(com.unboundid.ldap.sdk.DN) Before(org.junit.Before)

Example 9 with DN

use of com.unboundid.ldap.sdk.DN in project spring-security by spring-projects.

the class UnboundIdContainer method start.

@Override
public void start() {
    if (isRunning()) {
        return;
    }
    try {
        InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(this.defaultPartitionSuffix);
        config.addAdditionalBindCredentials("uid=admin,ou=system", "secret");
        config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", this.port));
        config.setEnforceSingleStructuralObjectClass(false);
        config.setEnforceAttributeSyntaxCompliance(true);
        DN dn = new DN(this.defaultPartitionSuffix);
        Entry entry = new Entry(dn);
        entry.addAttribute("objectClass", "top", "domain", "extensibleObject");
        entry.addAttribute("dc", dn.getRDN().getAttributeValues()[0]);
        InMemoryDirectoryServer directoryServer = new InMemoryDirectoryServer(config);
        directoryServer.add(entry);
        importLdif(directoryServer);
        directoryServer.startListening();
        this.port = directoryServer.getListenPort();
        this.directoryServer = directoryServer;
        this.running = true;
    } catch (LDAPException ex) {
        throw new RuntimeException("Server startup failed", ex);
    }
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) LDAPException(com.unboundid.ldap.sdk.LDAPException) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) DN(com.unboundid.ldap.sdk.DN)

Aggregations

DN (com.unboundid.ldap.sdk.DN)9 LDAPException (com.unboundid.ldap.sdk.LDAPException)6 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)5 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)4 InMemoryListenerConfig (com.unboundid.ldap.listener.InMemoryListenerConfig)3 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)2 RDN (com.unboundid.ldap.sdk.RDN)2 Before (org.junit.Before)2 Attribute (com.unboundid.ldap.sdk.Attribute)1 Entry (com.unboundid.ldap.sdk.Entry)1 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)1 SearchResult (com.unboundid.ldap.sdk.SearchResult)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)1 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)1 Test (org.junit.jupiter.api.Test)1 BaseDnConfiguration (org.xdi.oxauth.model.config.BaseDnConfiguration)1