Java Code Examples for org.apache.directory.server.ldap.LdapServer

The following examples show how to use org.apache.directory.server.ldap.LdapServer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: quarkus-http   Source File: KerberosKDCUtil.java    License: Apache License 2.0 7 votes vote down vote up
private static void startLdapServer() throws Exception {
    createWorkingDir();
    DirectoryServiceFactory dsf = new DefaultDirectoryServiceFactory();
    dsf.init(DIRECTORY_NAME);
    directoryService = dsf.getDirectoryService();
    directoryService.addLast(new KeyDerivationInterceptor()); // Derives the Kerberos keys for new entries.
    directoryService.getChangeLog().setEnabled(false);
    SchemaManager schemaManager = directoryService.getSchemaManager();

    createPartition(dsf, schemaManager, "users", "ou=users,dc=undertow,dc=io");

    CoreSession adminSession = directoryService.getAdminSession();
    Map<String, String> mappings = Collections.singletonMap("hostname", DefaultServer.getDefaultServerAddress().getHostString());
    processLdif(schemaManager, adminSession, "partition.ldif", mappings);
    processLdif(schemaManager, adminSession, "krbtgt.ldif", mappings);
    processLdif(schemaManager, adminSession, "user.ldif", mappings);
    processLdif(schemaManager, adminSession, "server.ldif", mappings);

    ldapServer = new LdapServer();
    ldapServer.setServiceName("DefaultLDAP");
    Transport ldap = new TcpTransport( "0.0.0.0", LDAP_PORT, 3, 5 );
    ldapServer.addTransports(ldap);
    ldapServer.setDirectoryService(directoryService);
    ldapServer.start();
}
 
Example 2
private void setUpKerberos() throws Exception
{
    final LdapServer ldapServer = LDAP.getLdapServer();
    final KdcServer kdcServer =
            ServerAnnotationProcessor.getKdcServer(LDAP.getDirectoryService(), ldapServer.getPort() + 1);
    kdcServer.getConfig().setPaEncTimestampRequired(false);

    final int port = kdcServer.getTransports()[0].getPort();
    final String krb5confPath = createKrb5Conf(port);
    SYSTEM_PROPERTY_SETTER.setSystemProperty("java.security.krb5.conf", krb5confPath);
    SYSTEM_PROPERTY_SETTER.setSystemProperty("java.security.krb5.realm", null);
    SYSTEM_PROPERTY_SETTER.setSystemProperty("java.security.krb5.kdc", null);

    final KerberosPrincipal servicePrincipal =
            new KerberosPrincipal(LDAP_SERVICE_NAME + "/" + HOSTNAME + "@" + REALM,
                                  KerberosPrincipal.KRB_NT_SRV_HST);
    final String servicePrincipalName = servicePrincipal.getName();
    ldapServer.setSaslHost(servicePrincipalName.substring(servicePrincipalName.indexOf("/") + 1,
                                                          servicePrincipalName.indexOf("@")));
    ldapServer.setSaslPrincipal(servicePrincipalName);
    ldapServer.setSearchBaseDn(USERS_DN);

    createPrincipal("KDC", "KDC", "krbtgt", UUID.randomUUID().toString(), "krbtgt/" + REALM + "@" + REALM);
    createPrincipal("Service", "LDAP Service", "ldap", UUID.randomUUID().toString(), servicePrincipalName);
}
 
Example 3
Source Project: MyVirtualDirectory   Source File: LdapsInitializer.java    License: Apache License 2.0 6 votes vote down vote up
public static IoFilterChainBuilder init( LdapServer server ) throws LdapException
{
    SSLContext sslCtx;
    try
    {
    	sslCtx = server.getSSLContext();
    	
    }
    catch ( Exception e )
    {
        throw new LdapException( I18n.err( I18n.ERR_683 ), e );
    }

    DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
    SslFilter sslFilter = new SslFilter( sslCtx );

    List<String> cipherSuites = server.getEnabledCipherSuites();
    if( ( cipherSuites != null ) && !cipherSuites.isEmpty() )
    {
        sslFilter.setEnabledCipherSuites( cipherSuites.toArray( new String[cipherSuites.size()] ) );
    }
    
    sslFilter.setWantClientAuth( true );
    chain.addLast( "sslFilter", sslFilter );
    return chain;
}
 
