Java Code Examples for org.apache.directory.api.ldap.model.name.Dn#EMPTY_DN

The following examples show how to use org.apache.directory.api.ldap.model.name.Dn#EMPTY_DN . 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
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The String Dn for this serverEntry. Can be null.
 * @throws LdapInvalidDnException If the Dn is invalid
 */
public DefaultEntry( SchemaManager schemaManager, String dn ) throws LdapInvalidDnException
{
    this.schemaManager = schemaManager;

    if ( Strings.isEmpty( dn ) )
    {
        this.dn = Dn.EMPTY_DN;
    }
    else
    {
        this.dn = new Dn( schemaManager, dn );
    }

    // Initialize the ObjectClass object
    initObjectClassAT();
}
 
Example 2
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The Dn for this serverEntry. Can be null.
 */
public DefaultEntry( SchemaManager schemaManager, Dn dn )
{
    this.schemaManager = schemaManager;

    if ( dn == null )
    {
        this.dn = Dn.EMPTY_DN;
    }
    else
    {
        this.dn = normalizeDn( dn );
    }

    // Initialize the ObjectClass object
    initObjectClassAT();
}
 
Example 3
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The Dn for this serverEntry. Can be null.
 */
public DefaultEntry( SchemaManager schemaManager, Dn dn )
{
    this.schemaManager = schemaManager;

    if ( dn == null )
    {
        this.dn = Dn.EMPTY_DN;
    }
    else
    {
        this.dn = dn;
        normalizeDN( this.dn );
    }

    // Initialize the ObjectClass object
    initObjectClassAT();
}
 
Example 4
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The String Dn for this serverEntry. Can be null.
 * @throws LdapInvalidDnException If the Dn is invalid
 */
public DefaultEntry( SchemaManager schemaManager, String dn ) throws LdapInvalidDnException
{
    this.schemaManager = schemaManager;

    if ( Strings.isEmpty( dn ) )
    {
        this.dn = Dn.EMPTY_DN;
    }
    else
    {
        this.dn = new Dn( dn );
        normalizeDN( this.dn );
    }

    // Initialize the ObjectClass object
    initObjectClassAT();
}
 
Example 5
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The Dn for this serverEntry. Can be null.
 */
public DefaultEntry( SchemaManager schemaManager, Dn dn )
{
    this.schemaManager = schemaManager;

    if ( dn == null )
    {
        this.dn = Dn.EMPTY_DN;
    }
    else
    {
        this.dn = dn;
        normalizeDN( this.dn );
    }

    // Initialize the ObjectClass object
    initObjectClassAT();
}
 
Example 6
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The String Dn for this serverEntry. Can be null.
 * @throws LdapInvalidDnException If the Dn is invalid
 */
public DefaultEntry( SchemaManager schemaManager, String dn ) throws LdapInvalidDnException
{
    this.schemaManager = schemaManager;

    if ( Strings.isEmpty( dn ) )
    {
        this.dn = Dn.EMPTY_DN;
    }
    else
    {
        this.dn = new Dn( dn );
        normalizeDN( this.dn );
    }

    // Initialize the ObjectClass object
    initObjectClassAT();
}
 
Example 7
Source File: TestDnNode.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the addition of a Dn with three Rdn
 */
@Test
public void testAdd3LevelDNNoElem() throws LdapException
{
    DnNode<Dn> tree = new DnNode<Dn>( Dn.EMPTY_DN, null );
    Dn dn = new Dn( "dc=c,dc=b,dc=a" );

    tree.add( dn );

    assertNotNull( tree );

    Map<String, DnNode<Dn>> children = tree.getChildren();
    assertNotNull( children );

    assertEquals( 1, children.size() );
    assertNull( tree.getElement() );

    DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ).getNormName() );
    DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ).getNormName() );
    DnNode<Dn> level3 = level2.getChildren().get( new Rdn( "dc=c" ).getNormName() );

    assertNotNull( level3 );
    assertFalse( level3.hasElement() );
}
 
Example 8
Source File: DnNode.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of DnNode.
 *
 * @param dn the node's Dn
 * @param element the element to store
 */
public DnNode( Dn dn, N element )
{
    if ( ( dn == null ) || ( dn.isEmpty() ) )
    {
        children = new HashMap<>();
        this.nodeDn = Dn.EMPTY_DN;

        return;
    }

    try
    {
        DnNode<N> rootNode = createNode( dn, element, dn.size() );

        // Now copy back the created node into this
        this.children = rootNode.children;
        this.depth = rootNode.depth;
        this.nodeDn = rootNode.nodeDn;
        this.nodeElement = rootNode.nodeElement;
        this.nodeRdn = rootNode.nodeRdn;
        this.parent = null;
    }
    catch ( LdapException le )
    {
        // Special cas e: the Dn is empty, this is not allowed
        throw new IllegalArgumentException( le.getMessage(), le );
    }
}
 
Example 9
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 */
public DefaultEntry( SchemaManager schemaManager )
{
    this.schemaManager = schemaManager;
    dn = Dn.EMPTY_DN;

    // Initialize the ObjectClass object
    if ( schemaManager != null )
    {
        initObjectClassAT();
    }
}
 
