Search in sources :

Example 6 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method writeBinaryAttribute.

public void writeBinaryAttribute(final String entryDN, final String attributeName, final byte[][] values, final boolean overwrite) throws ChaiUnavailableException, ChaiOperationException {
    activityPreCheck();
    getInputValidator().writeBinaryAttribute(entryDN, attributeName, values, overwrite);
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, values));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 7 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method writeStringAttribute.

public void writeStringAttribute(final String entryDN, final String attributeName, final Set<String> values, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().writeStringAttribute(entryDN, attributeName, values, overwrite);
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, values.toArray(new String[values.size()])));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 8 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project jackrabbit-oak by apache.

the class LdapIdentityProvider method getDeclaredGroupRefs.

// -----------------------------------------------------------< internal >---
/**
 * Collects the declared (direct) groups of an identity
 * @param ref reference to the identity
 * @return map of identities where the key is the DN of the LDAP entity
 */
Map<String, ExternalIdentityRef> getDeclaredGroupRefs(ExternalIdentityRef ref) throws ExternalIdentityException {
    if (!isMyRef(ref)) {
        return Collections.emptyMap();
    }
    String searchFilter = config.getMemberOfSearchFilter(ref.getId());
    LdapConnection connection = null;
    SearchCursor searchCursor = null;
    try {
        // Create the SearchRequest object
        SearchRequest req = new SearchRequestImpl();
        req.setScope(SearchScope.SUBTREE);
        String idAttribute = config.getGroupConfig().getIdAttribute();
        req.addAttributes(idAttribute == null ? SchemaConstants.NO_ATTRIBUTE : idAttribute);
        req.setTimeLimit((int) config.getSearchTimeout());
        req.setBase(new Dn(config.getGroupConfig().getBaseDN()));
        req.setFilter(searchFilter);
        if (log.isDebugEnabled()) {
            log.debug("getDeclaredGroupRefs: using SearchRequest {}.", req);
        }
        Map<String, ExternalIdentityRef> groups = new HashMap<String, ExternalIdentityRef>();
        DebugTimer timer = new DebugTimer();
        connection = connect();
        timer.mark("connect");
        searchCursor = connection.search(req);
        timer.mark("search");
        while (searchCursor.next()) {
            Response response = searchCursor.get();
            if (response instanceof SearchResultEntry) {
                Entry resultEntry = ((SearchResultEntry) response).getEntry();
                ExternalIdentityRef groupRef = new ExternalIdentityRef(resultEntry.getDn().toString(), this.getName());
                groups.put(groupRef.getId(), groupRef);
            }
        }
        timer.mark("iterate");
        if (log.isDebugEnabled()) {
            log.debug("getDeclaredGroupRefs: search below {} with {} found {} entries. {}", config.getGroupConfig().getBaseDN(), searchFilter, groups.size(), timer.getString());
        }
        return groups;
    } catch (Exception e) {
        log.error("Error during ldap membership search.", e);
        throw new ExternalIdentityException("Error during ldap membership search.", e);
    } finally {
        if (searchCursor != null) {
            try {
                searchCursor.close();
            } catch (IOException e) {
                log.warn("Failed to close search cursor.", e);
            }
        }
        disconnect(connection);
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) HashMap(java.util.HashMap) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) SearchRequestImpl(org.apache.directory.api.ldap.model.message.SearchRequestImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) IOException(java.io.IOException) LoginException(javax.security.auth.login.LoginException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) ExternalIdentityException(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) DebugTimer(org.apache.jackrabbit.oak.commons.DebugTimer) Response(org.apache.directory.api.ldap.model.message.Response) Entry(org.apache.directory.api.ldap.model.entry.Entry) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) ExternalIdentityException(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry)

Example 9 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project syncope by apache.

the class ApacheDSStartStopListener method initDirectoryService.

/**
 * Initialize the server. It creates the partition, adds the index, and injects the context entries for the created
 * partitions.
 *
 * @param workDir the directory to be used for storing the data
 * @param loadDefaultContent if default content should be loaded
 * @throws Exception if there were some problems while initializing
 */