Example 4
Source Project: codenvy   Source File: EmbeddedLdapServer.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public EmbeddedLdapServer(
    File workingDir,
    String partitionDn,
    String partitionId,
    int port,
    boolean enableChangelog,
    boolean allowAnonymousAccess,
    long maxSizeLimit)
    throws Exception {
  requireNonNull(partitionDn, "Required non-null partition dn");
  requireNonNull(partitionId, "Required non-null partition id");
  this.workingDir = workingDir;
  this.baseDn = new DN(partitionDn);
  this.port = port > 0 ? port : PORT_SERVICE.acquire();
  this.url = "ldap://localhost:" + this.port;
  ldapServer = new LdapServer();
  ldapServer.setTransports(new TcpTransport(this.port));
  if (maxSizeLimit > 0) {
    ldapServer.setMaxSizeLimit(maxSizeLimit);
  }
  service =
      initDirectoryService(
          workingDir, partitionId, partitionDn, enableChangelog, allowAnonymousAccess);
  ldapServer.setDirectoryService(service);
}
 
Example 5
Source Project: ranger   Source File: TestLdapUserGroup.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
	LdapServer ldapServer = new LdapServer();
	ldapServer.setSaslHost("127.0.0.1");
	ldapServer.setSearchBaseDn("DC=ranger,DC=qe,DC=hortonworks,DC=com");
	String ldapPort = System.getProperty("ldap.port");
	Assert.assertNotNull("Property 'ldap.port' null", ldapPort);
	ldapServer.setTransports(new TcpTransport("127.0.0.1", Integer.parseInt(ldapPort)));
	ldapServer.setDirectoryService(getService());
	ldapServer.setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT );
	setLdapServer(ldapServer);
	getService().startup();
	getLdapServer().start();
	config = UserGroupSyncConfig.getInstance();	
	ldapBuilder = new LdapUserGroupBuilder();
}
 
Example 6
/**
 * Adds a TCP server to the directory service.
 *
 * Note: The TCP server is not started until start() is called on this Builder.
 *
 * @param serviceName - The name of this server.
 * @param hostName - The host name to listen on.
 * @param port - The port to listen on.
 * @return This Builder for subsequent changes.
 */
public Builder addTcpServer(final String serviceName, final String hostName, final int port, final String keyStore, final String keyStorePassword) throws URISyntaxException {
    assertNotStarted();
    if (directoryService == null) {
        throw new IllegalStateException("The Directory service has not been created.");
    }

    LdapServer server = new LdapServer();
    server.setServiceName(serviceName);
    Transport ldaps = new TcpTransport( hostName, port, 3, 5 );
    ldaps.enableSSL(true);
    server.addTransports(ldaps);
    server.setKeystoreFile(new File(getClass().getResource(keyStore).getFile()).getAbsolutePath());
    server.setCertificatePassword(keyStorePassword);
    server.setDirectoryService(directoryService);
    servers.add(server);

    return this;
}
 
Example 7
private static void startMasterLdapServer() throws Exception {
    masterWorkingDir = createWorkingDir(masterWorkingDir, "master");
    DirectoryServiceFactory dsf = new InMemoryDirectoryServiceFactory();
    dsf.init(MASTER_DIRECTORY_NAME);
    masterDirectoryService = dsf.getDirectoryService();
    masterDirectoryService.getChangeLog().setEnabled(false);
    SchemaManager schemaManager = masterDirectoryService.getSchemaManager();

    createPartition(dsf, schemaManager, "simple", "dc=simple,dc=wildfly,dc=org", masterDirectoryService, masterWorkingDir);
    createPartition(dsf, schemaManager, "group-to-principal", "dc=group-to-principal,dc=wildfly,dc=org", masterDirectoryService, masterWorkingDir);
    createPartition(dsf, schemaManager, "principal-to-group", "dc=principal-to-group,dc=wildfly,dc=org", masterDirectoryService, masterWorkingDir);

    CoreSession adminSession = masterDirectoryService.getAdminSession();
    processLdif(schemaManager, adminSession, "memberOf-schema.ldif");
    processLdif(schemaManager, adminSession, "simple-partition.ldif");
    processLdif(schemaManager, adminSession, "group-to-principal.ldif");
    processLdif(schemaManager, adminSession, "principal-to-group.ldif");

    masterLdapServer = new LdapServer();
    masterLdapServer.setServiceName("DefaultLDAP");
    Transport ldap = new TcpTransport( "0.0.0.0", MASTER_LDAP_PORT, 3, 5 );
    masterLdapServer.addTransports(ldap);
    masterLdapServer.setDirectoryService(masterDirectoryService);
    masterLdapServer.start();
}
 
