Search in sources :

Example 76 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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 77 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project midpoint by Evolveum.

the class AbstractAdLdapTest method createAccountEntry.

@Override
protected Entry createAccountEntry(String uid, String cn, String givenName, String sn) throws LdapException {
    byte[] password = encodePassword("Secret.123");
    Entry entry = new DefaultEntry(toAccountDn(uid, cn), "objectclass", getLdapAccountObjectClass(), ATTRIBUTE_SAM_ACCOUNT_NAME_NAME, uid, "cn", cn, "givenName", givenName, "sn", sn, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512", ATTRIBUTE_UNICODE_PWD_NAME, password);
    return entry;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry)

Example 78 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project midpoint by Evolveum.

the class AbstractAdLdapMultidomainTest method createAccountEntry.

@Override
protected Entry createAccountEntry(String uid, String cn, String givenName, String sn) throws LdapException {
    byte[] password = encodePassword("Secret.123");
    Entry entry = new DefaultEntry(toAccountDn(uid, cn), "objectclass", getLdapAccountObjectClass(), ATTRIBUTE_SAM_ACCOUNT_NAME_NAME, uid, "cn", cn, "givenName", givenName, "sn", sn, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512", ATTRIBUTE_UNICODE_PWD_NAME, password);
    return entry;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry)

Example 79 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project aws-iam-ldap-bridge by denismo.

the class Runner method createStructure.

public void createStructure() throws Exception {
    String rootDN = AWSIAMAuthenticator.getConfig().rootDN;
    Dn dnIAM = service.getDnFactory().create(rootDN);
    if (!utils.exists(dnIAM)) {
        IAM_LOG.info("Creating partition " + rootDN);
        Partition iamPartition = utils.addPartition("iam", rootDN, service.getDnFactory());
        // Index some attributes on the apache partition
        utils.addIndex(iamPartition, "objectClass", "ou", "uid", "gidNumber", "uidNumber", "cn");
        if (!utils.exists(dnIAM)) {
            IAM_LOG.info("Creating root node " + rootDN);
            Rdn rdn = dnIAM.getRdn(0);
            Entry entryIAM = new DefaultEntry(service.getSchemaManager(), dnIAM, "objectClass: top", "objectClass: domain", "entryCsn: " + service.getCSN(), SchemaConstants.ENTRY_UUID_AT + ": " + UUID.randomUUID().toString(), rdn.getType() + ": " + rdn.getValue());
            service.getAdminSession().add(entryIAM);
            checkErrors();
        }
    }
    service.sync();
}
Also used : Partition(org.apache.directory.server.core.api.partition.Partition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) AbstractBTreePartition(org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition) JdbmPartition(org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition) SingleFileLdifPartition(org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) IndexEntry(org.apache.directory.server.xdbm.IndexEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) ParentIdAndRdn(org.apache.directory.server.xdbm.ParentIdAndRdn) Rdn(org.apache.directory.api.ldap.model.name.Rdn)

Example 80 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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)128 Entry (org.apache.directory.api.ldap.model.entry.Entry)116 Test (org.junit.Test)55 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)41 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)39 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)20 Modification (org.apache.directory.api.ldap.model.entry.Modification)16 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)16 Dn (org.apache.directory.api.ldap.model.name.Dn)15 CreateException (org.apache.directory.fortress.core.CreateException)15 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)14 Value (org.apache.directory.api.ldap.model.entry.Value)12 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)12 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)5 IOException (java.io.IOException)4 ObjectInputStream (java.io.ObjectInputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4