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

The following examples show how to use org.apache.directory.api.ldap.model.name.Dn#equals() . 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: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to make sure the entry being deleted exists, and has no children, otherwise throws the appropriate
 * LdapException.
 */
public void delete( DeleteOperationContext deleteContext ) throws LdapException
{
    Dn dn = deleteContext.getDn();

    if ( dn.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_253,
            subschemSubentryDn ) );
    }

    next( deleteContext );

    // Update the alias cache
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( dn.getNormName() ) )
        {
            notAliasCache.remove( dn.getNormName() );
        }
    }
}
 
Example 2
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void move( MoveOperationContext moveContext ) throws LdapException
{
    Dn oriChildName = moveContext.getDn();

    if ( oriChildName.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
            subschemSubentryDn, subschemSubentryDn ) );
    }

    next( moveContext );

    // Remove the original entry from the NotAlias cache, if needed
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( oriChildName.getNormName() ) )
        {
            notAliasCache.remove( oriChildName.getNormName() );
        }
    }
}
 
Example 3
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
{
    Dn oldDn = moveAndRenameContext.getDn();

    // Don't allow M&R in the SSSE
    if ( oldDn.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
            subschemSubentryDn, subschemSubentryDn ) );
    }

    // Remove the original entry from the NotAlias cache, if needed
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( oldDn.getNormName() ) )
        {
            notAliasCache.remove( oldDn.getNormName() );
        }
    }

    next( moveAndRenameContext );
}
 
Example 4
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to make sure the entry being deleted exists, and has no children, otherwise throws the appropriate
 * LdapException.
 */
public void delete( DeleteOperationContext deleteContext ) throws LdapException
{
    Dn dn = deleteContext.getDn();

    if ( dn.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_253,
            subschemSubentryDn ) );
    }

    next( deleteContext );

    // Update the alias cache
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( dn.getNormName() ) )
        {
            notAliasCache.remove( dn.getNormName() );
        }
    }
}
 
Example 5
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void move( MoveOperationContext moveContext ) throws LdapException
{
    Dn oriChildName = moveContext.getDn();

    if ( oriChildName.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
            subschemSubentryDn, subschemSubentryDn ) );
    }

    next( moveContext );

    // Remove the original entry from the NotAlias cache, if needed
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( oriChildName.getNormName() ) )
        {
            notAliasCache.remove( oriChildName.getNormName() );
        }
    }
}
 
Example 6
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
{
    Dn oldDn = moveAndRenameContext.getDn();

    // Don't allow M&R in the SSSE
    if ( oldDn.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
            subschemSubentryDn, subschemSubentryDn ) );
    }

    // Remove the original entry from the NotAlias cache, if needed
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( oldDn.getNormName() ) )
        {
            notAliasCache.remove( oldDn.getNormName() );
        }
    }

    next( moveAndRenameContext );
}
 
Example 7
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
{
    Dn dn = lookupContext.getDn();

    if ( dn.equals( subschemSubentryDn ) )
    {
        return new ClonedServerEntry( rootDse.clone() );
    }

    // This is for the case we do a lookup on the rootDSE
    if ( dn.isRootDse() )
    {
        Entry retval = new ClonedServerEntry( rootDse );

        return retval;
    }

    Partition partition = getPartition( dn );
    Entry entry = partition.lookup( lookupContext );

    if ( entry == null )
    {
        LdapNoSuchObjectException e = new LdapNoSuchObjectException( "Attempt to lookup non-existant entry: "
            + dn.getName() );

        throw e;
    }

    return entry;
}
 
Example 8
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
{
    Dn dn = lookupContext.getDn();

    if ( dn.equals( subschemSubentryDn ) )
    {
        return new ClonedServerEntry( rootDse.clone() );
    }

    // This is for the case we do a lookup on the rootDSE
    if ( dn.isRootDse() )
    {
        Entry retval = new ClonedServerEntry( rootDse );

        return retval;
    }

    Partition partition = getPartition( dn );
    Entry entry = partition.lookup( lookupContext );

    if ( entry == null )
    {
        LdapNoSuchObjectException e = new LdapNoSuchObjectException( "Attempt to lookup non-existant entry: "
            + dn.getName() );

        throw e;
    }

    return entry;
}
 