Example 8
private static void startSlaveLdapServer() throws Exception {
    slaveWorkingDir = createWorkingDir(slaveWorkingDir, "slave");
    DirectoryServiceFactory dsf = new InMemoryDirectoryServiceFactory();
    dsf.init(SLAVE_DIRECTORY_NAME);
    slaveDirectoryService = dsf.getDirectoryService();
    slaveDirectoryService.getChangeLog().setEnabled(false);
    SchemaManager schemaManager = slaveDirectoryService.getSchemaManager();

    createPartition(dsf, schemaManager, "simple", "dc=simple,dc=wildfly,dc=org", slaveDirectoryService, slaveWorkingDir);
    createPartition(dsf, schemaManager, "group-to-principal", "dc=group-to-principal,dc=wildfly,dc=org", slaveDirectoryService, slaveWorkingDir);
    createPartition(dsf, schemaManager, "principal-to-group", "dc=principal-to-group,dc=wildfly,dc=org", slaveDirectoryService, slaveWorkingDir);

    CoreSession adminSession = slaveDirectoryService.getAdminSession();
    processLdif(schemaManager, adminSession, "memberOf-schema.ldif");
    processLdif(schemaManager, adminSession, "simple-partition-slave.ldif");
    processLdif(schemaManager, adminSession, "group-to-principal-slave.ldif");
    processLdif(schemaManager, adminSession, "principal-to-group-slave.ldif");

    slaveLdapServer = new LdapServer();
    slaveLdapServer.setServiceName("DefaultLDAP");
    Transport ldap = new TcpTransport( "0.0.0.0", SLAVE_LDAP_PORT, 3, 5 );
    slaveLdapServer.addTransports(ldap);
    slaveLdapServer.setDirectoryService(slaveDirectoryService);
    slaveLdapServer.start();
}
 
Example 9
Source Project: keycloak   Source File: KerberosEmbeddedServer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected LdapServer createLdapServer() {
    LdapServer ldapServer = super.createLdapServer();

    ldapServer.setSaslHost(this.bindHost);
    ldapServer.setSaslPrincipal( this.ldapSaslPrincipal);
    ldapServer.setSaslRealms(new ArrayList<String>());

    ldapServer.addSaslMechanismHandler(SupportedSaslMechanisms.PLAIN, new PlainMechanismHandler());
    ldapServer.addSaslMechanismHandler(SupportedSaslMechanisms.CRAM_MD5, new CramMd5MechanismHandler());
    ldapServer.addSaslMechanismHandler(SupportedSaslMechanisms.DIGEST_MD5, new DigestMd5MechanismHandler());
    ldapServer.addSaslMechanismHandler(SupportedSaslMechanisms.GSSAPI, new GssapiMechanismHandler());
    ldapServer.addSaslMechanismHandler(SupportedSaslMechanisms.NTLM, new NtlmMechanismHandler());
    ldapServer.addSaslMechanismHandler(SupportedSaslMechanisms.GSS_SPNEGO, new NtlmMechanismHandler());

    return ldapServer;
}
 
