directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r412498 - in /directory/branches/apacheds/optimization/core/src: main/java/org/apache/directory/server/core/event/ main/java/org/apache/directory/server/core/normalization/ main/java/org/apache/directory/server/core/partition/impl/btree/jdb...
Date Wed, 07 Jun 2006 19:42:17 GMT
Author: akarasulu
Date: Wed Jun  7 12:42:17 2006
New Revision: 412498

URL: http://svn.apache.org/viewvc?rev=412498&view=rev
Log:
fixed various filter normalization issues

Added:
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java
      - copied, changed from r412239, directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/ValueNormalizingVisitor.java
Removed:
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/ValueNormalizingVisitor.java
Modified:
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/EventService.java
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationService.java
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDirectoryPartition.java
    directory/branches/apacheds/optimization/core/src/test/java/org/apache/directory/server/core/authz/support/RelatedProtectedItemFilterTest.java

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/EventService.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/EventService.java?rev=412498&r1=412497&r2=412498&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/EventService.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/EventService.java
Wed Jun  7 12:42:17 2006
@@ -23,15 +23,22 @@
 import org.apache.directory.server.core.interceptor.NextInterceptor;
 import org.apache.directory.server.core.invocation.Invocation;
 import org.apache.directory.server.core.invocation.InvocationStack;
+import org.apache.directory.server.core.normalization.NormalizingVisitor;
 import org.apache.directory.server.core.partition.DirectoryPartitionNexus;
 import org.apache.directory.server.core.partition.DirectoryPartitionNexusProxy;
 import org.apache.directory.server.core.schema.AttributeTypeRegistry;
 import org.apache.directory.server.core.schema.OidRegistry;
 import org.apache.directory.shared.ldap.filter.BranchNode;
 import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.filter.LeafNode;
 import org.apache.directory.shared.ldap.filter.ScopeNode;
 import org.apache.directory.shared.ldap.message.DerefAliasesEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.NameComponentNormalizer;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.naming.Name;
 import javax.naming.NamingException;
@@ -54,19 +61,24 @@
  */
 public class EventService extends BaseInterceptor
 {
+    private static Logger log = LoggerFactory.getLogger( EventService.class );
     private DirectoryPartitionNexus nexus;
     private Map sources = new HashMap();
     private Evaluator evaluator = null;
+    private AttributeTypeRegistry registry;
+    private NormalizingVisitor visitor;
 
-
+    
     public void init( DirectoryServiceConfiguration factoryCfg, InterceptorConfiguration
cfg ) throws NamingException
     {
         super.init( factoryCfg, cfg );
 
         OidRegistry oidRegistry = factoryCfg.getGlobalRegistries().getOidRegistry();
-        AttributeTypeRegistry attrRegistry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
-        evaluator = new ExpressionEvaluator( oidRegistry, attrRegistry );
+        registry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
+        evaluator = new ExpressionEvaluator( oidRegistry, registry );
         nexus = factoryCfg.getPartitionNexus();
+        NameComponentNormalizer ncn = new PerComponentNormalizer();
+        visitor = new NormalizingVisitor( ncn, factoryCfg.getGlobalRegistries().getOidRegistry()
);
     }
 
 
@@ -80,14 +92,71 @@
      * @param namingListener the naming listener to register
      */
     public void addNamingListener( EventContext ctx, Name name, ExprNode filter, SearchControls
searchControls,
-        NamingListener namingListener )
+        NamingListener namingListener ) throws NamingException
     {
-        ScopeNode scope = new ScopeNode( DerefAliasesEnum.NEVERDEREFALIASES, name.toString(),
searchControls
-            .getSearchScope() );
-        BranchNode and = new BranchNode( BranchNode.AND );
-        and.addNode( scope );
-        and.addNode( filter );
-        EventSourceRecord rec = new EventSourceRecord( name, and, ctx, searchControls, namingListener
);
+        LdapDN normalizedBaseDn = new LdapDN( name );
+        normalizedBaseDn.normalize();
+        
+        // -------------------------------------------------------------------
+        // must normalize the filter here: need to handle special cases
+        // -------------------------------------------------------------------
+
+        if ( filter.isLeaf() )
+        {
+            LeafNode ln = ( LeafNode ) filter;
+            if ( !registry.hasAttributeType( ln.getAttribute() ) )
+            {
+                StringBuffer buf = new StringBuffer();
+                buf.append( "undefined filter based on undefined attributeType '" );
+                buf.append( ln.getAttribute() );
+                buf.append( "' not evaluted at all.  Only using scope node." );
+                log.warn( buf.toString() );
+                filter = null;
+            }
+            else
+            {
+                filter.accept( visitor );
+            }
+        }
+        else 
+        {
+            filter.accept( visitor );
+    
+            // Check that after pruning/normalization we have a valid branch node at the
top
+            BranchNode child = ( BranchNode ) filter;
+
+            // If the remaining filter branch node has no children set filter to null
+            if ( child.getChildren().size() == 0 )
+            {
+                log.warn( "Undefined branchnode filter without child nodes not evaluted at
all. " +
+                        "Only using scope node." );
+                filter = null;
+            }
+
+            // Now for AND & OR nodes with a single child left replace them with their
child
+            if ( child.getChildren().size() == 1 && child.getOperator() != BranchNode.NOT
)
+            {
+                filter = child.getChild();
+            }
+        }
+        
+        
+        ScopeNode scope = new ScopeNode( DerefAliasesEnum.NEVERDEREFALIASES, normalizedBaseDn.toNormName(),

+            searchControls.getSearchScope() );
+        
+        if ( filter != null )
+        {
+            BranchNode and = new BranchNode( BranchNode.AND );
+            and.addNode( scope );
+            and.addNode( filter );
+            filter = and;
+        }
+        else
+        {
+            filter = scope;
+        }
+        
+        EventSourceRecord rec = new EventSourceRecord( name, filter, ctx, searchControls,
namingListener );
         Object obj = sources.get( namingListener );
 
         if ( obj == null )
@@ -307,7 +376,7 @@
     }
 
 
