Search in sources :

Example 6 with InMemoryDirectoryServer

use of com.unboundid.ldap.listener.InMemoryDirectoryServer in project gitblit by gitblit.

the class LdapBasedUnitTest method ldapInit.

/**
	 * Create three different in memory DS.
	 *
	 * Each DS has a different configuration:
	 * The first allows anonymous binds.
	 * The second requires authentication for all operations. It will only allow the DIRECTORY_MANAGER account
	 * to search for users and groups.
	 * The third one is like the second, but it allows users to search for users and groups, and restricts the
	 * USER_MANAGER from searching for groups.
	 */
@BeforeClass
public static void ldapInit() throws Exception {
    InMemoryDirectoryServer ds;
    InMemoryDirectoryServerConfig config = createInMemoryLdapServerConfig(AuthMode.ANONYMOUS);
    config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("anonymous"));
    ds = createInMemoryLdapServer(config);
    AuthMode.ANONYMOUS.setDS(ds);
    AuthMode.ANONYMOUS.setLdapPort(ds.getListenPort("anonymous"));
    config = createInMemoryLdapServerConfig(AuthMode.DS_MANAGER);
    config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("ds_manager"));
    config.setAuthenticationRequiredOperationTypes(EnumSet.allOf(OperationType.class));
    ds = createInMemoryLdapServer(config);
    AuthMode.DS_MANAGER.setDS(ds);
    AuthMode.DS_MANAGER.setLdapPort(ds.getListenPort("ds_manager"));
    config = createInMemoryLdapServerConfig(AuthMode.USR_MANAGER);
    config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("usr_manager"));
    config.setAuthenticationRequiredOperationTypes(EnumSet.allOf(OperationType.class));
    ds = createInMemoryLdapServer(config);
    AuthMode.USR_MANAGER.setDS(ds);
    AuthMode.USR_MANAGER.setLdapPort(ds.getListenPort("usr_manager"));
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) OperationType(com.unboundid.ldap.sdk.OperationType) BeforeClass(org.junit.BeforeClass)

Example 7 with InMemoryDirectoryServer

use of com.unboundid.ldap.listener.InMemoryDirectoryServer in project gocd by gocd.

the class InMemoryLdapServerForTests method startServer.

private InMemoryDirectoryServer startServer(int port, String baseDn, String bindDn, String bindPassword) throws LDAPException, BindException {
    InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("default", port);
    InMemoryDirectoryServerConfig serverConfig = new InMemoryDirectoryServerConfig(new DN(baseDn));
    /* Ignore schema so that it does not complain that some attributes (like sAMAccountName) are not valid. */
    serverConfig.setSchema(null);
    serverConfig.setListenerConfigs(listenerConfig);
    serverConfig.addAdditionalBindCredentials(bindDn, bindPassword);
    InMemoryDirectoryServer server = new InMemoryDirectoryServer(serverConfig);
    try {
        server.startListening();
    } catch (LDAPException e) {
        throw new RuntimeException(e);
    }
    new LDIFAddChangeRecord(baseDn, new Attribute("objectClass", "domain", "top")).processChange(server);
    return server;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) Attribute(com.unboundid.ldap.sdk.Attribute) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) InMemoryListenerConfig(com.unboundid.ldap.listener.InMemoryListenerConfig) DN(com.unboundid.ldap.sdk.DN)

Example 8 with InMemoryDirectoryServer

use of com.unboundid.ldap.listener.InMemoryDirectoryServer in project gitblit by gitblit.

the class LdapBasedUnitTest method createInMemoryLdapServer.

public static InMemoryDirectoryServer createInMemoryLdapServer(InMemoryDirectoryServerConfig config) throws Exception {
    InMemoryDirectoryServer imds = new InMemoryDirectoryServer(config);
    imds.importFromLDIF(true, RESOURCE_DIR + "sampledata.ldif");
    imds.startListening();
    return imds;
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer)

Example 9 with InMemoryDirectoryServer

use of com.unboundid.ldap.listener.InMemoryDirectoryServer in project spring-boot by spring-projects.

the class EmbeddedLdapAutoConfigurationTests method testSetPartitionSuffix.

@Test
public void testSetPartitionSuffix() throws LDAPException {
    load("spring.ldap.embedded.base-dn:dc=spring,dc=org");
    InMemoryDirectoryServer server = this.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.Test)

Example 10 with InMemoryDirectoryServer

use of com.unboundid.ldap.listener.InMemoryDirectoryServer in project spring-boot by spring-projects.

the class EmbeddedLdapAutoConfigurationTests method testSetDefaultPort.

@Test
public void testSetDefaultPort() throws LDAPException {
    load("spring.ldap.embedded.port:1234", "spring.ldap.embedded.base-dn:dc=spring,dc=org");
    InMemoryDirectoryServer server = this.context.getBean(InMemoryDirectoryServer.class);
    assertThat(server.getListenPort()).isEqualTo(1234);
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) Test(org.junit.Test)

Aggregations

InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)13 Test (org.junit.Test)7 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)5 InMemoryListenerConfig (com.unboundid.ldap.listener.InMemoryListenerConfig)2 DN (com.unboundid.ldap.sdk.DN)2 GitblitAuthority (com.gitblit.authority.GitblitAuthority)1 NewCertificateConfig (com.gitblit.authority.NewCertificateConfig)1 GitblitContext (com.gitblit.servlet.GitblitContext)1 X509Log (com.gitblit.utils.X509Utils.X509Log)1 X509Metadata (com.gitblit.utils.X509Utils.X509Metadata)1 Attribute (com.unboundid.ldap.sdk.Attribute)1 BindResult (com.unboundid.ldap.sdk.BindResult)1 Entry (com.unboundid.ldap.sdk.Entry)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 OperationType (com.unboundid.ldap.sdk.OperationType)1 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)1 LDIFReader (com.unboundid.ldif.LDIFReader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1