Example 10
public void afterPropertiesSet() throws Exception {

		if (this.enabledLdapOverSsl && this.keyStoreFile == null) {
			throw new IllegalArgumentException("When LdapOverSsl is enabled, the keyStoreFile property must be set.");
		}

		if (workingDir == null) {
			String apacheWorkDir = System.getProperty("apacheDSWorkDir");

			if (apacheWorkDir == null) {
				apacheWorkDir = createTempDirectory("apacheds-spring-security-");
			}

			setWorkingDirectory(new File(apacheWorkDir));
		}

		server = new LdapServer();

		// AbstractLdapIntegrationTests assume IPv4, so we specify the same here
		TcpTransport transport = new TcpTransport(port);

		if (enabledLdapOverSsl) {
			transport.setEnableSSL(true);
			server.setKeystoreFile(this.keyStoreFile.getAbsolutePath());
			server.setCertificatePassword(this.keyStorePassword);
		}

		server.setTransports(transport);
		server.setDirectoryService(service);
		start();
	}
 
Example 11
Source Project: light-oauth2   Source File: ApacheDirectoryServer.java    License: Apache License 2.0 5 votes vote down vote up
private static void startLdapServer() throws Exception {
    createWorkingDir();
    DirectoryServiceFactory dsf = new DefaultDirectoryServiceFactory();
    dsf.init(DIRECTORY_NAME);
    directoryService = dsf.getDirectoryService();
    directoryService.addLast(new KeyDerivationInterceptor()); // Derives the Kerberos keys for new entries.
    directoryService.getChangeLog().setEnabled(false);
    SchemaManager schemaManager = directoryService.getSchemaManager();

    createPartition(dsf, schemaManager, "users", "ou=users,dc=undertow,dc=io");

    CoreSession adminSession = directoryService.getAdminSession();
    //Map<String, String> mappings = Collections.singletonMap("hostname", DefaultServer.getDefaultServerAddress().getHostString());
    Map<String, String> mappings = Collections.singletonMap("hostname", "localhost");
    processLdif(schemaManager, adminSession, "partition.ldif", mappings);
    processLdif(schemaManager, adminSession, "krbtgt.ldif", mappings);
    processLdif(schemaManager, adminSession, "user.ldif", mappings);
    processLdif(schemaManager, adminSession, "server.ldif", mappings);

    ldapServer = new LdapServer();
    ldapServer.setServiceName("DefaultLDAP");
    Transport ldap = new TcpTransport( "0.0.0.0", LDAPS_PORT, 3, 5 );
    ldap.enableSSL(true);
    ldapServer.addTransports(ldap);
    ldapServer.setKeystoreFile(ApacheDirectoryServer.class.getResource("/config/server.keystore").getFile());
    ldapServer.setCertificatePassword("password");
    ldapServer.loadKeyStore();
    ldapServer.setDirectoryService(directoryService);
    ldapServer.start();
}
 
Example 12
Source Project: light-oauth2   Source File: ApacheDirectoryServer.java    License: Apache License 2.0 5 votes vote down vote up
private static void startLdapServer() throws Exception {
    createWorkingDir();
    DirectoryServiceFactory dsf = new DefaultDirectoryServiceFactory();
    dsf.init(DIRECTORY_NAME);
    directoryService = dsf.getDirectoryService();
    directoryService.addLast(new KeyDerivationInterceptor()); // Derives the Kerberos keys for new entries.
    directoryService.getChangeLog().setEnabled(false);
    SchemaManager schemaManager = directoryService.getSchemaManager();

    createPartition(dsf, schemaManager, "users", "ou=users,dc=undertow,dc=io");

    CoreSession adminSession = directoryService.getAdminSession();
    //Map<String, String> mappings = Collections.singletonMap("hostname", DefaultServer.getDefaultServerAddress().getHostString());
    Map<String, String> mappings = Collections.singletonMap("hostname", "localhost");
    processLdif(schemaManager, adminSession, "partition.ldif", mappings);
    processLdif(schemaManager, adminSession, "krbtgt.ldif", mappings);
    processLdif(schemaManager, adminSession, "user.ldif", mappings);
    processLdif(schemaManager, adminSession, "server.ldif", mappings);

    ldapServer = new LdapServer();
    ldapServer.setServiceName("DefaultLDAP");
    Transport ldap = new TcpTransport( "0.0.0.0", LDAPS_PORT, 3, 5 );
    ldap.enableSSL(true);
    ldapServer.addTransports(ldap);
    ldapServer.setKeystoreFile(ApacheDirectoryServer.class.getResource("/config/server.keystore").getFile());
    ldapServer.setCertificatePassword("password");
    ldapServer.loadKeyStore();
    ldapServer.setDirectoryService(directoryService);
    ldapServer.start();
}
 