-    Set getSelectingSources( Name name, Attributes entry ) throws NamingException
+    Set getSelectingSources( LdapDN name, Attributes entry ) throws NamingException
     {
         if ( sources.isEmpty() )
         {
@@ -322,7 +391,7 @@
             if ( obj instanceof EventSourceRecord )
             {
                 EventSourceRecord rec = ( EventSourceRecord ) obj;
-                if ( evaluator.evaluate( rec.getFilter(), name.toString(), entry ) )
+                if ( evaluator.evaluate( rec.getFilter(), name.toNormName(), entry ) )
                 {
                     selecting.add( obj );
                 }
@@ -333,7 +402,7 @@
                 for ( int ii = 0; ii < records.size(); ii++ )
                 {
                     EventSourceRecord rec = ( EventSourceRecord ) records.get( ii );
-                    if ( evaluator.evaluate( rec.getFilter(), name.toString(), entry ) )
+                    if ( evaluator.evaluate( rec.getFilter(), name.toNormName(), entry )
)
                     {
                         selecting.add( obj );
                     }
@@ -395,6 +464,49 @@
         public SearchControls getSearchControls()
         {
             return controls;
+        }
+    }
+    
+    
+    /**
+     * A normalizer that normalizes each name component specifically according to
+     * the attribute type of the name component.
+     */
+    private class PerComponentNormalizer implements NameComponentNormalizer
+    {
+        public String normalizeByName( String name, String value ) throws NamingException
+        {
+            AttributeType type = registry.lookup( name );
+            return ( String ) type.getEquality().getNormalizer().normalize( value );
+        }
+
+
+        public String normalizeByName( String name, byte[] value ) throws NamingException
+        {
+            AttributeType type = registry.lookup( name );
+
+            return ( String ) type.getEquality().getNormalizer().normalize( value );
+        }
+
+
+        public String normalizeByOid( String oid, String value ) throws NamingException
+        {
+            AttributeType type = registry.lookup( oid );
+            return ( String ) type.getEquality().getNormalizer().normalize( value );
+        }
+
+
+        public boolean isDefined( String id )
+        {
+            return registry.hasAttributeType( id );
+        }
+
+
+        public String normalizeByOid( String oid, byte[] value ) throws NamingException
+        {
+            AttributeType type = registry.lookup( oid );
+
+            return ( String ) type.getEquality().getNormalizer().normalize( value );
         }
     }
 }

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java?rev=412498&r1=412497&r2=412498&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
Wed Jun  7 12:42:17 2006
@@ -67,8 +67,8 @@
      *
      * @param substringEvaluator
      */
-    public LeafEvaluator(OidRegistry oidRegistry, AttributeTypeRegistry attributeTypeRegistry,
-        SubstringEvaluator substringEvaluator) throws NamingException
+    public LeafEvaluator( OidRegistry oidRegistry, AttributeTypeRegistry attributeTypeRegistry,
+        SubstringEvaluator substringEvaluator ) throws NamingException
     {
         this.oidRegistry = oidRegistry;
         this.attributeTypeRegistry = attributeTypeRegistry;
@@ -138,7 +138,7 @@
         String attrId = node.getAttribute();
 
         // get the attribute associated with the node
-        Attribute attr = entry.get( attrId );
+        Attribute attr = getAttributeByOid( attrId, entry );
 
         // If we do not have the attribute just return false
         if ( null == attr )
@@ -199,18 +199,43 @@
      * @param entry the perspective candidate
      * @return the ava evaluation on the perspective candidate
      */
-    private boolean evalPresence( String attrId, Attributes entry )
+    private boolean evalPresence( String attrId, Attributes entry ) throws NamingException
     {
         if ( entry == null )
         {
             return false;
         }
 
-        return null != entry.get( attrId );
+        return null != getAttributeByOid( attrId, entry );
     }
 
 
     /**
+     * Iterates through all attributes checking to see if the id corresponds to 
+     * the attribute's OID.  Once a match is found it is returned shorting the 
+     * loop.
+     * 
+     * @param attributeOid the OID of the attribute
+     * @param entry the attributes of the entry
+     * @return the Attribute corresponding to the OID
+     * @throws NamingException 
+     */
+    private Attribute getAttributeByOid( String attributeOid, Attributes entry ) throws NamingException
+    {
+        for ( NamingEnumeration ii = entry.getIDs(); ii.hasMore(); /**/ )
+        {
+            String id = ( String ) ii.next();
+            String oid = oidRegistry.getOid( id );
+            if ( oid.equals( attributeOid ) )
+            {
+                return entry.get( id );
+            }
+        }
+        return null;
+    }
+    
+
+    /**
      * Evaluates a simple equality attribute value assertion on a perspective
      * candidate.
      *
@@ -225,7 +250,7 @@
         Comparator comparator = getComparator( node.getAttribute() );
 
         // get the attribute associated with the node
-        Attribute attr = entry.get( node.getAttribute() );
+        Attribute attr = getAttributeByOid( node.getAttribute(), entry );
 
         // If we do not have the attribute just return false
         if ( null == attr )

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationService.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationService.java?rev=412498&r1=412497&r2=412498&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationService.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationService.java
Wed Jun  7 12:42:17 2006
@@ -58,7 +58,7 @@
     private static final Logger log = LoggerFactory.getLogger( NormalizationService.class
);
 
     /** a filter node value normalizer and undefined node remover */
-    private ValueNormalizingVisitor visitor;
+    private NormalizingVisitor visitor;
     /** the attributeType registry used for normalization and determining if some filter
nodes are undefined */
     private AttributeTypeRegistry registry;
 
@@ -67,7 +67,7 @@
     {
         registry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
         NameComponentNormalizer ncn = new PerComponentNormalizer();
-        visitor = new ValueNormalizingVisitor( ncn );
+        visitor = new NormalizingVisitor( ncn, factoryCfg.getGlobalRegistries().getOidRegistry()
);
     }
 
 
@@ -237,6 +237,7 @@
         name = LdapDN.normalize( name );
         return next.compare( name, oid, value );
     }
+
 
     /**
      * A normalizer that normalizes each name component specifically according to

Copied: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java
(from r412239, directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/ValueNormalizingVisitor.java)
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java?p2=directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java&p1=directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/ValueNormalizingVisitor.java&r1=412239&r2=412498&rev=412498&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/ValueNormalizingVisitor.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/normalization/NormalizingVisitor.java
Wed Jun  7 12:42:17 2006
@@ -17,10 +17,12 @@
 package org.apache.directory.server.core.normalization;
 
 
+import org.apache.directory.server.core.schema.OidRegistry;
 import org.apache.directory.shared.ldap.filter.BranchNode;
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.FilterVisitor;
 import org.apache.directory.shared.ldap.filter.LeafNode;
+import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.directory.shared.ldap.filter.SimpleNode;
 import org.apache.directory.shared.ldap.name.NameComponentNormalizer;
 
@@ -48,22 +50,43 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ValueNormalizingVisitor implements FilterVisitor
+public class NormalizingVisitor implements FilterVisitor
 {
     /** logger used by this class */
-    private final static Logger log = LoggerFactory.getLogger( ValueNormalizingVisitor.class
);
+    private final static Logger log = LoggerFactory.getLogger( NormalizingVisitor.class );
     /** the name component normalizer used by this visitor */
     private final NameComponentNormalizer ncn;
+    /** the oid registry used to resolve OIDs for attributeType ids */
+    private final OidRegistry registry;
 
 
-    public ValueNormalizingVisitor(NameComponentNormalizer ncn)
+    public NormalizingVisitor( NameComponentNormalizer ncn, OidRegistry registry )
     {
         this.ncn = ncn;
+        this.registry = registry;
     }
 
 
     public void visit( ExprNode node )
     {
+        if ( node instanceof PresenceNode )
+        {
+            PresenceNode pnode = ( PresenceNode ) node;
+            
+            try
+            {
+                pnode.setAttribute( registry.getOid( pnode.getAttribute() ) );
+            }
+            catch ( NamingException e )
+            {
+                log.error( "Failed to normalize filter node attribute: " + pnode.getAttribute(),
e );
+                RuntimeException rte = new RuntimeException( e.getMessage() );
+                rte.initCause( e );
+                throw rte;
+            }
+            return;
+        }
+
         if ( node instanceof SimpleNode )
         {
             SimpleNode snode = ( SimpleNode ) node;
@@ -89,9 +112,23 @@
             catch ( NamingException e )
             {
                 log.error( "Failed to normalize filter value: " + e.getMessage(), e );
-                throw new RuntimeException( e.getMessage() );
+                RuntimeException rte = new RuntimeException( e.getMessage() );
+                rte.initCause( e );
+                throw rte;
             }
 
+            try
+            {
+                snode.setAttribute( registry.getOid( snode.getAttribute() ) );
+            }
+            catch ( NamingException e )
+            {
+                log.error( "Failed to normalize filter node attribute: " + snode.getAttribute(),
e );
+                RuntimeException rte = new RuntimeException( e.getMessage() );
+                rte.initCause( e );
+                throw rte;
+            }
+            
             snode.setValue( normalized );
             return;
         }
@@ -175,7 +212,7 @@
 
     public boolean canVisit( ExprNode node )
     {
-        return node instanceof BranchNode || node instanceof SimpleNode;
+        return true;
     }
 
 

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDirectoryPartition.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDirectoryPartition.java?rev=412498&r1=412497&r2=412498&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDirectoryPartition.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDirectoryPartition.java
Wed Jun  7 12:42:17 2006
@@ -48,6 +48,7 @@
 import org.apache.directory.server.core.partition.impl.btree.IndexAssertionEnumeration;
 import org.apache.directory.server.core.partition.impl.btree.IndexNotFoundException;
 import org.apache.directory.server.core.partition.impl.btree.IndexRecord;
+import org.apache.directory.server.core.schema.OidRegistry;
 
 import org.apache.directory.shared.ldap.exception.LdapAuthenticationNotSupportedException;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
@@ -107,6 +108,8 @@
     private Index subAliasIdx;
     /** a system index on aliasedObjectName attribute */
     private Index aliasIdx;
+    
+    private OidRegistry oidRegistry;
 
 
     // ------------------------------------------------------------------------
@@ -124,6 +127,7 @@
     public synchronized void init( DirectoryServiceConfiguration factoryCfg, DirectoryPartitionConfiguration
cfg )
         throws NamingException
     {
+        oidRegistry = factoryCfg.getGlobalRegistries().getOidRegistry();
         Map oids = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry().getNormalizerMapping();
         LdapDN.setOidsMap( oids );
         this.upSuffix = new LdapDN( cfg.getSuffix() );
@@ -296,7 +300,7 @@
     public void addIndexOn( AttributeType spec ) throws NamingException
     {
         Index idx = new JdbmIndex( spec, workingDirectory );
-        indices.put( spec.getName().toLowerCase(), idx );
+        indices.put( spec.getOid(), idx );
     }
 
 
@@ -315,7 +319,7 @@
         }
 
         existanceIdx = new JdbmIndex( attrType, workingDirectory );
-        sysIndices.put( attrType.getName().toLowerCase(), existanceIdx );
+        sysIndices.put( attrType.getOid(), existanceIdx );
     }
 
 
@@ -334,7 +338,7 @@
         }
 
         hierarchyIdx = new JdbmIndex( attrType, workingDirectory );
-        sysIndices.put( attrType.getName().toLowerCase(), hierarchyIdx );
+        sysIndices.put( attrType.getOid(), hierarchyIdx );
     }
 
 
