Java Code Examples for org.apache.directory.api.ldap.model.schema.SchemaManager#lookupAttributeTypeRegistry()

The following examples show how to use org.apache.directory.api.ldap.model.schema.SchemaManager#lookupAttributeTypeRegistry() . 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: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Try to inject an AttributeType with a superior and no Syntax : it should
 * take its superior' syntax and MR
 */
@Test
public void testAddAttributeTypeSupNoSyntaxNoSuperior() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "1.1.0" );
    attributeType.setEqualityOid( null );
    attributeType.setOrderingOid( null );
    attributeType.setSubstringOid( null );
    attributeType.setSuperiorOid( "2.5.18.4" );
    attributeType.setUsage( UsageEnum.DIRECTORY_OPERATION );

    // It should not fail
    assertTrue( schemaManager.add( attributeType ) );

    AttributeType result = schemaManager.lookupAttributeTypeRegistry( "1.1.0" );

    assertEquals( "1.3.6.1.4.1.1466.115.121.1.12", result.getSyntaxOid() );
    assertEquals( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID, result.getEqualityOid() );
    assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 2
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * Convert a list of ModificationItemImpl to a list of 
 *
 * @param modificationImpls
 * @param atRegistry
 * @return
 * @throws LdapException
 */
public static List<Modification> convertToServerModification( List<ModificationItem> modificationItems,
    SchemaManager schemaManager ) throws LdapException
{
    if ( modificationItems != null )
    {
        List<Modification> modifications = new ArrayList<Modification>( modificationItems.size() );

        for ( ModificationItem modificationItem : modificationItems )
        {
            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( modificationItem
                .getAttribute().getID() );
            modifications.add( toServerModification( modificationItem, attributeType ) );
        }

        return modifications;
    }
    else
    {
        return null;
    }
}
 
Example 3
Source File: FilteringOperationContext.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Tells if an attribute is present in the list of attribute to return
 * 
 * @param attribute The attribute we are looking for
 * @return true if the attribute is present
 */
public boolean contains( SchemaManager schemaManager, String attribute )
{
    if ( isNoAttributes() )
    {
        return false;
    }

    try
    {
        AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute );

        return contains( schemaManager, attributeType );
    }
    catch ( LdapException le )
    {
        return false;
    }
}
 
Example 4
Source File: FilteringOperationContext.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Tells if an attribute is present in the list of attribute to return
 * 
 * @param attribute The attribute we are looking for
 * @return true if the attribute is present
 */
public boolean contains( SchemaManager schemaManager, String attribute )
{
    if ( isNoAttributes() )
    {
        return false;
    }

    try
    {
        AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute );

        return contains( schemaManager, attributeType );
    }
    catch ( LdapException le )
    {
        return false;
    }
}
 
Example 5
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Delete an existing AT referenced by some descendant
 */