Example 13
Source Project: gemfirexd-oss   Source File: LdapTestServer.java    License: Apache License 2.0 5 votes vote down vote up
/** stops the LdapServer */
public void stopService() throws Exception {
  final LdapServer server = this.server;
  if (server != null && server.isStarted()) {
    server.stop();
  }
  service.shutdown();
  FileUtils.deleteQuietly(service.getWorkingDirectory());
  // null the singleton instance
  instance = null;
}
 
Example 14
Source Project: gemfirexd-oss   Source File: LdapTestServer.java    License: Apache License 2.0 5 votes vote down vote up
/** stops the LdapServer */
public void stopService() throws Exception {
  final LdapServer server = this.server;
  if (server != null && server.isStarted()) {
    server.stop();
  }
  service.shutdown();
  FileUtils.deleteQuietly(service.getWorkingDirectory());
  // null the singleton instance
  instance = null;
}
 
Example 15
Source Project: Benchmark   Source File: LDAPServer.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * starts the LdapServer
 *
 * @throws Exception
 */
public void startServer() throws Exception {
	server = new LdapServer();
	int serverPort = 10389;
	server.setTransports(new TcpTransport(serverPort));
	server.setDirectoryService(service);

	server.start();
}
 
Example 16
Source Project: cukes   Source File: EmbeddedLDAPServer.java    License: Apache License 2.0 5 votes vote down vote up
public void start() throws Exception {
    DirectoryServiceFactory factory = new DefaultDirectoryServiceFactory();
    factory.init("server");
    service = factory.getDirectoryService();
    service.addPartition(createPartition("default", "cn=test"));
    service.addPartition(createPartition("domain", "dc=example,dc=com"));

    server = new LdapServer();
    server.setDirectoryService(service);
    server.setTransports(new TcpTransport(PORT));
    server.start();
}
 
Example 17
Source Project: carbon-identity   Source File: ApacheLDAPServer.java    License: Apache License 2.0 5 votes vote down vote up
protected void initializeLDAPServer()
        throws DirectoryServerException {

    if (null == this.service || null == this.ldapConfigurations) {
        throw new DirectoryServerException(
                "The default apacheds service is not initialized. " +
                        "Make sure apacheds service is initialized first.");
    }

    this.ldapServer = new LdapServer();

    this.ldapServer.setTransports(new TcpTransport(this.ldapConfigurations.getLdapPort()));

    // set server initial properties
    this.ldapServer.setAllowAnonymousAccess(false);
    this.ldapServer.setMaxTimeLimit(this.ldapConfigurations.getMaxTimeLimit());
    this.ldapServer.setMaxSizeLimit(this.ldapConfigurations.getMaxSizeLimit());
    this.ldapServer.setSaslHost(this.ldapConfigurations.getSaslHostName());
    this.ldapServer.setSaslPrincipal(this.ldapConfigurations.getSaslPrincipalName());

    // add the apacheds service
    this.ldapServer.setDirectoryService(this.service);

    setupSaslMechanisms();

    try {
        this.ldapServer.addExtendedOperationHandler(new StartTlsHandler());
        this.ldapServer.addExtendedOperationHandler(
                new StoredProcedureExtendedOperationHandler());
    } catch (Exception e) {
        throw new DirectoryServerException("can not add the extension handlers ", e);
    }
}
 
Example 18
@Override
public void close() throws IOException {
    for (LdapServer current : servers) {
        current.stop();
    }
    try {
        directoryService.shutdown();
    } catch (Exception e) {
        throw new IOException("Unable to shut down DirectoryService", e);
    }
}
 
Example 19
public LdapService start() throws Exception {
    assertNotStarted();
    started = true;

    for (LdapServer current : servers) {
        current.start();
    }

    return new LdapService(directoryService, servers);
}
 
