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

The following examples show how to use org.apache.directory.api.ldap.model.name.Dn#isSchemaAware() . 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 directory-ldap-api 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
 * @return The normalized Dn
 */
private Dn normalizeDn( Dn dn )
{
    if ( !dn.isSchemaAware() )
    {
        try
        {
            // The dn must be normalized
            return new Dn( schemaManager, dn );
        }
        catch ( LdapException ne )
        {
            if ( LOG.isWarnEnabled() )
            {
                LOG.warn( I18n.msg( I18n.MSG_13201_DN_CANT_BE_NORMALIZED, dn ) );
            }

            return dn;
        }
    }
    else
    {
        return dn;
    }
}
 
Example 2
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 3
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of DefaultEntry, with a
 * Dn and a list of IDs.
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The Dn for this serverEntry. Can be null.
 * @param elements The list of attributes to create.
 * @throws LdapException If the provided Dn or Elements are invalid
 */
public DefaultEntry( SchemaManager schemaManager, Dn dn, Object... elements ) throws LdapException
{
    DefaultEntry entry = ( DefaultEntry ) createEntry( schemaManager, elements );

    this.dn = dn;
    this.attributes = entry.attributes;
    this.schemaManager = schemaManager;

    if ( schemaManager != null )
    {
        if ( !dn.isSchemaAware() )
        {
            this.dn = new Dn( schemaManager, dn );
        }

        initObjectClassAT();
    }
}
 
Example 4
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 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: NormalizationInterceptor.java    From syncope with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void add( AddOperationContext addContext ) throws LdapException
{
    Dn addDn = addContext.getDn();
    
    if ( !addDn.isSchemaAware() )
    {
        addContext.setDn( new Dn( schemaManager, addDn ) );
    }
    
    Dn entryDn = addContext.getEntry().getDn();
    
    if ( !entryDn.isSchemaAware() )
    {
        addContext.getEntry().setDn( new Dn( schemaManager, entryDn ) );
    }
    
    addRdnAttributesToEntry( addContext.getDn(), addContext.getEntry() );
    
    next( addContext );
}
 
Example 7
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void modify( ModifyOperationContext modifyContext ) throws LdapException
{
    Dn dn = modifyContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        modifyContext.setDn( new Dn( schemaManager, dn ) );
    }

    if ( modifyContext.getModItems() != null )
    {
        for ( Modification modification : modifyContext.getModItems() )
        {
            AttributeType attributeType = schemaManager.getAttributeType( modification.getAttribute().getId() );
            modification.apply( attributeType );
        }
    }

    next( modifyContext );
}
 
Example 8
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
{
    Dn dn = searchContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        searchContext.setDn( new Dn( schemaManager, dn ) );
    }

    ExprNode filter = searchContext.getFilter();

    if ( filter == null )
    {
        LOG.warn( "undefined filter based on undefined attributeType not evaluted at all.  Returning empty enumeration." );
        return new EntryFilteringCursorImpl( new EmptyCursor<Entry>(), searchContext, schemaManager );
    }

    // Normalize the filter
    filter = ( ExprNode ) filter.accept( normVisitor );

    if ( filter == null )
    {
        LOG.warn( "undefined filter based on undefined attributeType not evaluted at all.  Returning empty enumeration." );
        return new EntryFilteringCursorImpl( new EmptyCursor<Entry>(), searchContext, schemaManager );
    }

    // We now have to remove the (ObjectClass=*) filter if it's present, and to add the scope filter
    ExprNode modifiedFilter = removeObjectClass( filter );

    searchContext.setFilter( modifiedFilter );

    // TODO Normalize the returned Attributes, storing the UP attributes to format the returned values.
    return next( searchContext );
}
 
Example 9
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void rename( RenameOperationContext renameContext ) throws LdapException
{
    // Normalize the new Rdn and the Dn if needed
    Dn dn = renameContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        renameContext.setDn( new Dn( schemaManager, dn ) );
    }
    
    Rdn newRdn = renameContext.getNewRdn();
    
    if ( !newRdn.isSchemaAware() )
    {
        renameContext.setNewRdn( new Rdn( schemaManager, newRdn ) );
    }
    
    Dn newDn = renameContext.getNewDn();
    
    if ( !newDn.isSchemaAware() )
    {
        renameContext.setNewDn( new Dn( schemaManager, newDn ) );
    }

    // Push to the next interceptor
    next( renameContext );
}
 
Example 10
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
{
    Rdn newRdn = moveAndRenameContext.getNewRdn();
    
    if ( !newRdn.isSchemaAware() )
    {
        moveAndRenameContext.setNewRdn( new Rdn( schemaManager, newRdn ) );
    }
    
    Dn dn = moveAndRenameContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        moveAndRenameContext.setDn( new Dn( schemaManager, dn ) );
    }
    
    Dn newDn = moveAndRenameContext.getNewDn();
    
    if ( !newDn.isSchemaAware() )
    {
        moveAndRenameContext.setNewDn( new Dn( schemaManager, newDn ) );
    }
    
    Dn newSuperiorDn = moveAndRenameContext.getNewSuperiorDn();
    
    if ( !newSuperiorDn.isSchemaAware() )
    {
        moveAndRenameContext.setNewSuperiorDn( new Dn( schemaManager, newSuperiorDn ) );
    }

    next( moveAndRenameContext );
}
 
Example 11
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
{
    Dn dn = lookupContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        lookupContext.setDn( new Dn( schemaManager, dn ) );
    }

    return next( lookupContext );
}
 
