Search in sources :

Example 6 with LdifReader

use of org.apache.directory.api.ldap.model.ldif.LdifReader 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)

Example 7 with LdifReader

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

the class AbstractServer method addEntry.

/**
     * Inject an ldif String into the server. DN must be relative to the
     * root.
     *
     * @param ldif the entries to inject
     * @throws NamingException if the entries cannot be added
     */
protected void addEntry(String ldif) throws Exception {
    ByteArrayInputStream in = new ByteArrayInputStream(ldif.getBytes("utf-8"));
    LdifReader reader = new LdifReader(in);
    loadLdif(reader);
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)7 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)6 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)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 ByteArrayInputStream (java.io.ByteArrayInputStream)2 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 TreeSet (java.util.TreeSet)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1 CreateKdcServer (org.apache.directory.server.annotations.CreateKdcServer)1 AddOperationContext (org.apache.directory.server.core.api.interceptor.context.AddOperationContext)1