Example 20
Source Project: vertx-auth   Source File: EmbeddedADS.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * starts the LdapServer
 *
 * @throws Exception
 */
public void startServer() throws Exception {
  server = new LdapServer();
  int serverPort = 10389;
  server.setTransports(new TcpTransport(serverPort));
  server.setDirectoryService(service);

  server.start();
}
 
Example 21
@Test
public void testEmbeddedLdapServerInitialization() throws IndexNotFoundException {
    LdapServer ldapServer = embeddedLdapServer.getLdapServer();
    assertNotNull(ldapServer);

    DirectoryService directoryService = embeddedLdapServer.getDirectoryService();
    assertNotNull(directoryService);
    assertNotNull(directoryService.getSchemaPartition());
    assertNotNull(directoryService.getSystemPartition());
    assertNotNull(directoryService.getSchemaManager());
    assertNotNull(directoryService.getDnFactory());

    assertNotNull(directoryService.isDenormalizeOpAttrsEnabled());

    ChangeLog changeLog = directoryService.getChangeLog();

    assertNotNull(changeLog);
    assertFalse(changeLog.isEnabled());

    assertNotNull(directoryService.isStarted());
    assertNotNull(ldapServer.isStarted());

    List userList = new ArrayList(embeddedLdapServer.getUserIndexMap().keySet());
    java.util.Collections.sort(userList);
    List checkList = Arrays.asList("uid");
    assertEquals(userList, checkList);
}
 
Example 22
Source Project: cloudstack   Source File: EmbeddedLdapServer.java    License: Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    if (getDirectoryService() == null) {
        if (getDeleteInstanceDirectoryOnStartup()) {
            deleteDirectory(getGuessedInstanceDirectory());
        }

        DefaultDirectoryServiceFactory serviceFactory = new DefaultDirectoryServiceFactory();
        serviceFactory.init(getDirectoryServiceName());
        setDirectoryService(serviceFactory.getDirectoryService());

        getDirectoryService().getChangeLog().setEnabled(false);
        getDirectoryService().setDenormalizeOpAttrsEnabled(true);

        createBasePartition();

        getDirectoryService().startup();

        createRootEntry();
    }

    if (getLdapServer() == null) {
        setLdapServer(new LdapServer());
        getLdapServer().setDirectoryService(getDirectoryService());
        getLdapServer().setTransports(new TcpTransport(getLdapServerPort()));
        getLdapServer().start();
    }
}
 
Example 23
Source Project: aws-iam-ldap-bridge   Source File: Runner.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * starts the LdapServer
 *
 * @throws Exception
 */
public void startServer() throws Exception
{
    server = new LdapServer();

    server.setTransports( new TcpTransport( serverPort ) );
    server.setDirectoryService( service );

    server.start();
}
 
Example 24
public void startLdapServer(MiniKdc miniKdc) throws Exception {
    ldapServer = new LdapServer();
    Field f = MiniKdc.class.getDeclaredField("ds");
    f.setAccessible(true);
    DirectoryService ds = (DirectoryService) f.get(miniKdc);
    ldapServer.setDirectoryService(ds);
    TcpTransport tcpTransport = new TcpTransport(4016);
    ldapServer.setTransports(tcpTransport);
    LOG.info(ds.getAdminSession().getAuthenticatedPrincipal().getDn());
    ldapServer.start();
}
 