Example 9
Source File: BindRequestImpl.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean equals( Object obj )
{
    if ( obj == this )
    {
        return true;
    }

    if ( !( obj instanceof BindRequest ) )
    {
        return false;
    }

    if ( !super.equals( obj ) )
    {
        return false;
    }

    BindRequest req = ( BindRequest ) obj;

    if ( req.isSimple() != isSimple() )
    {
        return false;
    }

    if ( req.isVersion3() != isVersion3() )
    {
        return false;
    }

    String name1 = req.getName();
    String name2 = getName();

    if ( Strings.isEmpty( name1 ) )
    {
        if ( !Strings.isEmpty( name2 ) )
        {
            return false;
        }
    }
    else
    {
        if ( Strings.isEmpty( name2 ) )
        {
            return false;
        }
        else if ( !name2.equals( name1 ) )
        {
            return false;
        }
    }

    Dn dn1 = req.getDn();
    Dn dn2 = getDn();

    if ( Dn.isNullOrEmpty( dn1 ) )
    {
        if ( !Dn.isNullOrEmpty( dn2 ) )
        {
            return false;
        }
    }
    else
    {
        if ( Dn.isNullOrEmpty( dn2 ) )
        {
            return false;
        }
        else if ( !dn1.equals( dn2 ) )
        {
            return false;
        }
    }

    return Arrays.equals( req.getCredentials(), getCredentials() );
}
 
Example 10
Source File: ParsedDnComparator.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int compare( Object obj0, Object obj1 )
{
    Dn dn0 = null;
    Dn dn1 = null;

    try
    {
        dn0 = getDn( obj0 );
        dn1 = getDn( obj1 );
    }
    catch ( LdapException e )
    {
        // -- what do we do here ?
        return -1;
    }

    int dn0Size = dn0.getRdns().size();
    int dn1Size = dn1.getRdns().size();
    
    // check the equality first, cause
    // when both DNs are equal checking isAncestorOf() returns true
    if ( dn0.equals( dn1 ) )
    {
        return 0;
    }
    else if ( dn0Size > dn1Size )
    {
        return -1;
    }
    else if ( dn1Size > dn0Size )
    {
        return 1;
    }

    for ( int i = dn0Size - 1; i >= 0; i-- )
    {
        int comp = dn0.getRdn( i ).compareTo( dn1.getRdn( i ) );
        
        if ( comp != 0 )
        {
            return comp;
        }
    }
    
    return 0;
}
 
Example 11
Source File: DnComparator.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int compare( Object obj0, Object obj1 )
{
    if ( ( obj0 instanceof String ) && ( obj1 instanceof String ) )
    {
        return compare( ( String ) obj0, ( String ) obj1 );
    }
    
    Dn dn0 = null;
    Dn dn1 = null;

    try
    {
        dn0 = getDn( obj0 );
        dn1 = getDn( obj1 );
    }
    catch ( LdapException e )
    {
        // -- what do we do here ?
        return -1;
    }

    int dn0Size = dn0.getRdns().size();
    int dn1Size = dn1.getRdns().size();
    
    // check the equality first, cause
    // when both DNs are equal checking isAncestorOf() returns true
    if ( dn0.equals( dn1 ) )
    {
        return 0;
    }
    else if ( dn0Size > dn1Size )
    {
        return -1;
    }
    else if ( dn1Size > dn0Size )
    {
        return 1;
    }

    for ( int i = dn0Size - 1; i >= 0; i-- )
    {
        int comp = dn0.getRdn( i ).compareTo( dn1.getRdn( i ) );
        
        if ( comp != 0 )
        {
            return comp;
        }
    }
    
    return 0;
}
 
Example 12
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void moveAndRename( Dn entryDn, Dn newDn, boolean deleteOldRdn ) throws LdapException
{
    // Check the parameters first
    if ( entryDn == null )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_04142_NULL_ENTRY_DN ) );
    }

    if ( entryDn.isRootDse() )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_04143_CANNOT_MOVE_ROOT_DSE ) );
    }

    if ( newDn == null )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_04144_NULL_NEW_DN ) );
    }

    if ( newDn.isRootDse() )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_04145_ROOT_DSE_CANNOT_BE_TARGET ) );
    }

    // Create the request
    ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
    modDnRequest.setName( entryDn );
    modDnRequest.setNewRdn( newDn.getRdn() );
    
    // Check if we really need to specify newSuperior.
    // newSuperior is optional [RFC4511, section 4.9]
    // Some servers (e.g. OpenDJ 2.6) require a special privilege if
    // newSuperior is specified even if it is the same as the old one. Therefore let's not
    // specify it if we do not need it. This is better interoperability. 
    Dn newDnParent = newDn.getParent();
    if ( newDnParent != null && !newDnParent.equals( entryDn.getParent() ) )
    {
        modDnRequest.setNewSuperior( newDnParent );
    }
    
    modDnRequest.setDeleteOldRdn( deleteOldRdn );

    ModifyDnResponse modifyDnResponse = modifyDn( modDnRequest );

    processResponse( modifyDnResponse );
}
 