@@ -353,7 +357,7 @@
         }
 
         aliasIdx = new JdbmIndex( attrType, workingDirectory );
-        sysIndices.put( attrType.getName().toLowerCase(), aliasIdx );
+        sysIndices.put( attrType.getOid(), aliasIdx );
     }
 
 
@@ -372,7 +376,7 @@
         }
 
         oneAliasIdx = new JdbmIndex( attrType, workingDirectory );
-        sysIndices.put( attrType.getName().toLowerCase(), oneAliasIdx );
+        sysIndices.put( attrType.getOid(), oneAliasIdx );
     }
 
 
@@ -391,7 +395,7 @@
         }
 
         subAliasIdx = new JdbmIndex( attrType, workingDirectory );
-        sysIndices.put( attrType.getName().toLowerCase(), subAliasIdx );
+        sysIndices.put( attrType.getOid(), subAliasIdx );
     }
 
 
@@ -410,7 +414,7 @@
         }
 
         updnIdx = new JdbmIndex( attrType, workingDirectory );
-        sysIndices.put( attrType.getName().toLowerCase(), updnIdx );
+        sysIndices.put( attrType.getOid(), updnIdx );
     }
 
 
@@ -429,7 +433,7 @@
         }
 
         ndnIdx = new JdbmIndex( attrType, workingDirectory );