Example 25
Source Project: spring-ldap   Source File: EmbeddedLdapServer.java    License: Apache License 2.0 5 votes vote down vote up
public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName, String defaultPartitionSuffix, int port)
        throws Exception{
    workingDirectory = new File(System.getProperty("java.io.tmpdir") + "/apacheds-test1");
    FileUtils.deleteDirectory(workingDirectory);

    DefaultDirectoryService directoryService = new DefaultDirectoryService();
    directoryService.setShutdownHookEnabled(true);
    directoryService.setAllowAnonymousAccess(true);

    directoryService.setWorkingDirectory(workingDirectory);
    directoryService.getChangeLog().setEnabled( false );

    JdbmPartition partition = new JdbmPartition();
    partition.setId(defaultPartitionName);
    partition.setSuffix(defaultPartitionSuffix);
    directoryService.addPartition(partition);

    directoryService.startup();

    // Inject the apache root entry if it does not already exist
    if ( !directoryService.getAdminSession().exists( partition.getSuffixDn() ) )
    {
        ServerEntry entry = directoryService.newEntry(new LdapDN(defaultPartitionSuffix));
        entry.add("objectClass", "top", "domain", "extensibleObject");
        entry.add("dc", defaultPartitionName);
        directoryService.getAdminSession().add( entry );
    }

    LdapServer ldapServer = new LdapServer();
    ldapServer.setDirectoryService(directoryService);

    TcpTransport ldapTransport = new TcpTransport(port);
    ldapServer.setTransports( ldapTransport );
    ldapServer.start();

    return new EmbeddedLdapServer(directoryService, ldapServer);
}
 
Example 26
Source Project: camunda-bpm-platform   Source File: LdapTestEnvironment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * starts the LdapServer
 *
 * @throws Exception
 */
public void startServer() throws Exception {
  ldapService = new LdapServer();
  Properties properties = loadTestProperties();
  String port = properties.getProperty("ldap.server.port");
  ldapService.setTransports(new TcpTransport(Integer.parseInt(port)));
  ldapService.setDirectoryService(service);
  ldapService.start();
}
 
Example 27
Source Project: gemfirexd-oss   Source File: LdapTestServer.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isServerStarted() {
  final LdapServer server = this.server;
  return server != null && server.isStarted();
}
 
Example 28
Source Project: MyVirtualDirectory   Source File: LdapsInitializer.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the LDAPS server.
 *
 * @param ldapServer The LDAP server instance
 * @param transport The TCP transport that contains the SSL configuration
 * @return A IoFilter chain
 * @throws LdapException If we had a pb
 */
public static IoFilterChainBuilder init( LdapServer ldapServer, TcpTransport transport ) throws LdapException
{
    SSLContext sslCtx;

    try
    {
    	sslCtx = ldapServer.getSSLContext();
    	
    	//TODO see if this is correct
    	// Initialize the SSLContext to work with our key managers.
        //sslCtx = SSLContext.getInstance( "TLS" );
        //sslCtx.init( ldapServer.getKeyManagerFactory().getKeyManagers(), new TrustManager[]
        //    { new NoVerificationTrustManager() }, new SecureRandom() );
    	
    }
    catch ( Exception e )
    {
        throw new LdapException( I18n.err( I18n.ERR_683 ), e );
    }

    DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
    SslFilter sslFilter = new SslFilter( sslCtx );

    // The ciphers
    List<String> cipherSuites = transport.getCipherSuite();

    if ( ( cipherSuites != null ) && !cipherSuites.isEmpty() )
    {
        sslFilter.setEnabledCipherSuites( cipherSuites.toArray( new String[cipherSuites.size()] ) );
    }

    // The protocols
    List<String> enabledProtocols = transport.getEnabledProtocols();

    if ( ( enabledProtocols != null ) && !enabledProtocols.isEmpty() )
    {
        sslFilter.setEnabledProtocols( enabledProtocols.toArray( new String[enabledProtocols.size()] ) );
    }
    else
    {
        // Be sure we disable SSLV3
        sslFilter.setEnabledProtocols( new String[]
            { "SSLv2Hello", "TLSv1", "TLSv1.1", "TLSv1.2" } );
    }

    // The remaining SSL parameters
    sslFilter.setNeedClientAuth( transport.isNeedClientAuth() );
    sslFilter.setWantClientAuth( transport.isWantClientAuth() );
    
    chain.addLast( "sslFilter", sslFilter );

    return chain;
}
 
Example 29
Source Project: gemfirexd-oss   Source File: LdapTestServer.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isServerStarted() {
  final LdapServer server = this.server;
  return server != null && server.isStarted();
}
 
Example 30
Source Project: openmeetings   Source File: CreateLdapServerExtension.java    License: Apache License 2.0 4 votes vote down vote up
public LdapServer getLdapServer() {
	return ldapServer;
}