Example 13
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * In the pre-invocation state this interceptor method checks to see if the entry to be added already exists.  If it
 * does an exception is raised.
 */
public void add( AddOperationContext addContext ) throws LdapException
{
    Dn name = addContext.getDn();

    if ( subschemSubentryDn.equals( name ) )
    {
        throw new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_249 ) );
    }

    Dn suffix = nexus.getSuffixDn( name );

    // we're adding the suffix entry so just ignore stuff to mess with the parent
    if ( suffix.equals( name ) )
    {
        next( addContext );
        return;
    }

    Dn parentDn = name.getParent();

    // check if we're trying to add to a parent that is an alias
    boolean notAnAlias;

    synchronized ( notAliasCache )
    {
        notAnAlias = notAliasCache.containsKey( parentDn.getNormName() );
    }

    /*if ( !notAnAlias )
    {
        // We don't know if the parent is an alias or not, so we will launch a
        // lookup, and update the cache if it's not an alias
        Entry attrs;

        try
        {
            CoreSession session = addContext.getSession();
            LookupOperationContext lookupContext = new LookupOperationContext( session, parentDn, SchemaConstants.ALL_ATTRIBUTES_ARRAY );

            attrs = directoryService.getPartitionNexus().lookup( lookupContext );
        }
        catch ( Exception e )
        {
            LdapNoSuchObjectException e2 = new LdapNoSuchObjectException(
                I18n.err( I18n.ERR_251_PARENT_NOT_FOUND, parentDn.getName() ) );
            throw e2;
        }

        Attribute objectClass = ( ( ClonedServerEntry ) attrs ).getOriginalEntry().get(
            OBJECT_CLASS_AT );

        if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
        {
            String msg = I18n.err( I18n.ERR_252_ALIAS_WITH_CHILD_NOT_ALLOWED, name.getName(), parentDn.getName() );
            LdapAliasException e = new LdapAliasException( msg );
            //e.setResolvedName( DNFactory.create( parentDn.getName() ) );
            throw e;
        }
        else
        {
            synchronized ( notAliasCache )
            {
                notAliasCache.put( parentDn.getNormName(), parentDn );
            }
        }
    }*/

    next( addContext );
}
 
Example 14
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void modify( ModifyOperationContext modifyContext ) throws LdapException
{
    // A modification on a simple entry will be done in three steps :
    // - get the original entry (it should already been in the context)
    // - apply the modification on it
    // - check that the entry is still correct
    // - add the operational attributes (modifiersName/modifyTimeStamp)
    // - store the modified entry on the backend.
    //
    // A modification done on the schema is a bit different, as there is two more
    // steps
    // - We have to update the registries
    // - We have to modify the ou=schemaModifications entry
    //

    // First, check that the entry is either a subschemaSubentry or a schema element.
    // This is the case if it's a child of cn=schema or ou=schema
    Dn dn = modifyContext.getDn();

    // Gets the stored entry on which the modification must be applied
    if ( dn.equals( subschemaSubentryDn ) )
    {
        LOG.debug( "Modification attempt on schema subentry {}: \n{}", dn, modifyContext );

        // We can get rid of the modifiersName and modifyTimestamp, they are useless.
        List<Modification> mods = modifyContext.getModItems();
        List<Modification> cleanMods = new ArrayList<Modification>();

        for ( Modification mod : mods )
        {
            AttributeType at = ( ( DefaultModification ) mod ).getAttribute().getAttributeType();

            if ( !MODIFIERS_NAME_AT.equals( at ) && !MODIFY_TIMESTAMP_AT.equals( at ) && !ENTRY_CSN_AT.equals( at ) )
            {
                cleanMods.add( mod );
            }
        }

        modifyContext.setModItems( cleanMods );

        // Now that the entry has been modified, update the SSSE
        schemaSubEntryManager.modifySchemaSubentry( modifyContext, modifyContext
            .hasRequestControl( Cascade.OID ) );

        return;
    }

    Entry entry = modifyContext.getEntry();
    List<Modification> modifications = modifyContext.getModItems();
    checkModifyEntry( dn, entry, modifications );

    next( modifyContext );
}
 
