Java Code Examples for org.apache.directory.api.ldap.model.name.Dn#apply()

The following examples show how to use org.apache.directory.api.ldap.model.name.Dn#apply() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * normalizes the given Dn if it was not already normalized
 *
 * @param dn the Dn to be normalized
 */
private void normalizeDN( Dn dn )
{
    if ( !dn.isSchemaAware() )
    {
        try
        {
            // The dn must be normalized
            dn.apply( schemaManager );
        }
        catch ( LdapException ne )
        {
            LOG.warn( "The Dn '{}' cannot be normalized", dn );
        }
    }
}
 
Example 2
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
{
    Dn base = searchContext.getDn();

    // TODO since we're handling the *, and + in the EntryFilteringCursor
    // we may not need this code: we need see if this is actually the
    // case and remove this code.
    if ( base.size() == 0 )
    {
        return searchFromRoot( searchContext );
    }

    // Not sure we need this code...
    base.apply( schemaManager );

    // Normal case : do a search on the specific partition
    Partition backend = getPartition( base );

    return backend.search( searchContext );
}
 
Example 3
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * normalizes the given Dn if it was not already normalized
 *
 * @param dn the Dn to be normalized
 */
private void normalizeDN( Dn dn )
{
    if ( !dn.isSchemaAware() )
    {
        try
        {
            // The dn must be normalized
            dn.apply( schemaManager );
        }
        catch ( LdapException ne )
        {
            LOG.warn( "The Dn '{}' cannot be normalized", dn );
        }
    }
}
 
Example 4
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
{
    Dn base = searchContext.getDn();

    // TODO since we're handling the *, and + in the EntryFilteringCursor
    // we may not need this code: we need see if this is actually the
    // case and remove this code.
    if ( base.size() == 0 )
    {
        return searchFromRoot( searchContext );
    }

    // Not sure we need this code...
    base.apply( schemaManager );

    // Normal case : do a search on the specific partition
    Partition backend = getPartition( base );

    return backend.search( searchContext );
}
 
Example 5
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Partition getPartition( Dn dn ) throws LdapException
{
    Partition parent = null;

    if ( !dn.isSchemaAware() )
    {
        dn.apply( schemaManager );
    }

    synchronized ( partitionLookupTree )
    {
        parent = partitionLookupTree.getElement( dn );
    }

    if ( parent == null )
    {
        throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_268, dn ) );
    }
    else
    {
        return parent;
    }
}
 
Example 6
Source File: LDAPIAMPoller.java    From aws-iam-ldap-bridge with Apache License 2.0 6 votes vote down vote up
private void clearDN(String dnStr) throws LdapException, ParseException, IOException, CursorException {
    Dn dn = directory.getDnFactory().create(dnStr);
    dn.apply(directory.getSchemaManager());
    ExprNode filter = FilterParser.parse(directory.getSchemaManager(), "(ObjectClass=*)");
    NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( directory.getSchemaManager() );
    FilterNormalizingVisitor visitor = new FilterNormalizingVisitor( ncn, directory.getSchemaManager() );
    filter.accept(visitor);
    SearchOperationContext context = new SearchOperationContext(directory.getAdminSession(),
            dn, SearchScope.SUBTREE, filter, SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES);
    EntryFilteringCursor cursor = directory.getPartitionNexus().search(context);
    cursor.beforeFirst();
    Collection<Dn> dns = new ArrayList<Dn>();
    while (cursor.next()) {
        Entry ent = cursor.get();
        if (ent.getDn().equals(dn)) continue;
        dns.add(ent.getDn());
    }
    cursor.close();

    LOG.debug("Deleting " + dns.size() + " items from under " + dnStr);
    for (Dn deleteDn: dns) {
        directory.getAdminSession().delete(deleteDn);
    }
}
 
Example 7
Source File: LDAPIAMPoller.java    From aws-iam-ldap-bridge with Apache License 2.0 6 votes vote down vote up
private Collection<Entry> getAllEntries(String rootDN, String className) {
    try {
        Dn dn = directory.getDnFactory().create(rootDN);
        dn.apply(directory.getSchemaManager());
        ExprNode filter = FilterParser.parse(directory.getSchemaManager(), String.format("(ObjectClass=%s)", className));
        NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( directory.getSchemaManager() );
        FilterNormalizingVisitor visitor = new FilterNormalizingVisitor( ncn, directory.getSchemaManager() );
        filter.accept(visitor);
        SearchOperationContext context = new SearchOperationContext(directory.getAdminSession(),
                dn, SearchScope.SUBTREE, filter, SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES);
        EntryFilteringCursor cursor = directory.getPartitionNexus().search(context);
        cursor.beforeFirst();
        Collection<Entry> entries = new ArrayList<Entry>();
        while (cursor.next()) {
            Entry ent = cursor.get();
            if (ent.getDn().equals(dn)) continue;
            entries.add(ent);
        }
        cursor.close();
        return entries;
    } catch (Throwable e) {
        return Collections.emptyList();
    }
}