directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r499731 - /directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Date Thu, 25 Jan 2007 10:55:33 GMT
Author: elecharny
Date: Thu Jan 25 02:55:32 2007
New Revision: 499731

URL: http://svn.apache.org/viewvc?view=rev&rev=499731
Log:
Fixed DIRSERVER-836

Modified:
    directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java

Modified: directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?view=diff&rev=499731&r1=499730&r2=499731
==============================================================================
--- directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
(original)
+++ directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Thu Jan 25 02:55:32 2007
@@ -370,6 +370,73 @@
         return new SearchResultFilteringEnumeration( e, new SearchControls(), invocation,
binaryAttributeFilter );
     }
 
+    /**
+     * Remove all unknown attributes from the searchControls, to avoid an exception.
+     * 
+     * RFC 2251 states that :
+     * " Attributes MUST be named at most once in the list, and are returned "
+     * " at most once in an entry. "
+     * " If there are attribute descriptions in "
+     * " the list which are not recognized, they are ignored by the server."
+     *
+     * @param searchCtls The SearchControls we will filter
+     */
+    private void filterAttributesToReturn( SearchControls searchCtls ) throws NamingException
+    {
+        String[] attributes = searchCtls.getReturningAttributes();
+
+        if ( ( attributes == null ) || ( attributes.length == 0 ) )
+        {
+            return;
+        }
+        
+        Map filteredAttrs = new HashMap(); 
+        
+        for ( int i = 0; i < attributes.length; i++ )
+        {
+            String attribute = attributes[i];
+            
+            // Skip special attributes
+            if ( ( "*".equals( attribute ) ) || ( "+".equals( attribute ) ) || ( "1.1".equals(
attribute ) ) )
+            {
+                if ( !filteredAttrs.containsKey( attribute ) )
+                {
+                    filteredAttrs.put( attribute, attribute );
+                }
+
+                continue;
+            }
+            
+            if ( globalRegistries.getAttributeTypeRegistry().hasAttributeType( attribute
) )
+            {
+                String oid = globalRegistries.getOidRegistry().getOid( attribute );
+                
+                if ( !filteredAttrs.containsKey( oid ) )
+                {
+                    filteredAttrs.put( oid, attribute );
+                }
+            }
+        }
+        
+        // If we still have the same attribute number, then we can just get out the method
+        if ( filteredAttrs.size() == attributes.length )
+        {
+            return;
+        }
+        
+        // Some attributes have been removed. let's modify the searchControl
+        String[] newAttributesList = new String[filteredAttrs.size()];
+        
+        int pos = 0;
+        Iterator keys = filteredAttrs.keySet().iterator();
+        
+        while ( keys.hasNext() )
+        {
+            newAttributesList[pos++] = (String)filteredAttrs.get( keys.next() );
+        }
+        
+        searchCtls.setReturningAttributes( newAttributesList );
+    }
 
     /**
      * 
@@ -379,6 +446,12 @@
     {
         // check to make sure the DN searched for is a subentry
         Invocation invocation = InvocationStack.getInstance().peek();
+
+        // We have to eliminate bad attributes from the request, accordingly
+        // to RFC 2251, chap. 4.5.1. Basically, all unknown attributes are removed
+        // from the list
+        filterAttributesToReturn( searchCtls );
+        
         if ( !subschemaSubentryDn.toNormName().equals( base.toNormName() ) )
         {
             NamingEnumeration e = nextInterceptor.search( base, env, filter, searchCtls );



Mime
View raw message