Search in sources :

Example 1 with DefaultSchemaManager

use of org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager in project aws-iam-ldap-bridge by denismo.

the class Runner method initSchemaPartition.

/**
 * initialize the schema manager and add the schema partition to diectory service
 *
 * @throws Exception if the schema LDIF files are not found on the classpath
 */
private void initSchemaPartition() throws Exception {
    InstanceLayout instanceLayout = service.getInstanceLayout();
    File schemaPartitionDirectory = new File(instanceLayout.getPartitionsDirectory(), "schema");
    // Extract the schema on disk (a brand new one) and load the registries
    if (schemaPartitionDirectory.exists()) {
        System.out.println("schema partition already exists, skipping schema extraction");
    } else {
        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(instanceLayout.getPartitionsDirectory());
        extractor.extractOrCopy();
    }
    SchemaLoader loader = new LdifSchemaLoader(schemaPartitionDirectory);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    // We have to load the schema now, otherwise we won't be able
    // to initialize the Partitions, as we won't be able to parse
    // and normalize their suffix Dn
    schemaManager.loadAllEnabled();
    List<Throwable> errors = schemaManager.getErrors();
    if (errors.size() != 0) {
        throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
    }
    service.setSchemaManager(schemaManager);
    // Init the LdifPartition with schema
    LdifPartition schemaLdifPartition = new LdifPartition(schemaManager, service.getDnFactory());
    schemaLdifPartition.setPartitionPath(schemaPartitionDirectory.toURI());
    // The schema partition
    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(schemaLdifPartition);
    service.setSchemaPartition(schemaPartition);
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) SchemaLoader(org.apache.directory.api.ldap.model.schema.registries.SchemaLoader) LdifSchemaLoader(org.apache.directory.api.ldap.schemaloader.LdifSchemaLoader) DefaultSchemaLdifExtractor(org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor) SchemaLdifExtractor(org.apache.directory.api.ldap.schemaextractor.SchemaLdifExtractor) DefaultSchemaManager(org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) LdifSchemaLoader(org.apache.directory.api.ldap.schemaloader.LdifSchemaLoader) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) SingleFileLdifPartition(org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition) DefaultSchemaLdifExtractor(org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor) File(java.io.File) DefaultSchemaManager(org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager)

Example 2 with DefaultSchemaManager

use of org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager in project goodies by sonatype.

the class LdapServer method start.

public void start() throws Exception {
    if (running) {
        throw new IllegalStateException("The LdapServer is already running");
    }
    long start = System.currentTimeMillis();
    if (port <= 0) {
        port = portRegistry.reservePort();
    }
    // an example that shows how to create and configure embedded apacheds instance
    // http://svn.apache.org/repos/asf/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DefaultDirectoryServiceFactory.java
    directoryService = new DefaultDirectoryService();
    // support multiple embedded ldap servers by assigning each one a distinct cache
    URL configURL = getClass().getClassLoader().getResource("directory-cacheservice.xml");
    Configuration config = ConfigurationFactory.parseConfiguration(configURL);
    config.setName(config.getName() + '_' + System.identityHashCode(this));
    directoryService.setCacheService(new CacheService(new CacheManager(config)));
    directoryService.setInstanceLayout(new InstanceLayout(workingDirectory));
    SchemaManager schemaManager = new DefaultSchemaManager();
    directoryService.setSchemaManager(schemaManager);
    // required by group mapping tests
    schemaManager.enable("nis");
    initPartitions(directoryService);
    ldapServer = new org.apache.directory.server.ldap.LdapServer();
    Transport transport = new TcpTransport(LOCALHOST, port);
    transport.setEnableSSL(ldapsKeystore != null);
    ldapServer.setTransports(transport);
    if (ldapsKeystore != null) {
        ldapServer.setKeystoreFile(ldapsKeystore.getCanonicalPath());
    }
    if (ldapsKeystorePassword != null) {
        ldapServer.setCertificatePassword(ldapsKeystorePassword);
    }
    ldapServer.setDirectoryService(directoryService);
    // allowed authentication mechanisms
    Authenticator[] authenticators;
    switch(authLevel) {
        case SIMPLE:
            authenticators = new Authenticator[] { new SimpleAuthenticator() };
            break;
        case STRONG:
            authenticators = new Authenticator[] { new StrongAuthenticator() };
            ldapServer.setSaslMechanismHandlers(saslHandlers);
            ldapServer.setSaslHost(LOCALHOST);
            ldapServer.setSaslRealms(Arrays.asList(getSaslRealm()));
            ldapServer.setSearchBaseDn(searchBaseDn);
            break;
        case NONE:
        default:
            directoryService.setAllowAnonymousAccess(true);
            authenticators = new Authenticator[] { new AnonymousAuthenticator(), new SimpleAuthenticator() };
            break;
    }
    AuthenticationInterceptor auth = (AuthenticationInterceptor) directoryService.getInterceptor(InterceptorEnum.AUTHENTICATION_INTERCEPTOR.getName());
    auth.setAuthenticators(authenticators);
    directoryService.startup();
    ldapServer.start();
    running = true;
    log.debug("Started LdapServer in {} ms", System.currentTimeMillis() - start);
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) Configuration(net.sf.ehcache.config.Configuration) AuthenticationInterceptor(org.apache.directory.server.core.authn.AuthenticationInterceptor) DefaultSchemaManager(org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) AnonymousAuthenticator(org.apache.directory.server.core.authn.AnonymousAuthenticator) URL(java.net.URL) DefaultDirectoryService(org.apache.directory.server.core.DefaultDirectoryService) StrongAuthenticator(org.apache.directory.server.core.authn.StrongAuthenticator) SimpleAuthenticator(org.apache.directory.server.core.authn.SimpleAuthenticator) CacheManager(net.sf.ehcache.CacheManager) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) Transport(org.apache.directory.server.protocol.shared.transport.Transport) AnonymousAuthenticator(org.apache.directory.server.core.authn.AnonymousAuthenticator) Authenticator(org.apache.directory.server.core.authn.Authenticator) SimpleAuthenticator(org.apache.directory.server.core.authn.SimpleAuthenticator) StrongAuthenticator(org.apache.directory.server.core.authn.StrongAuthenticator) CacheService(org.apache.directory.server.core.api.CacheService) DefaultSchemaManager(org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager)

Aggregations

SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)2 DefaultSchemaManager (org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager)2 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)2 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 CacheManager (net.sf.ehcache.CacheManager)1 Configuration (net.sf.ehcache.config.Configuration)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 SchemaLoader (org.apache.directory.api.ldap.model.schema.registries.SchemaLoader)1 SchemaLdifExtractor (org.apache.directory.api.ldap.schemaextractor.SchemaLdifExtractor)1 DefaultSchemaLdifExtractor (org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor)1 LdifSchemaLoader (org.apache.directory.api.ldap.schemaloader.LdifSchemaLoader)1 DefaultDirectoryService (org.apache.directory.server.core.DefaultDirectoryService)1 CacheService (org.apache.directory.server.core.api.CacheService)1 SchemaPartition (org.apache.directory.server.core.api.schema.SchemaPartition)1 AnonymousAuthenticator (org.apache.directory.server.core.authn.AnonymousAuthenticator)1 AuthenticationInterceptor (org.apache.directory.server.core.authn.AuthenticationInterceptor)1 Authenticator (org.apache.directory.server.core.authn.Authenticator)1