@Test
public void testDeleteExistingAttributeTypeUsedByDescendant() throws Exception
{
    SchemaManager schemaManager = loadSchema( "Apache" );

    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    // Try to delete an AT which has descendant
    // (modifiersName has one descendant : schemaModifiersName)
    AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( "modifiersName" );

    // It should fail
    assertFalse( schemaManager.delete( attributeType ) );

    assertTrue( isAttributeTypePresent( schemaManager, "modifiersName" ) );
    assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 6
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Delete an existing AT referenced by some other OC
 */
@Test
public void testDeleteExistingAttributeTypeUsedByOC() throws Exception
{
    SchemaManager schemaManager = loadSchema( "Core" );

    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    // Try to delete an AT which is referenced by at least one OC
    // (modifiersName has one descendant : schemaModifiersName)
    AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( "cn" );

    // It should fail
    assertFalse( schemaManager.delete( attributeType ) );

    assertTrue( isAttributeTypePresent( schemaManager, "cn" ) );
    assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 7
Source File: SearchParams.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Normalize the ReturningAttributes. It reads all the String from the returningAttributesString,
 * and grab the associated AttributeType from the schema to store it into the returningAttributes
 * Set.
 *
 * @param schemaManager The schema manager
 */
public void normalize( SchemaManager schemaManager )
{
    for ( String returnAttribute : returningAttributesStr )
    {
        try
        {
            String id = SchemaUtils.stripOptions( returnAttribute );
            Set<String> options = SchemaUtils.getOptions( returnAttribute );

            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
            AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType, options );

            returningAttributes.add( attrOptions );
        }
        catch ( LdapException ne )
        {
            if ( LOG.isWarnEnabled() )
            {
                LOG.warn( I18n.msg( I18n.MSG_13500_ATTRIBUTE_NOT_IN_SCHEMA, returnAttribute ) );
            }
            
            // Unknown attributes should be silently ignored, as RFC 2251 states
        }
    }
}
 
Example 8
Source File: DefaultModification.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of DefaultModification.
 *
 * @param schemaManager The schema manager 
 * @param modification The modification
 */
public DefaultModification( SchemaManager schemaManager, Modification modification )
{
    operation = modification.getOperation();

    Attribute modAttribute = modification.getAttribute();

    try
    {
        AttributeType at = modAttribute.getAttributeType();

        if ( at == null )
        {
            at = schemaManager.lookupAttributeTypeRegistry( modAttribute.getId() );
        }

        attribute = new DefaultAttribute( at, modAttribute );
    }
    catch ( LdapException ne )
    {
        // The attributeType is incorrect. Log, but do nothing otherwise.
        LOG.error( I18n.err( I18n.ERR_13230_INCORRECT_ATTRIBUTE, modAttribute.getId() ) );
    }
}
 
Example 9
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Check if an AT is present in the AT registry
 */
private boolean isATPresent( SchemaManager schemaManager, String oid )
{
    try
    {
        AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid );

        return attributeType != null;
    }
    catch ( LdapException ne )
    {
        return false;
    }
}
 
Example 10
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Try to inject an AttributeType which already exist
 */
@Test
public void testAddAttributeTypeAlreadyExist() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "2.5.18.4" );
    attributeType.setEqualityOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setOrderingOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setSubstringOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );

    // It should fail
    assertFalse( schemaManager.add( attributeType ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 1, errors.size() );
    Throwable error = errors.get( 0 );

    assertTrue( error instanceof LdapSchemaException );

    // The AT must be there
    assertTrue( isATPresent( schemaManager, "2.5.18.4" ) );

    // Check that it hasen't changed
    AttributeType original = schemaManager.lookupAttributeTypeRegistry( "2.5.18.4" );
    assertEquals( "distinguishedNameMatch", original.getEqualityOid() );
    assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 11
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Try to inject an AttributeType with an ObjectClass name
 */
@Test
public void testAddAttributeTypeNameOfAnObjectClass() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "1.1.1.0" );
    attributeType.setEqualityOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setOrderingOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setSubstringOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
    attributeType.setNames( "Test", "referral" );

    // It should be ok
    assertTrue( schemaManager.add( attributeType ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 0, errors.size() );

    // The AT must be present
    assertTrue( isATPresent( schemaManager, "1.1.1.0" ) );

    assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );

    AttributeType added = schemaManager.lookupAttributeTypeRegistry( "referral" );
    assertNotNull( added );
    assertEquals( "1.1.1.0", added.getOid() );
    assertTrue( added.getNames().contains( "referral" ) );
}
 
Example 12
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a BasicAttributes or a AttributesImpl to a ServerEntry
 *
 * @param attributes the BasicAttributes or AttributesImpl instance to convert
 * @param registries The registries, needed ro build a ServerEntry
 * @param dn The Dn which is needed by the ServerEntry
 * @return An instance of a ServerEntry object
 * 
 * @throws LdapInvalidAttributeTypeException If we get an invalid attribute
 */
