Search in sources :

Example 71 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project sonarqube by SonarSource.

the class ApacheDS method importLdif.

/**
 * Stream will be closed automatically.
 */
public void importLdif(InputStream is) throws Exception {
    try (LdifReader reader = new LdifReader(is)) {
        CoreSession coreSession = directoryService.getAdminSession();
        // see LdifFileLoader
        for (LdifEntry ldifEntry : reader) {
            String ldif = ldifEntry.toString();
            LOG.info(ldif);
            if (ChangeType.Add == ldifEntry.getChangeType() || /* assume "add" by default */
            ChangeType.None == ldifEntry.getChangeType()) {
                coreSession.add(new DefaultEntry(coreSession.getDirectoryService().getSchemaManager(), ldifEntry.getEntry()));
            } else if (ChangeType.Modify == ldifEntry.getChangeType()) {
                coreSession.modify(ldifEntry.getDn(), ldifEntry.getModifications());
            } else if (ChangeType.Delete == ldifEntry.getChangeType()) {
                coreSession.delete(ldifEntry.getDn());
            } else {
                throw new IllegalStateException();
            }
        }
    }
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) CoreSession(org.apache.directory.server.core.api.CoreSession) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 72 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project qpid-broker-j by apache.

the class SimpleLDAPAuthenticationManagerTest method createPrincipal.

private void createPrincipal(final String sn, final String cn, final String uid, final String userPassword, final String kerberosPrincipalName) throws LdapException {
    final DirectoryService directoryService = LDAP.getDirectoryService();
    final Entry entry = new DefaultEntry(directoryService.getSchemaManager());
    entry.setDn(String.format("uid=%s,%s", uid, USERS_DN));
    entry.add("objectClass", "top", "person", "inetOrgPerson", "krb5principal", "krb5kdcentry");
    entry.add("cn", cn);
    entry.add("sn", sn);
    entry.add("uid", uid);
    entry.add("userPassword", userPassword);
    entry.add("krb5PrincipalName", kerberosPrincipalName);
    entry.add("krb5KeyVersionNumber", "0");
    directoryService.getAdminSession().add(entry);
}
Also used : KeytabEntry(org.apache.directory.server.kerberos.shared.keytab.KeytabEntry) 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) DirectoryService(org.apache.directory.server.core.api.DirectoryService)

Example 73 with DefaultEntry

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

the class GSSAPILdapLoginModuleTest method createPrincipal.

private void createPrincipal(String rdn, String sn, String cn, String uid, String userPassword, String principalName) throws LdapException {
    Entry entry = new DefaultEntry();
    entry.setDn(rdn + "," + USERS_DN);
    entry.add("objectClass", "top", "person", "inetOrgPerson", "krb5principal", "krb5kdcentry");
    entry.add("cn", cn);
    entry.add("sn", sn);
    entry.add("uid", uid);
    entry.add("userPassword", userPassword);
    entry.add("krb5PrincipalName", principalName);
    entry.add("krb5KeyVersionNumber", "0");
    conn.add(entry);
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) ContextEntry(org.apache.directory.server.core.annotations.ContextEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry)

Example 74 with DefaultEntry

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

the class Krb5LoginModuleTest method createPrincipal.

private void createPrincipal(String rdn, String sn, String cn, String uid, String userPassword, String principalName) throws LdapException {
    Entry entry = new DefaultEntry();
    entry.setDn(rdn + "," + USERS_DN);
    entry.add("objectClass", "top", "person", "inetOrgPerson", "krb5principal", "krb5kdcentry");
    entry.add("cn", cn);
    entry.add("sn", sn);
    entry.add("uid", uid);
    entry.add("userPassword", userPassword);
    entry.add("krb5PrincipalName", principalName);
    entry.add("krb5KeyVersionNumber", "0");
    conn.add(entry);
}
Also used : ContextEntry(org.apache.directory.server.core.annotations.ContextEntry) KeytabEntry(org.apache.directory.server.kerberos.shared.keytab.KeytabEntry) 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 75 with DefaultEntry

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

the class KerberosServerSetupTask method createLdap1.

//@formatter:off
@CreateDS(name = "JBossDS-KerberosServerSetupTask", 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")
@CreateKdcServer(primaryRealm = KERBEROS_PRIMARY_REALM, kdcPrincipal = "krbtgt/" + KERBEROS_PRIMARY_REALM + "@" + KERBEROS_PRIMARY_REALM, searchBaseDn = "dc=jboss,dc=org", transports = { @CreateTransport(protocol = "UDP", port = KERBEROS_PORT), @CreateTransport(protocol = "TCP", port = KERBEROS_PORT) })
public //@formatter:on
void createLdap1(ManagementClient managementClient, final String hostname) throws Exception {
    final Map<String, String> map = new HashMap<String, String>();
    final String cannonicalHost = NetworkUtils.formatPossibleIpv6Address(Utils.getCannonicalHost(managementClient));
    map.put("hostname", cannonicalHost);
    map.put("realm", KERBEROS_PRIMARY_REALM);
    directoryService1 = DSAnnotationProcessor.getDirectoryService();
    final String ldifContent = StrSubstitutor.replace(IOUtils.toString(KerberosServerSetupTask.class.getResourceAsStream(KerberosServerSetupTask.class.getSimpleName() + ".ldif"), "UTF-8"), map);
    LOGGER.trace(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, cannonicalHost);
    ldapServer1 = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService1);
    krbServer1 = KDCServerAnnotationProcessor.getKdcServer(directoryService1, KERBEROS_PORT, cannonicalHost);
    ldapServer1.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) CreateDS(org.apache.directory.server.core.annotations.CreateDS) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) CreateLdapServer(org.apache.directory.server.annotations.CreateLdapServer) CreateKdcServer(org.apache.directory.server.annotations.CreateKdcServer)

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