-        sysIndices.put( attrType.getName().toLowerCase(), ndnIdx );
+        sysIndices.put( attrType.getOid(), ndnIdx );
     }
 
 
@@ -445,39 +449,54 @@
     }
 
 
-    public boolean hasUserIndexOn( String attribute )
+    public boolean hasUserIndexOn( String oid )
     {
-        return indices.containsKey( attribute ) || indices.containsKey( attribute.toLowerCase()
);
+        return indices.containsKey( oid );
     }
 
 
-    public boolean hasSystemIndexOn( String attribute )
+    public boolean hasSystemIndexOn( String oid )
     {
-        return sysIndices.containsKey( attribute ) || sysIndices.containsKey( attribute.toLowerCase()
);
+        return sysIndices.containsKey( oid );
     }
 
 
     /**
-     * @todo replace lookups to use the OID instead of the name.  Also note
-     * that the OID registry can be used to go between names and oids.
      * 
      * @see org.apache.directory.server.core.partition.impl.btree.BTreeDirectoryPartition#getUserIndex(String)
      */
-    public Index getUserIndex( String attribute ) throws IndexNotFoundException
+    public Index getUserIndex( String oid ) throws IndexNotFoundException
     {
-        String lowerCased = attribute.toLowerCase();
-
-        if ( indices.containsKey( attribute ) )
+        try
+        {
+            oid = oidRegistry.getOid( oid );
+        }
+        catch ( NamingException e )
         {
-            return ( Index ) indices.get( attribute );
+            log.error( "Failed to identify OID for: " + oid, e );
+            throw new IndexNotFoundException( "Failed to identify OID for: " + oid, oid,
e );
         }
-        else if ( indices.containsKey( lowerCased ) )
+
+        if ( indices.containsKey( oid ) )
         {
-            return ( Index ) indices.get( lowerCased );
+            return ( Index ) indices.get( oid );
         }
         else
         {
-            throw new IndexNotFoundException( "An index on attribute " + attribute + " does
not exist!" );
+            String name = "unknown";
+            try
+            {
+                name = oidRegistry.getPrimaryName( oid );
+            }
+            catch ( NamingException e )
+            {
+                String msg = "Failed to resolve primary name for " + oid + " in user index
lookup";
+                log.error( msg, e );
+                throw new IndexNotFoundException( msg, oid, e );
+            }
+            
+            throw new IndexNotFoundException( "A user index on attribute " + oid + " (" 
+                + name + ") does not exist!" );
         }
     }
 
@@ -488,21 +507,39 @@
      * 
      * @see BTreeDirectoryPartition#getEntryId(String)
      */
-    public Index getSystemIndex( String indexName ) throws IndexNotFoundException
+    public Index getSystemIndex( String oid ) throws IndexNotFoundException
     {
-        String lowerCased = indexName.toLowerCase();
-
-        if ( sysIndices.containsKey( indexName ) )
+        try
+        {
+            oid = oidRegistry.getOid( oid );
+        }
+        catch ( NamingException e )
         {
-            return ( Index ) sysIndices.get( indexName );
+            log.error( "Failed to identify OID for: " + oid, e );
+            throw new IndexNotFoundException( "Failed to identify OID for: " + oid, oid,
e );
         }
-        else if ( sysIndices.containsKey( lowerCased ) )
+
+
+        if ( sysIndices.containsKey( oid ) )
         {
-            return ( Index ) sysIndices.get( lowerCased );
+            return ( Index ) sysIndices.get( oid );
         }
         else
         {
-            throw new IndexNotFoundException( "A system index by the name of " + indexName
+ " does not exist!" );
+            String name = "unknown";
+            try
+            {
+                name = oidRegistry.getPrimaryName( oid );
+            }
+            catch ( NamingException e )
+            {
+                String msg = "Failed to resolve primary name for " + oid + " in user index
lookup";
+                log.error( msg, e );
+                throw new IndexNotFoundException( msg, oid, e );
+            }
+            
+            throw new IndexNotFoundException( "A system index on attribute " + oid + " ("

+                + name + ") does not exist!" );
         }
     }
 

Modified: directory/branches/apacheds/optimization/core/src/test/java/org/apache/directory/server/core/authz/support/RelatedProtectedItemFilterTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/test/java/org/apache/directory/server/core/authz/support/RelatedProtectedItemFilterTest.java?rev=412498&r1=412497&r2=412498&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/test/java/org/apache/directory/server/core/authz/support/RelatedProtectedItemFilterTest.java
(original)
+++ directory/branches/apacheds/optimization/core/src/test/java/org/apache/directory/server/core/authz/support/RelatedProtectedItemFilterTest.java
Wed Jun  7 12:42:17 2006
@@ -46,7 +46,6 @@
 import org.apache.directory.shared.ldap.aci.ProtectedItem;
 import org.apache.directory.shared.ldap.aci.ProtectedItem.MaxValueCountItem;
 import org.apache.directory.shared.ldap.aci.ProtectedItem.RestrictedByItem;
-import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.directory.shared.ldap.name.LdapDN;
 
 
@@ -265,9 +264,12 @@
     }
 
 
+    /* this test requires a real registry with real values or the dummy registry
+     * needs to be altered to contain some usable mock data.  This is a result of
+     * using the registry now in this operation.    
     public void testRangeOfValues() throws Exception
     {
-        Attributes entry = new BasicAttributes();
+        Attributes entry = new BasicAttributes( true );
         entry.put( "attrA", "valueA" );
         Collection tuples = getTuples( new ProtectedItem.RangeOfValues( new PresenceNode(
"attrA" ) ) );
 
@@ -278,6 +280,7 @@
         Assert.assertEquals( 0, filterA.filter( tuples, OperationScope.ATTRIBUTE_TYPE_AND_VALUE,
null, null, USER_NAME,
             null, null, new LdapDN( "ou=testEntry" ), null, null, entry, null ).size() );
     }
+    */
 
 
     public void testRestrictedBy() throws Exception



Mime
View raw message