public static Entry toServerEntry( Attributes attributes, Dn dn, SchemaManager schemaManager )
    throws LdapInvalidAttributeTypeException
{
    if ( attributes instanceof BasicAttributes )
    {
        try
        {
            Entry entry = new DefaultEntry( schemaManager, dn );

            for ( NamingEnumeration<? extends javax.naming.directory.Attribute> attrs = attributes.getAll(); attrs
                .hasMoreElements(); )
            {
                javax.naming.directory.Attribute attr = attrs.nextElement();

                String attributeId = attr.getID();
                String id = SchemaUtils.stripOptions( attributeId );
                Set<String> options = SchemaUtils.getOptions( attributeId );
                // TODO : handle options.
                AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
                Attribute serverAttribute = ServerEntryUtils.toServerAttribute( attr, attributeType );

                if ( serverAttribute != null )
                {
                    entry.put( serverAttribute );
                }
            }

            return entry;
        }
        catch ( LdapException ne )
        {
            throw new LdapInvalidAttributeTypeException( ne.getLocalizedMessage() );
        }
    }
    else
    {
        return null;
    }
}
 
Example 13
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a BasicAttributes or a AttributesImpl to a ServerEntry
 *
 * @param attributes the BasicAttributes or AttributesImpl instance to convert
 * @param registries The registries, needed ro build a ServerEntry
 * @param dn The Dn which is needed by the ServerEntry
 * @return An instance of a ServerEntry object
 * 
 * @throws LdapInvalidAttributeTypeException If we get an invalid attribute
 */
public static Entry toServerEntry( Attributes attributes, Dn dn, SchemaManager schemaManager )
    throws LdapInvalidAttributeTypeException
{
    if ( attributes instanceof BasicAttributes )
    {
        try
        {
            Entry entry = new DefaultEntry( schemaManager, dn );

            for ( NamingEnumeration<? extends javax.naming.directory.Attribute> attrs = attributes.getAll(); attrs
                .hasMoreElements(); )
            {
                javax.naming.directory.Attribute attr = attrs.nextElement();

                String attributeId = attr.getID();
                String id = SchemaUtils.stripOptions( attributeId );
                Set<String> options = SchemaUtils.getOptions( attributeId );
                // TODO : handle options.
                AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
                Attribute serverAttribute = ServerEntryUtils.toServerAttribute( attr, attributeType );

                if ( serverAttribute != null )
                {
                    entry.put( serverAttribute );
                }
            }

            return entry;
        }
        catch ( LdapException ne )
        {
            throw new LdapInvalidAttributeTypeException( ne.getLocalizedMessage() );
        }
    }
    else
    {
        return null;
    }
}
 
Example 14
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
public static List<Modification> toServerModification( ModificationItem[] modifications,
    SchemaManager schemaManager ) throws LdapException
{
    if ( modifications != null )
    {
        List<Modification> modificationsList = new ArrayList<Modification>();

        for ( ModificationItem modification : modifications )
        {
            String attributeId = modification.getAttribute().getID();
            String id = stripOptions( attributeId );
            Set<String> options = getOptions( attributeId );

            // -------------------------------------------------------------------
            // DIRSERVER-646 Fix: Replacing an unknown attribute with no values 
            // (deletion) causes an error
            // -------------------------------------------------------------------

            // TODO - after removing JNDI we need to make the server handle 
            // this in the codec

            if ( !schemaManager.getAttributeTypeRegistry().contains( id )
                && modification.getAttribute().size() == 0
                && modification.getModificationOp() == DirContext.REPLACE_ATTRIBUTE )
            {
                continue;
            }

            // -------------------------------------------------------------------
            // END DIRSERVER-646 Fix
            // -------------------------------------------------------------------

            // TODO : handle options
            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
            modificationsList.add( toServerModification( modification, attributeType ) );
        }

        return modificationsList;
    }
    else
    {
        return null;
    }
}
 