Example 15
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * In the pre-invocation state this interceptor method checks to see if the entry to be added already exists.  If it
 * does an exception is raised.
 */
public void add( AddOperationContext addContext ) throws LdapException
{
    Dn name = addContext.getDn();

    if ( subschemSubentryDn.equals( name ) )
    {
        throw new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_249 ) );
    }

    Dn suffix = nexus.getSuffixDn( name );

    // we're adding the suffix entry so just ignore stuff to mess with the parent
    if ( suffix.equals( name ) )
    {
        next( addContext );
        return;
    }

    Dn parentDn = name.getParent();

    // check if we're trying to add to a parent that is an alias
    boolean notAnAlias;

    synchronized ( notAliasCache )
    {
        notAnAlias = notAliasCache.containsKey( parentDn.getNormName() );
    }

    /*if ( !notAnAlias )
    {
        // We don't know if the parent is an alias or not, so we will launch a
        // lookup, and update the cache if it's not an alias
        Entry attrs;

        try
        {
            CoreSession session = addContext.getSession();
            LookupOperationContext lookupContext = new LookupOperationContext( session, parentDn, SchemaConstants.ALL_ATTRIBUTES_ARRAY );

            attrs = directoryService.getPartitionNexus().lookup( lookupContext );
        }
        catch ( Exception e )
        {
            LdapNoSuchObjectException e2 = new LdapNoSuchObjectException(
                I18n.err( I18n.ERR_251_PARENT_NOT_FOUND, parentDn.getName() ) );
            throw e2;
        }

        Attribute objectClass = ( ( ClonedServerEntry ) attrs ).getOriginalEntry().get(
            OBJECT_CLASS_AT );

        if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
        {
            String msg = I18n.err( I18n.ERR_252_ALIAS_WITH_CHILD_NOT_ALLOWED, name.getName(), parentDn.getName() );
            LdapAliasException e = new LdapAliasException( msg );
            //e.setResolvedName( DNFactory.create( parentDn.getName() ) );
            throw e;
        }
        else
        {
            synchronized ( notAliasCache )
            {
                notAliasCache.put( parentDn.getNormName(), parentDn );
            }
        }
    }*/

    next( addContext );
}
 
Example 16
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void modify( ModifyOperationContext modifyContext ) throws LdapException
{
    // A modification on a simple entry will be done in three steps :
    // - get the original entry (it should already been in the context)
    // - apply the modification on it
    // - check that the entry is still correct
    // - add the operational attributes (modifiersName/modifyTimeStamp)
    // - store the modified entry on the backend.
    //
    // A modification done on the schema is a bit different, as there is two more
    // steps
    // - We have to update the registries
    // - We have to modify the ou=schemaModifications entry
    //

    // First, check that the entry is either a subschemaSubentry or a schema element.
    // This is the case if it's a child of cn=schema or ou=schema
    Dn dn = modifyContext.getDn();

    // Gets the stored entry on which the modification must be applied
    if ( dn.equals( subschemaSubentryDn ) )
    {
        LOG.debug( "Modification attempt on schema subentry {}: \n{}", dn, modifyContext );

        // We can get rid of the modifiersName and modifyTimestamp, they are useless.
        List<Modification> mods = modifyContext.getModItems();
        List<Modification> cleanMods = new ArrayList<Modification>();

        for ( Modification mod : mods )
        {
            AttributeType at = ( ( DefaultModification ) mod ).getAttribute().getAttributeType();

            if ( !MODIFIERS_NAME_AT.equals( at ) && !MODIFY_TIMESTAMP_AT.equals( at ) && !ENTRY_CSN_AT.equals( at ) )
            {
                cleanMods.add( mod );
            }
        }

        modifyContext.setModItems( cleanMods );

        // Now that the entry has been modified, update the SSSE
        schemaSubEntryManager.modifySchemaSubentry( modifyContext, modifyContext
            .hasRequestControl( Cascade.OID ) );

        return;
    }

    checkModifyEntry( modifyContext );

    next( modifyContext );
}