Search in sources :

Example 6 with SchemaManager

use of org.apache.directory.api.ldap.model.schema.SchemaManager in project undertow by undertow-io.

the class KerberosKDCUtil method startLdapServer.

private static void startLdapServer() throws Exception {
    createWorkingDir();
    DirectoryServiceFactory dsf = new DefaultDirectoryServiceFactory();
    dsf.init(DIRECTORY_NAME);
    directoryService = dsf.getDirectoryService();
    // Derives the Kerberos keys for new entries.
    directoryService.addLast(new KeyDerivationInterceptor());
    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();
}
Also used : KeyDerivationInterceptor(org.apache.directory.server.core.kerberos.KeyDerivationInterceptor) LdapServer(org.apache.directory.server.ldap.LdapServer) DefaultDirectoryServiceFactory(org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) CoreSession(org.apache.directory.server.core.api.CoreSession) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) Transport(org.apache.directory.server.protocol.shared.transport.Transport) DirectoryServiceFactory(org.apache.directory.server.core.factory.DirectoryServiceFactory) DefaultDirectoryServiceFactory(org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory)

Example 7 with SchemaManager

use of org.apache.directory.api.ldap.model.schema.SchemaManager in project wildfly by wildfly.

the class KerberosServerSetupTask method createLdap1.

//@formatter:off
@CreateDS(name = "JBossDS-KerberosServerSetupTask", factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class, partitions = { @CreatePartition(name = "jboss", suffix = "dc=jboss,dc=org", contextEntry = @ContextEntry(entryLdif = "dn: dc=jboss,dc=org\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n"), indexes = { @CreateIndex(attribute = "objectClass"), @CreateIndex(attribute = "dc"), @CreateIndex(attribute = "ou") }) }, additionalInterceptors = { KeyDerivationInterceptor.class })
@CreateLdapServer(transports = { @CreateTransport(protocol = "LDAP", port = LDAP_PORT), @CreateTransport(protocol = "LDAPS", port = LDAPS_PORT) }, certificatePassword = "secret")
@CreateKdcServer(primaryRealm = KERBEROS_PRIMARY_REALM, kdcPrincipal = "krbtgt/" + KERBEROS_PRIMARY_REALM + "@" + KERBEROS_PRIMARY_REALM, searchBaseDn = "dc=jboss,dc=org", transports = { @CreateTransport(protocol = "UDP", port = KERBEROS_PORT), @CreateTransport(protocol = "TCP", port = KERBEROS_PORT) })
public //@formatter:on
void createLdap1(ManagementClient managementClient, final String hostname) throws Exception {
    final Map<String, String> map = new HashMap<String, String>();
    final String cannonicalHost = NetworkUtils.formatPossibleIpv6Address(Utils.getCannonicalHost(managementClient));
    map.put("hostname", cannonicalHost);
    map.put("realm", KERBEROS_PRIMARY_REALM);
    directoryService1 = DSAnnotationProcessor.getDirectoryService();
    final String ldifContent = StrSubstitutor.replace(IOUtils.toString(KerberosServerSetupTask.class.getResourceAsStream(KerberosServerSetupTask.class.getSimpleName() + ".ldif"), "UTF-8"), map);
    LOGGER.trace(ldifContent);
    final SchemaManager schemaManager = directoryService1.getSchemaManager();
    try {
        for (LdifEntry ldifEntry : new LdifReader(IOUtils.toInputStream(ldifContent))) {
            directoryService1.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer((CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class));
    FileOutputStream fos = new FileOutputStream(KEYSTORE_FILE);
    IOUtils.copy(getClass().getResourceAsStream(KEYSTORE_FILENAME), fos);
    fos.close();
    createLdapServer.setKeyStore(KEYSTORE_FILE.getAbsolutePath());
    fixTransportAddress(createLdapServer, cannonicalHost);
    ldapServer1 = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService1);
    krbServer1 = KDCServerAnnotationProcessor.getKdcServer(directoryService1, KERBEROS_PORT, cannonicalHost);
    ldapServer1.start();
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) CreateDS(org.apache.directory.server.core.annotations.CreateDS) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) CreateLdapServer(org.apache.directory.server.annotations.CreateLdapServer) CreateKdcServer(org.apache.directory.server.annotations.CreateKdcServer)

Example 8 with SchemaManager

use of org.apache.directory.api.ldap.model.schema.SchemaManager in project wildfly by wildfly.

the class LdapExtLDAPServerSetupTask method createLdap1.

//@formatter:off
@CreateDS(name = "JBossDS-LdapExtLDAPServerSetupTask", factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class, partitions = { @CreatePartition(name = "jboss", suffix = "dc=jboss,dc=org", contextEntry = @ContextEntry(entryLdif = "dn: dc=jboss,dc=org\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n"), indexes = { @CreateIndex(attribute = "objectClass"), @CreateIndex(attribute = "dc"), @CreateIndex(attribute = "ou") }) }, additionalInterceptors = { KeyDerivationInterceptor.class })
@CreateLdapServer(transports = { @CreateTransport(protocol = "LDAP", port = LDAP_PORT), @CreateTransport(protocol = "LDAPS", port = LDAPS_PORT) }, certificatePassword = "secret")
public //@formatter:on
void createLdap1(final String hostname) throws Exception {
    final Map<String, String> map = new HashMap<String, String>();
    map.put("hostname", NetworkUtils.formatPossibleIpv6Address(hostname));
    map.put("ldapPort2", Integer.toString(LDAP_PORT2));
    directoryService1 = DSAnnotationProcessor.getDirectoryService();
    final String ldifContent = StrSubstitutor.replace(IOUtils.toString(LdapExtLoginModuleTestCase.class.getResourceAsStream(LdapExtLoginModuleTestCase.class.getSimpleName() + ".ldif"), "UTF-8"), map);
    LOGGER.debug(ldifContent);
    final SchemaManager schemaManager = directoryService1.getSchemaManager();
    try {
        for (LdifEntry ldifEntry : new LdifReader(IOUtils.toInputStream(ldifContent))) {
            directoryService1.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer((CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class));
    FileOutputStream fos = new FileOutputStream(KEYSTORE_FILE);
    IOUtils.copy(getClass().getResourceAsStream(KEYSTORE_FILENAME), fos);
    fos.close();
    createLdapServer.setKeyStore(KEYSTORE_FILE.getAbsolutePath());
    fixTransportAddress(createLdapServer, hostname);
    ldapServer1 = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService1);
    ldapServer1.start();
    LOGGER.trace("ldapServer1 = " + ldapServer1);
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) CreateDS(org.apache.directory.server.core.annotations.CreateDS) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) CreateLdapServer(org.apache.directory.server.annotations.CreateLdapServer)

Aggregations

SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)8 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)4 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)4 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)4 CreateLdapServer (org.apache.directory.server.annotations.CreateLdapServer)4 CreateDS (org.apache.directory.server.core.annotations.CreateDS)4 ManagedCreateLdapServer (org.jboss.as.test.integration.security.common.ManagedCreateLdapServer)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)3 SchemaPartition (org.apache.directory.server.core.api.schema.SchemaPartition)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 SchemaLoader (org.apache.directory.api.ldap.model.schema.registries.SchemaLoader)2 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)2 CacheService (org.apache.directory.server.core.api.CacheService)2 DefaultDnFactory (org.apache.directory.server.core.shared.DefaultDnFactory)2 LdapServer (org.apache.directory.server.ldap.LdapServer)2 FileNotFoundException (java.io.FileNotFoundException)1