Search in sources :

Example 1 with LdifEntry

use of org.apache.directory.api.ldap.model.ldif.LdifEntry in project jackrabbit-oak by apache.

the class AbstractServer method loadLdif.

protected List<LdifEntry> loadLdif(LdifReader ldifReader) throws Exception {
    List<LdifEntry> entries = new ArrayList<LdifEntry>();
    for (LdifEntry ldifEntry : ldifReader) {
        Dn dn = ldifEntry.getDn();
        if (ldifEntry.isEntry()) {
            org.apache.directory.api.ldap.model.entry.Entry items = ldifEntry.getEntry();
            rootDSE.add(new DefaultEntry(directoryService.getSchemaManager(), items));
            LOG.info("Added entry {}", dn);
            entries.add(ldifEntry);
        }
    }
    return entries;
}
Also used : ArrayList(java.util.ArrayList) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 2 with LdifEntry

use of org.apache.directory.api.ldap.model.ldif.LdifEntry in project wildfly by wildfly.

the class LdapExtLDAPServerSetupTask method createLdap2.

//@formatter:off
@CreateDS(name = "JBossComDS", factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class, partitions = { @CreatePartition(name = "jbossCom", suffix = "dc=jboss,dc=com", contextEntry = @ContextEntry(entryLdif = "dn: dc=jboss,dc=com\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n"), indexes = { @CreateIndex(attribute = "objectClass"), @CreateIndex(attribute = "dc"), @CreateIndex(attribute = "ou") }), @CreatePartition(name = "jbossOrg", 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_PORT2) })
public //@formatter:on
void createLdap2(final String hostname) throws Exception {
    directoryService2 = DSAnnotationProcessor.getDirectoryService();
    final SchemaManager schemaManager = directoryService2.getSchemaManager();
    try {
        for (LdifEntry ldifEntry : new LdifReader(LdapExtLoginModuleTestCase.class.getResourceAsStream(LdapExtLoginModuleTestCase.class.getSimpleName() + "2.ldif"))) {
            directoryService2.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer((CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class));
    fixTransportAddress(createLdapServer, hostname);
    ldapServer2 = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService2);
    ldapServer2.start();
    LOGGER.trace("ldapServer2 = " + ldapServer2);
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) 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)

Example 3 with LdifEntry

use of org.apache.directory.api.ldap.model.ldif.LdifEntry in project wildfly by wildfly.

the class LdapServerSetupTask method startLdapServer.

@CreateDS(name = "JBossDS-LdapServerSetupTask", 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 startLdapServer(final String hostname) throws Exception, IOException, ClassNotFoundException, FileNotFoundException {
    final Map<String, String> map = new HashMap<String, String>();
    map.put("hostname", NetworkUtils.formatPossibleIpv6Address(hostname));
    directoryService = DSAnnotationProcessor.getDirectoryService();
    final String ldifContent = StrSubstitutor.replace(IOUtils.toString(LdapServerSetupTask.class.getResourceAsStream("picketlink-idm-tests.ldif"), "UTF-8"), map);
    final SchemaManager schemaManager = directoryService.getSchemaManager();
    try {
        for (LdifEntry ldifEntry : new LdifReader(IOUtils.toInputStream(ldifContent))) {
            directoryService.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);
    ldapServer = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService);
    ldapServer.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) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) CreateDS(org.apache.directory.server.core.annotations.CreateDS) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) CreateLdapServer(org.apache.directory.server.annotations.CreateLdapServer)

Example 4 with LdifEntry

use of org.apache.directory.api.ldap.model.ldif.LdifEntry in project wildfly by wildfly.

the class InMemorySchemaPartition method doInit.

/**
     * Partition initialization - loads schema entries from the files on classpath.
     *
     * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit()
     */
@Override
protected void doInit() throws Exception {
    if (initialized)
        return;
    LOG.debug("Initializing schema partition " + getId());
    suffixDn.apply(schemaManager);
    super.doInit();
    // load schema
    final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*"));
    for (String resourcePath : new TreeSet<String>(resMap.keySet())) {
        if (resourcePath.endsWith(".ldif")) {
            URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file");
            LdifReader reader = new LdifReader(resource.openStream());
            LdifEntry ldifEntry = reader.next();
            reader.close();
            Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
            // add mandatory attributes
            if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) {
                entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString());
            }
            if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
                entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
            }
            AddOperationContext addContext = new AddOperationContext(null, entry);
            super.add(addContext);
        }
    }
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) TreeSet(java.util.TreeSet) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) AddOperationContext(org.apache.directory.server.core.api.interceptor.context.AddOperationContext) URL(java.net.URL) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 5 with LdifEntry

use of org.apache.directory.api.ldap.model.ldif.LdifEntry in project undertow by undertow-io.

the class KerberosKDCUtil method processLdif.

private static void processLdif(final SchemaManager schemaManager, final CoreSession adminSession, final String ldifName, final Map<String, String> mappings) throws Exception {
    InputStream resourceInput = KerberosKDCUtil.class.getResourceAsStream("/ldif/" + ldifName);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(resourceInput.available());
    int current;
    while ((current = resourceInput.read()) != -1) {
        if (current == '$') {
            // Enter String replacement mode.
            int second = resourceInput.read();
            if (second == '{') {
                ByteArrayOutputStream substitute = new ByteArrayOutputStream();
                while ((current = resourceInput.read()) != -1 && current != '}') {
                    substitute.write(current);
                }
                if (current == -1) {
                    baos.write(current);
                    baos.write(second);
                    // Terminator never found.
                    baos.write(substitute.toByteArray());
                }
                String toReplace = new String(substitute.toByteArray(), StandardCharsets.UTF_8);
                if (mappings.containsKey(toReplace)) {
                    baos.write(mappings.get(toReplace).getBytes());
                } else {
                    throw new IllegalArgumentException(String.format("No mapping found for '%s'", toReplace));
                }
            } else {
                baos.write(current);
                baos.write(second);
            }
        } else {
            baos.write(current);
        }
    }
    ByteArrayInputStream ldifInput = new ByteArrayInputStream(baos.toByteArray());
    LdifReader ldifReader = new LdifReader(ldifInput);
    for (LdifEntry ldifEntry : ldifReader) {
        adminSession.add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
    }
    ldifReader.close();
    ldifInput.close();
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Aggregations

DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)7 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)7 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)6 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)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 FileOutputStream (java.io.FileOutputStream)3 HashMap (java.util.HashMap)3 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1 CreateKdcServer (org.apache.directory.server.annotations.CreateKdcServer)1