Search in sources :

Example 1 with DefaultEntry

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

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

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

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project SEPA by arces-wot.

the class LdapSecurityManager method addJwt.

@Override
public void addJwt(String uid, SignedJWT token) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] addToken " + uid + " uid=" + uid + ",ou=tokens," + prop.getBase(), "(objectclass=*)");
    bind();
    try {
        cursor = ldap.search("uid=" + uid + ",ou=tokens," + prop.getBase(), "(objectclass=*)", SearchScope.OBJECT, "*");
        if (!cursor.next()) {
            ldap.add(new DefaultEntry("uid=" + uid + ",ou=tokens," + prop.getBase(), "ObjectClass: top", "ObjectClass: account", "ObjectClass: javaSerializedObject", "javaClassName: " + token.getClass().getName(), "javaSerializedData: " + token.serialize()));
        } else {
            Modification replaceGn = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "javaSerializedData", token.serialize());
            ldap.modify("uid=" + uid + ",ou=tokens," + prop.getBase(), replaceGn);
        }
    } catch (LdapException | CursorException e) {
        logger.error("[LDAP] addToken exception " + e.getMessage());
        throw new SEPASecurityException("addToken exception " + e.getMessage());
    } finally {
        unbind();
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 5 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project SEPA by arces-wot.

the class LdapSecurityManager method storeCredentials.

@Override
public boolean storeCredentials(DigitalIdentity identity, String client_secret) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] storeCredentials " + identity + " secret: " + client_secret);
    byte[] password = PasswordUtil.createStoragePassword(client_secret.getBytes(), LdapSecurityConstants.HASH_METHOD_SSHA);
    bind();
    try {
        cursor = ldap.search("uid=" + identity.getUid() + ",ou=credentials," + prop.getBase(), "(objectclass=*)", SearchScope.OBJECT, "*");
        if (cursor.next())
            removeCredentials(identity);
        Entry entry = new DefaultEntry("uid=" + identity.getUid() + ",ou=credentials," + prop.getBase());
        entry.add("ObjectClass", "top");
        entry.add("ObjectClass", identity.getObjectClass());
        entry.add("ObjectClass", "uidObject");
        entry.add("ObjectClass", "simpleSecurityObject");
        entry.add("ObjectClass", "javaSerializedObject");
        if (identity.getObjectClass().equals("inetOrgPerson")) {
            entry.add("cn", ((UserIdentity) identity).getCommonName());
            entry.add("sn", ((UserIdentity) identity).getSurname());
        } else
            entry.add("cn", "Authorized Digital Identity " + identity.getUid());
        entry.add("uid", identity.getUid());
        entry.add("userPassword", password);
        entry.add("javaClassName", identity.getEndpointCredentials().getClass().getName());
        entry.add("javaSerializedData", identity.getEndpointCredentials().serialize());
        ldap.add(entry);
    } catch (LdapException | CursorException e) {
        logger.error("[LDAP] storeCredentials exception " + e.getMessage());
        throw new SEPASecurityException("storeCredentials exception " + e.getMessage());
    } finally {
        unbind();
    }
    return true;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

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