Example 12
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
{
    Dn dn = hasEntryContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        hasEntryContext.setDn( new Dn( schemaManager, dn ) );
    }

    return next( hasEntryContext );
}
 
Example 13
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void delete( DeleteOperationContext deleteContext ) throws LdapException
{
    Dn dn = deleteContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        deleteContext.setDn( new Dn( schemaManager, dn ) );
    }

    next( deleteContext );
}
 
Example 14
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( CompareOperationContext compareContext ) throws LdapException
{
    Dn dn = compareContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        compareContext.setDn( new Dn( schemaManager, dn ) );
    }

    // Get the attributeType from the OID
    try
    {
        AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( compareContext.getOid() );

        // Translate the value from binary to String if the AT is HR
        if ( attributeType.getSyntax().isHumanReadable() && ( !compareContext.getValue().isHumanReadable() ) )
        {
            compareContext.setValue( compareContext.getValue() );
        }

        compareContext.setAttributeType( attributeType );
    }
    catch ( LdapException le )
    {
        throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) );
    }

    return next( compareContext );
}
 
Example 15
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void move( MoveOperationContext moveContext ) throws LdapException
{
    Dn moveDn = moveContext.getDn();
    
    if ( !moveDn.isSchemaAware() )
    {
        moveContext.setDn( new Dn( schemaManager, moveDn ) );
    }

    Dn oldSuperiorDn = moveContext.getOldSuperior();
    
    if ( !oldSuperiorDn.isSchemaAware() )
    {
        moveContext.setOldSuperior( new Dn( schemaManager, oldSuperiorDn ) );
    }

    Dn newSuperiorDn = moveContext.getNewSuperior();
    
    if ( !newSuperiorDn.isSchemaAware() )
    {
        moveContext.setNewSuperior( new Dn( schemaManager, newSuperiorDn ) );
    }
    
    Dn newDn = moveContext.getNewDn();
    
    if ( !newDn.isSchemaAware() )
    {
        moveContext.setNewDn( new Dn( schemaManager, newDn ) );
    }

    Rdn rdn = moveContext.getRdn();
    
    if ( !rdn.isSchemaAware() )
    {
        moveContext.setRdn( new Rdn( schemaManager, rdn ) );
    }

    next( moveContext );
}
 
Example 16
Source File: SearchRequestHandler.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * <p>
 * Determines if a search request is a subSchemaSubEntry search.
 * </p>
 * <p>
 * It is a schema search if:
 * - the base Dn is the Dn of the subSchemaSubEntry of the root DSE
 * - and the scope is BASE OBJECT
 * - and the filter is (objectClass=subschema)
 * (RFC 4512, 4.4,)
 * </p>
 * <p>
 * However in this method we only check the first condition to avoid
 * performance issues.
 * </p>
 *
 * @param session the LDAP session
 * @param req the request issued
 *
 * @return true if the search is on the subSchemaSubEntry, false otherwise
 *
 * @throws Exception the exception
 */
private boolean isSubSchemaSubEntrySearch( LdapSession session, SearchRequest req ) throws Exception
{
    Dn base = req.getBase();
    String baseNormForm = ( base.isSchemaAware() ? base.getNormName() : base.getNormName() );

    DirectoryService ds = session.getCoreSession().getDirectoryService();
    PartitionNexus nexus = ds.getPartitionNexus();

    if ( SUBSCHEMA_SUBENTRY_AT == null )
    {
        SUBSCHEMA_SUBENTRY_AT = session.getCoreSession().getDirectoryService().getSchemaManager().getAttributeType(
            SchemaConstants.SUBSCHEMA_SUBENTRY_AT );
    }

    Value<?> subschemaSubentry = nexus.getRootDseValue( SUBSCHEMA_SUBENTRY_AT );
    Dn subschemaSubentryDn = ds.getDnFactory().create( subschemaSubentry.getString() );
    String subschemaSubentryDnNorm = subschemaSubentryDn.getNormName();

    return subschemaSubentryDnNorm.equals( baseNormForm );
}
 
Example 17
Source File: SearchRequestHandler.java    From MyVirtualDirectory with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * Determines if a search request is a subSchemaSubEntry search.
 * </p>
 * <p>
 * It is a schema search if:
 * - the base Dn is the Dn of the subSchemaSubEntry of the root DSE
 * - and the scope is BASE OBJECT
 * - and the filter is (objectClass=subschema)
 * (RFC 4512, 4.4,)
 * </p>
 * <p>
 * However in this method we only check the first condition to avoid
 * performance issues.
 * </p>
 *
 * @param session the LDAP session
 * @param req the request issued
 *
 * @return true if the search is on the subSchemaSubEntry, false otherwise
 *
 * @throws Exception the exception
 */
private boolean isSubSchemaSubEntrySearch( LdapSession session, SearchRequest req ) throws Exception
{
    Dn base = req.getBase();
    String baseNormForm = ( base.isSchemaAware() ? base.getNormName() : base.getNormName() );

    DirectoryService ds = session.getCoreSession().getDirectoryService();
    PartitionNexus nexus = ds.getPartitionNexus();
    Value<?> subschemaSubentry = nexus.getRootDse( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
    Dn subschemaSubentryDn = new Dn( ds.getSchemaManager(), subschemaSubentry.getString() );
    String subschemaSubentryDnNorm = subschemaSubentryDn.getNormName();

    return subschemaSubentryDnNorm.equals( baseNormForm );
}