private void initDirectoryService(final ServletContext servletContext, final File workDir, final boolean loadDefaultContent) throws Exception {
    // Initialize the LDAP service
    service = new DefaultDirectoryService();
    service.setInstanceLayout(new InstanceLayout(workDir));
    CacheService cacheService = new CacheService();
    cacheService.initialize(service.getInstanceLayout());
    service.setCacheService(cacheService);
    // first load the schema
    initSchemaPartition();
    // then the system partition
    // this is a MANDATORY partition
    // DO NOT add this via addPartition() method, trunk code complains about duplicate partition
    // while initializing
    JdbmPartition systemPartition = new JdbmPartition(service.getSchemaManager(), service.getDnFactory());
    systemPartition.setId("system");
    systemPartition.setPartitionPath(new File(service.getInstanceLayout().getPartitionsDirectory(), systemPartition.getId()).toURI());
    systemPartition.setSuffixDn(new Dn(ServerDNConstants.SYSTEM_DN));
    systemPartition.setSchemaManager(service.getSchemaManager());
    // mandatory to call this method to set the system partition
    // Note: this system partition might be removed from trunk
    service.setSystemPartition(systemPartition);
    // Disable the ChangeLog system
    service.getChangeLog().setEnabled(false);
    service.setDenormalizeOpAttrsEnabled(true);
    // Now we can create as many partitions as we need
    Partition ispPartition = addPartition("isp", "o=isp", service.getDnFactory());
    // Index some attributes on the apache partition
    addIndex(ispPartition, "objectClass", "ou", "uid");
    // And start the service
    service.startup();
    if (loadDefaultContent) {
        Resource contentLdif = WebApplicationContextUtils.getWebApplicationContext(servletContext).getResource("classpath:/content.ldif");
        LdifInputStreamLoader contentLoader = new LdifInputStreamLoader(service.getAdminSession(), contentLdif.getInputStream());
        int numEntries = contentLoader.execute();
        LOG.info("Successfully created {} entries", numEntries);
    }
}
Also used : DefaultDirectoryService(org.apache.directory.server.core.DefaultDirectoryService) InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) Partition(org.apache.directory.server.core.api.partition.Partition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) JdbmPartition(org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) JdbmPartition(org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition) Resource(org.springframework.core.io.Resource) Dn(org.apache.directory.api.ldap.model.name.Dn) File(java.io.File) CacheService(org.apache.directory.server.core.api.CacheService)

Example 10 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project syncope by apache.

the class ApacheDSStartStopListener method contextInitialized.

/**
 * Startup ApacheDS embedded.
 *
 * @param sce ServletContext event
 */
@Override
public void contextInitialized(final ServletContextEvent sce) {
    File workDir = (File) sce.getServletContext().getAttribute("javax.servlet.context.tempdir");
    workDir = new File(workDir, "server-work");
    final boolean loadDefaultContent = !workDir.exists();
    if (loadDefaultContent && !workDir.mkdirs()) {
        throw new RuntimeException("Could not create " + workDir.getAbsolutePath());
    }
    Entry result;
    try {
        initDirectoryService(sce.getServletContext(), workDir, loadDefaultContent);
        server = new LdapServer();
        server.setTransports(new TcpTransport(Integer.parseInt(WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean("testds.port", String.class))));
        server.setDirectoryService(service);
        server.start();
        // store directoryService in context to provide it to servlets etc.
        sce.getServletContext().setAttribute(DirectoryService.JNDI_KEY, service);
        result = service.getAdminSession().lookup(new Dn("o=isp"));
    } catch (Exception e) {
        LOG.error("Fatal error in context init", e);
        throw new RuntimeException(e);
    }
    if (result == null) {
        throw new RuntimeException("Base DN not found");
    } else {
        LOG.info("ApacheDS startup completed succesfully");
    }
}
Also used : LdapServer(org.apache.directory.server.ldap.LdapServer) Entry(org.apache.directory.api.ldap.model.entry.Entry) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) Dn(org.apache.directory.api.ldap.model.name.Dn) File(java.io.File)

Aggregations

Dn (org.apache.directory.api.ldap.model.name.Dn)307 Test (org.junit.Test)183 Rdn (org.apache.directory.api.ldap.model.name.Rdn)63 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)50 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)39 Entry (org.apache.directory.api.ldap.model.entry.Entry)34 DnNode (org.apache.directory.api.ldap.util.tree.DnNode)30 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)20 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)19 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)17 Modification (org.apache.directory.api.ldap.model.entry.Modification)17 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)16 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)10 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)10 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)10 Referral (org.apache.directory.api.ldap.model.message.Referral)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)8 Value (org.apache.directory.api.ldap.model.entry.Value)8