Example 10
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 */
public DefaultEntry( SchemaManager schemaManager )
{
    this.schemaManager = schemaManager;
    dn = Dn.EMPTY_DN;

    // Initialize the ObjectClass object
    if ( schemaManager != null )
    {
        initObjectClassAT();
    }
}
 
Example 11
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 */
public DefaultEntry( SchemaManager schemaManager )
{
    this.schemaManager = schemaManager;
    dn = Dn.EMPTY_DN;

    // Initialize the ObjectClass object
    if ( schemaManager != null )
    {
        initObjectClassAT();
    }
}
 
Example 12
Source File: DnNode.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of DnNode.
 */
public DnNode()
{
    children = new HashMap<>();
    nodeDn = Dn.EMPTY_DN;
    nodeRdn = Rdn.EMPTY_RDN;
}
 
Example 13
Source File: CursorLdapReferralException.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * @return the remainingDn
 */
public Dn getRemainingDn()
{
    if ( ldapReferralException != null )
    {
        return ldapReferralException.getRemainingDn();
    }
    else
    {
        return Dn.EMPTY_DN;
    }
}
 
Example 14
Source File: StoreModifyDnRequestEntryName.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<ModifyDnRequest> container ) throws DecoderException
{
    ModifyDnRequest modifyDnRequest = container.getMessage();

    // Get the Value and store it in the modifyDNRequest
    TLV tlv = container.getCurrentTLV();

    // We have to handle the special case of a 0 length matched DN
    if ( tlv.getLength() == 0 )
    {
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException( I18n.err( I18n.ERR_05119_NULL_ENTRY ) );
    }
    else
    {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString( dnBytes );

        try
        {
            Dn entry = new Dn( dnStr );
            modifyDnRequest.setName( entry );
        }
        catch ( LdapInvalidDnException ine )
        {
            String msg = I18n.err( I18n.ERR_05113_INVALID_DN, dnStr, Strings.dumpBytes( dnBytes ) );
            LOG.error( I18n.err( I18n.ERR_05114_ERROR_MESSAGE, msg, ine.getMessage() ) );

            ModifyDnResponseImpl response = new ModifyDnResponseImpl( modifyDnRequest.getMessageId() );
            throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
                Dn.EMPTY_DN, ine );
        }
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05137_MODIFYING_DN, modifyDnRequest.getName() ) );
    }
}
 
Example 15
Source File: StoreCompareRequestEntryName.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<CompareRequest> container ) throws DecoderException
{
    CompareRequest compareRequest = container.getMessage();

    // Get the Value and store it in the CompareRequest
    TLV tlv = container.getCurrentTLV();

    // We have to handle the special case of a 0 length matched Dn
    if ( tlv.getLength() == 0 )
    {
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException( I18n.err( I18n.ERR_05119_NULL_ENTRY ) );
    }
    else
    {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString( dnBytes );

        try
        {
            Dn entry = new Dn( dnStr );
            compareRequest.setName( entry );
        }
        catch ( LdapInvalidDnException ine )
        {
            String msg = I18n.err( I18n.ERR_05113_INVALID_DN, dnStr, Strings.dumpBytes( dnBytes ) );
            LOG.error( I18n.err( I18n.ERR_05114_ERROR_MESSAGE, msg, ine.getMessage() ) );

            CompareResponseImpl response = new CompareResponseImpl( compareRequest.getMessageId() );
            throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
                Dn.EMPTY_DN, ine );
        }
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05123_COMPARING_DN, compareRequest.getName() ) );
    }
}
 
Example 16
Source File: InitDelRequest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<DeleteRequest> container ) throws DecoderException
{
    // Create the DeleteRequest LdapMessage instance and store it in the container
    DeleteRequest delRequest = new DeleteRequestImpl();
    delRequest.setMessageId( container.getMessageId() );
    container.setMessage( delRequest );

    // And store the Dn into it
    // Get the Value and store it in the DelRequest
    TLV tlv = container.getCurrentTLV();

    // We have to handle the special case of a 0 length matchedDN
    if ( tlv.getLength() == 0 )
    {
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException( I18n.err( I18n.ERR_05119_NULL_ENTRY ) );
    }
    else
    {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString( dnBytes );

        try
        {
            Dn entry = new Dn( dnStr );
            delRequest.setName( entry );
        }
        catch ( LdapInvalidDnException ine )
        {
            String msg = I18n.err( I18n.ERR_05120_INVALID_DELETE_DN, dnStr, 
                Strings.dumpBytes( dnBytes ), ine.getLocalizedMessage() );
            LOG.error( msg );

            DeleteResponseImpl response = new DeleteResponseImpl( delRequest.getMessageId() );
            throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
                Dn.EMPTY_DN, ine );
        }
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05124_DELETING_DN, delRequest.getName() ) );
    }

    // We can have an END transition
    container.setGrammarEndAllowed( true );
}
 
Example 17
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * @param schemaManager
 * @param entry
 * @throws LdapException
 */