Example 15
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 16
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 17
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
public static List<Modification> toServerModification( Modification[] modifications,
    SchemaManager schemaManager ) throws LdapException
{
    if ( modifications != null )
    {
        List<Modification> modificationsList = new ArrayList<Modification>();

        for ( Modification modification : modifications )
        {
            String attributeId = modification.getAttribute().getUpId();
            String id = stripOptions( attributeId );
            modification.getAttribute().setUpId( id );
            Set<String> options = getOptions( attributeId );

            // -------------------------------------------------------------------
            // DIRSERVER-646 Fix: Replacing an unknown attribute with no values 
            // (deletion) causes an error
            // -------------------------------------------------------------------
            if ( !schemaManager.getAttributeTypeRegistry().contains( id )
                && modification.getAttribute().size() == 0
                && modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE )
            {
                // The attributeType does not exist in the schema.
                // It's an error
                String message = I18n.err( I18n.ERR_467, id );
                throw new LdapInvalidAttributeTypeException( message );
            }
            else
            {
                // TODO : handle options
                AttributeType attributeType = null;
                try {
                	attributeType = schemaManager.lookupAttributeTypeRegistry( id );
                } catch (LdapNoSuchAttributeException e) {
                	attributeType = ApacheDSUtil.addAttributeToSchema(modification.getAttribute(), schemaManager);
                }
                modificationsList.add( toServerModification( modification, attributeType ) );
            }
        }

        return modificationsList;
    }
    else
    {
        return null;
    }
}
 
Example 18
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
public static List<Modification> toServerModification( Modification[] modifications,
    SchemaManager schemaManager ) throws LdapException
{
    if ( modifications != null )
    {
        List<Modification> modificationsList = new ArrayList<Modification>();

        for ( Modification modification : modifications )
        {
            String attributeId = modification.getAttribute().getUpId();
            String id = stripOptions( attributeId );
            modification.getAttribute().setUpId( id );
            Set<String> options = getOptions( attributeId );

            // -------------------------------------------------------------------
            // DIRSERVER-646 Fix: Replacing an unknown attribute with no values 
            // (deletion) causes an error
            // -------------------------------------------------------------------
            if ( !schemaManager.getAttributeTypeRegistry().contains( id )
                && modification.getAttribute().size() == 0
                && modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE )
            {
                // The attributeType does not exist in the schema.
                // It's an error
                String message = I18n.err( I18n.ERR_467, id );
                throw new LdapInvalidAttributeTypeException( message );
            }
            else
            {
                // TODO : handle options
                AttributeType attributeType = null;
                try {
                	attributeType = schemaManager.lookupAttributeTypeRegistry( id );
                } catch (LdapNoSuchAttributeException e) {
                	attributeType = ApacheDSUtil.addAttributeToSchema(modification.getAttribute(), schemaManager);
                }
                modificationsList.add( toServerModification( modification, attributeType ) );
            }
        }

        return modificationsList;
    }
    else
    {
        return null;
    }
}
 
Example 19
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
public static List<Modification> toServerModification( ModificationItem[] modifications,
    SchemaManager schemaManager ) throws LdapException
{
    if ( modifications != null )
    {
        List<Modification> modificationsList = new ArrayList<Modification>();

        for ( ModificationItem modification : modifications )
        {
            String attributeId = modification.getAttribute().getID();
            String id = stripOptions( attributeId );
            Set<String> options = getOptions( attributeId );

            // -------------------------------------------------------------------
            // DIRSERVER-646 Fix: Replacing an unknown attribute with no values 
            // (deletion) causes an error
            // -------------------------------------------------------------------

            // TODO - after removing JNDI we need to make the server handle 
            // this in the codec

            if ( !schemaManager.getAttributeTypeRegistry().contains( id )
                && modification.getAttribute().size() == 0
                && modification.getModificationOp() == DirContext.REPLACE_ATTRIBUTE )
            {
                continue;
            }

            // -------------------------------------------------------------------
            // END DIRSERVER-646 Fix
            // -------------------------------------------------------------------

            // TODO : handle options
            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
            modificationsList.add( toServerModification( modification, attributeType ) );
        }

        return modificationsList;
    }
    else
    {
        return null;
    }
}
 
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;
        }
    }
}