directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ersin Er" <ersin...@gmail.com>
Subject Re: svn commit: r498096 - in /directory/trunks/apacheds: core-unit/src/test/java/org/apache/directory/server/core/collective/ core/src/main/java/org/apache/directory/server/core/collective/
Date Sat, 20 Jan 2007 10:30:31 GMT
Hi,

Can someone please tell me the correct error codes for the collective
attribute related schema checks below? Here are code snippets from the
commit below:

/*
 * TODO: Replace the Exception and the ResultCodeEnum with the correct ones.
 */
 throw new LdapSchemaViolationException(
      "Collective attributes cannot be stored in
non-collectiveAttributeSubentries",
      ResultCodeEnum.OTHER);

and

/*
 * TODO: Replace the Exception and the ResultCodeEnum with the correct ones.
 */
throw new LdapSchemaViolationException(
     "Cannot operate on collective attributes in
non-collectiveAttributeSubentries",
     ResultCodeEnum.OTHER);

First one is thrown when one tries to add an entry with collective
attributes but without collectiveAttributeSubentry object class.

The second one is thrown when one tries add collective attributes to
an entry which is not a collective attribute subentry.

Thanks.

On 1/20/07, ersiner@apache.org <ersiner@apache.org> wrote:
> Author: ersiner
> Date: Sat Jan 20 02:01:30 2007
> New Revision: 498096
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=498096
> Log:
> Fix for DIRSERVER-821 and DIRSERVER-822.
> May have not handled some extreme cases.
> Implamented as a specific schema checking for collective attributes.
> Bound to CollectiveAttributeService  instead of SchemaService. May move to SchemaService
later.
> Added three news tests to test new checks.
>
>
> Added:
>     directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java
> Modified:
>     directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceITest.java
>     directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
>
> Modified: directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceITest.java
> URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceITest.java?view=diff&rev=498096&r1=498095&r2=498096
> ==============================================================================
> --- directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceITest.java
(original)
> +++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceITest.java
Sat Jan 20 02:01:30 2007
> @@ -41,7 +41,7 @@
>   * Test cases for the collective attribute service.
>   *
>   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
> - * @version $Rev$
> + * @version $Rev:$
>   */
>  public class CollectiveAttributeServiceITest extends AbstractAdminTestCase
>  {
> @@ -422,6 +422,58 @@
>          c_st = attributes.get( "c-st" );
>          assertNull( c_ou );
>          assertNull( c_st );
> +    }
> +
> +
> +    public void testAddRegularEntryWithCollectiveAttribute()
> +    {
> +        Attributes entry = getTestEntry( "Ersin Er" );
> +        entry.put( "c-l", "Turkiye" );
> +        try
> +        {
> +            super.sysRoot.createSubcontext( "cn=Ersin Er", entry );
> +            fail( "Entry addition with collective attribute should have failed." );
> +        }
> +        catch ( NamingException e )
> +        {
> +            // Intended execution point
> +        }
> +    }
> +
> +
> +    public void testModifyRegularEntryAddingCollectiveAttribute() throws NamingException
> +    {
> +        Attributes entry = getTestEntry( "Ersin Er" );
> +        super.sysRoot.createSubcontext( "cn=Ersin Er", entry );
> +        Attributes changeSet = new AttributesImpl( "c-l", "Turkiye", true );
> +        try
> +        {
> +
> +            super.sysRoot.modifyAttributes( "cn=Ersin Er", DirContext.ADD_ATTRIBUTE,
changeSet );
> +            fail( "Collective attribute addition to non-collectiveAttributeSubentry
should have failed." );
> +        }
> +        catch ( NamingException e )
> +        {
> +            // Intended execution point
> +        }
> +    }
> +
> +
> +    public void testModifyRegularEntryAddingCollectiveAttribute2() throws NamingException
> +    {
> +        Attributes entry = getTestEntry( "Ersin Er" );
> +        super.sysRoot.createSubcontext( "cn=Ersin Er", entry );
> +        Attribute change = new AttributeImpl( "c-l", "Turkiye");
> +        ModificationItemImpl mod = new ModificationItemImpl(DirContext.ADD_ATTRIBUTE,
change);
> +        try
> +        {
> +            super.sysRoot.modifyAttributes( "cn=Ersin Er", new ModificationItemImpl[]
{ mod } );
> +            fail( "Collective attribute addition to non-collectiveAttributeSubentry
should have failed." );
> +        }
> +        catch ( NamingException e )
> +        {
> +            // Intended execution point
> +        }
>      }
>
>  }
>
> Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
> URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java?view=diff&rev=498096&r1=498095&r2=498096
> ==============================================================================
> --- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
(original)
> +++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
Sat Jan 20 02:01:30 2007
> @@ -44,6 +44,7 @@
>  import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
>  import org.apache.directory.shared.ldap.filter.ExprNode;
>  import org.apache.directory.shared.ldap.message.AttributeImpl;
> +import org.apache.directory.shared.ldap.message.ModificationItemImpl;
>  import org.apache.directory.shared.ldap.name.LdapDN;
>  import org.apache.directory.shared.ldap.schema.AttributeType;
>
> @@ -56,7 +57,7 @@
>   * collectiveAttributeInnerAreas.
>   *
>   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
> - * @version $Rev$
> + * @version $Rev:$
>   */
>  public class CollectiveAttributeService extends BaseInterceptor
>  {
> @@ -81,6 +82,8 @@
>
>      private AttributeTypeRegistry attrTypeRegistry = null;
>      private PartitionNexus nexus = null;
> +
> +    private CollectiveAttributesSchemaChecker collectiveAttributesSchemaChecker = null;
>
>
>      public void init( DirectoryServiceConfiguration factoryCfg, InterceptorConfiguration
cfg ) throws NamingException
> @@ -88,6 +91,7 @@
>          super.init( factoryCfg, cfg );
>          nexus = factoryCfg.getPartitionNexus();
>          attrTypeRegistry = factoryCfg.getRegistries().getAttributeTypeRegistry();
> +        collectiveAttributesSchemaChecker = new CollectiveAttributesSchemaChecker(nexus,
attrTypeRegistry);
>      }
>
>
> @@ -282,14 +286,29 @@
>          return new SearchResultFilteringEnumeration( e, searchCtls, invocation, SEARCH_FILTER
);
>      }
>
> +    // ------------------------------------------------------------------------
> +    // Partial Schema Checking
> +    // ------------------------------------------------------------------------
>
> -    /*
> -     * TODO: Add change inducing Interceptor methods to track and prevent
> -     *       modification of collective attributes over entries/subentries
> -     *       which are not of type collectiveAttributeSubentry.
> -     *
> -     * See: http://issues.apache.org/jira/browse/DIRSERVER-821
> -     * See: http://issues.apache.org/jira/browse/DIRSERVER-822
> -     */
> +    public void add( NextInterceptor next, LdapDN normName, Attributes entry ) throws
NamingException
> +    {
> +        collectiveAttributesSchemaChecker.checkAdd( normName, entry );
> +        super.add( next, normName, entry );
> +    }
> +
> +
> +    public void modify( NextInterceptor next, LdapDN normName, int modOp, Attributes
mods ) throws NamingException
> +    {
> +        collectiveAttributesSchemaChecker.checkModify( normName, modOp, mods );
> +        super.modify( next, normName, modOp, mods );
> +    }
> +
> +
> +    public void modify( NextInterceptor next, LdapDN normName, ModificationItemImpl[]
mods ) throws NamingException
> +    {
> +        collectiveAttributesSchemaChecker.checkModify( normName, mods );
> +        super.modify( next, normName, mods );
> +    }
>
> +
>  }
>
> Added: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java
> URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java?view=auto&rev=498096
> ==============================================================================
> --- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java
(added)
> +++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java
Sat Jan 20 02:01:30 2007
> @@ -0,0 +1,151 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF licenses this file
> + *  to you under the Apache License, Version 2.0 (the
> + *  "License"); you may not use this file except in compliance
> + *  with the License.  You may obtain a copy of the License at
> + *
> + *    http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,
> + *  software distributed under the License is distributed on an
> + *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + *  KIND, either express or implied.  See the License for the
> + *  specific language governing permissions and limitations
> + *  under the License.
> + *
> + */
> +
> +package org.apache.directory.server.core.collective;
> +
> +import javax.naming.NamingEnumeration;
> +import javax.naming.NamingException;
> +import javax.naming.directory.Attribute;
> +import javax.naming.directory.Attributes;
> +import javax.naming.directory.DirContext;
> +
> +import org.apache.directory.server.core.partition.PartitionNexus;
> +import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
> +import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
> +import org.apache.directory.shared.ldap.message.ModificationItemImpl;
> +import org.apache.directory.shared.ldap.message.ResultCodeEnum;
> +import org.apache.directory.shared.ldap.name.LdapDN;
> +import org.apache.directory.shared.ldap.schema.AttributeType;
> +import org.apache.directory.shared.ldap.schema.SchemaUtils;
> +
> +
> +/**
> + * Schema checking utilities specifically for operations on collective attributes.
> + *
> + * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
> + * @version $Rev:$
> + */
> +public class CollectiveAttributesSchemaChecker
> +{
> +    private PartitionNexus nexus = null;
> +    private AttributeTypeRegistry attrTypeRegistry = null;
> +
> +    public CollectiveAttributesSchemaChecker( PartitionNexus nexus, AttributeTypeRegistry
attrTypeRegistry )
> +    {
> +        this.nexus = nexus;
> +        this.attrTypeRegistry = attrTypeRegistry;
> +    }
> +
> +    public void checkAdd( LdapDN normName, Attributes entry ) throws LdapSchemaViolationException,
NamingException
> +    {
> +        Attribute objectClass = entry.get( "objectClass" );
> +        if ( objectClass.contains( "collectiveAttributeSubentry" ) )
> +        {
> +            return;
> +        }
> +
> +        if ( containsAnyCollectiveAttributes( entry ) )
> +        {
> +            /*
> +             * TODO: Replace the Exception and the ResultCodeEnum with the correct ones.
> +             */
> +            throw new LdapSchemaViolationException(
> +                "Collective attributes cannot be stored in non-collectiveAttributeSubentries",
> +                ResultCodeEnum.OTHER);
> +        }
> +    }
> +
> +    public void checkModify( LdapDN normName, int modOp, Attributes mods ) throws NamingException
> +    {
> +        ModificationItemImpl[] modsAsArray = new ModificationItemImpl[ mods.size() ];
> +        NamingEnumeration allAttrs = mods.getAll();
> +        int i = 0;
> +        while ( allAttrs.hasMoreElements() )
> +        {
> +            Attribute attr = ( Attribute ) allAttrs.nextElement();
> +            modsAsArray[i] = new ModificationItemImpl( modOp, attr );
> +            i++;
> +        }
> +
> +        checkModify( normName, modsAsArray );
> +    }
> +
> +
> +    public void checkModify( LdapDN normName, ModificationItemImpl[] mods ) throws NamingException
> +    {
> +        Attributes originalEntry = nexus.lookup( normName );
> +        Attributes targetEntry = SchemaUtils.getTargetEntry( mods, originalEntry );
> +        Attribute targetObjectClasses = targetEntry.get( "objectClass" );
> +
> +        if ( targetObjectClasses.contains( "collectiveAttributeSubentry" ) )
> +        {
> +            return;
> +        }
> +
> +        if ( addsAnyCollectiveAttributes( mods ) )
> +        {
> +            /*
> +             * TODO: Replace the Exception and the ResultCodeEnum with the correct ones.
> +             */
> +            throw new LdapSchemaViolationException(
> +                "Cannot operate on collective attributes in non-collectiveAttributeSubentries",
> +                ResultCodeEnum.OTHER);
> +        }
> +    }
> +
> +
> +    private boolean addsAnyCollectiveAttributes( ModificationItemImpl[] mods ) throws
NamingException
> +    {
> +        for ( int i = 0; i < mods.length; i++ )
> +        {
> +            Attribute attr = mods[i].getAttribute();
> +            String attrID = attr.getID();
> +            AttributeType attrType = attrTypeRegistry.lookup( attrID );
> +            int modOp = mods[i].getModificationOp();
> +
> +            if ( ( modOp == DirContext.ADD_ATTRIBUTE || modOp == DirContext.REPLACE_ATTRIBUTE
) &&
> +                attrType.isCollective() )
> +            {
> +                return true;
> +            }
> +        }
> +
> +        return false;
> +    }
> +
> +
> +    private boolean containsAnyCollectiveAttributes( Attributes entry ) throws NamingException
> +    {
> +        NamingEnumeration allIDs = entry.getIDs();
> +        while ( allIDs.hasMoreElements() )
> +        {
> +            String attrTypeStr = ( String ) allIDs.nextElement();
> +            AttributeType attrType = attrTypeRegistry.lookup( attrTypeStr );
> +            if ( attrType.isCollective() )
> +            {
> +                return true;
> +            }
> +        }
> +
> +        return false;
> +    }
> +
> +
> +}
>
>
>


-- 
Ersin

Mime
View raw message