public DefaultEntry( SchemaManager schemaManager, Entry entry ) throws LdapException
{
    this.schemaManager = schemaManager;

    // Initialize the ObjectClass object
    initObjectClassAT();

    // We will clone the existing entry, because it may be normalized
    if ( entry.getDn() != null )
    {
        dn = entry.getDn();
        normalizeDN( dn );
    }
    else
    {
        dn = Dn.EMPTY_DN;
    }

    // Init the attributes map
    attributes = new HashMap<String, Attribute>( entry.size() );

    // and copy all the attributes
    for ( Attribute attribute : entry )
    {
        try
        {
            // First get the AttributeType
            AttributeType attributeType = attribute.getAttributeType();

            if ( attributeType == null )
            {
                try {
                	attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() );
                } catch (LdapNoSuchAttributeException e) {
                	attributeType = ApacheDSUtil.addAttributeToSchema(attribute, schemaManager);
                }
            }

            // Create a new ServerAttribute.
            Attribute serverAttribute = new DefaultAttribute( attributeType, attribute );

            // And store it
            add( serverAttribute );
        }
        catch ( LdapException ne )
        {
            // Just log a warning
            LOG.warn( "The attribute '" + attribute.getId() + "' cannot be stored" );
            throw ne;
        }
    }
}
 
Example 18
Source File: StoreSearchRequestBaseObject.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<SearchRequest> container ) throws DecoderException
{
    SearchRequest searchRequest = container.getMessage();

    TLV tlv = container.getCurrentTLV();

    // We have to check that this is a correct Dn
    // We have to handle the special case of a 0 length base
    // object,
    // which means that the search is done from the default
    // root.
    if ( tlv.getLength() != 0 )
    {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString( dnBytes );

        try
        {
            Dn baseObject = new Dn( dnStr );
            searchRequest.setBase( baseObject );
        }
        catch ( LdapInvalidDnException ine )
        {
            String msg = I18n.err( I18n.ERR_05132_INVALID_ROOT_DN, dnStr, Strings.dumpBytes( dnBytes ) );
            LOG.error( I18n.err( I18n.ERR_05114_ERROR_MESSAGE, msg, ine.getMessage() ) );

            SearchResultDoneImpl response = new SearchResultDoneImpl( searchRequest.getMessageId() );
            throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
                Dn.EMPTY_DN, ine );
        }
    }
    else
    {
        searchRequest.setBase( Dn.EMPTY_DN );
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05160_SEARCHING_WITH_ROOT_DN, searchRequest.getBase() ) );
    }
}
 
Example 19
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, copying
 * another entry.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 * @param entry the entry to copy
 * @throws LdapException If the provided entry is invalid
 */
public DefaultEntry( SchemaManager schemaManager, Entry entry ) throws LdapException
{
    this.schemaManager = schemaManager;

    // Initialize the ObjectClass object
    initObjectClassAT();

    // We will clone the existing entry, because it may be normalized
    if ( entry.getDn() != null )
    {
        dn = normalizeDn( entry.getDn() );
    }
    else
    {
        dn = Dn.EMPTY_DN;
    }

    // Init the attributes map
    attributes = new HashMap<>( entry.size() );

    // and copy all the attributes
    for ( Attribute attribute : entry )
    {
        try
        {
            // First get the AttributeType
            AttributeType attributeType = attribute.getAttributeType();

            if ( attributeType == null )
            {
                attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() );
            }

            // Create a new ServerAttribute.
            Attribute serverAttribute = new DefaultAttribute( attributeType, attribute );

            // And store it
            add( serverAttribute );
        }
        catch ( Exception ne )
        {
            // Just log a warning
            if ( LOG.isWarnEnabled() )
            {
                LOG.warn( I18n.msg( I18n.MSG_13200_CANT_STORE_ATTRIBUTE, attribute.getId() ) );
            }

            throw ne;
        }
    }
}
 
Example 20
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * @param schemaManager
 * @param entry
 * @throws LdapException
 */
public DefaultEntry( SchemaManager schemaManager, Entry entry ) throws LdapException
{
    this.schemaManager = schemaManager;

    // Initialize the ObjectClass object
    initObjectClassAT();

    // We will clone the existing entry, because it may be normalized
    if ( entry.getDn() != null )
    {
        dn = entry.getDn();
        normalizeDN( dn );
    }
    else
    {
        dn = Dn.EMPTY_DN;
    }

    // Init the attributes map
    attributes = new HashMap<String, Attribute>( entry.size() );

    // and copy all the attributes
    for ( Attribute attribute : entry )
    {
        try
        {
            // First get the AttributeType
            AttributeType attributeType = attribute.getAttributeType();

            if ( attributeType == null )
            {
                try {
                	attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() );
                } catch (LdapNoSuchAttributeException e) {
                	attributeType = ApacheDSUtil.addAttributeToSchema(attribute, schemaManager);
                }
            }

            // Create a new ServerAttribute.
            Attribute serverAttribute = new DefaultAttribute( attributeType, attribute );

            // And store it
            add( serverAttribute );
        }
        catch ( LdapException ne )
        {
            // Just log a warning
            LOG.warn( "The attribute '" + attribute.getId() + "' cannot be stored" );
            throw ne;
        }
    }
}