directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r499739 - /directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Date Thu, 25 Jan 2007 11:13:05 GMT
Author: elecharny
Date: Thu Jan 25 03:12:59 2007
New Revision: 499739

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

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

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?view=diff&rev=499739&r1=499738&r2=499739
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Thu Jan 25 03:12:59 2007
@@ -382,6 +382,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<String, String> filteredAttrs = new HashMap<String, String>(); 
+        
+        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 ( registries.getAttributeTypeRegistry().hasAttributeType( attribute ) )
+            {
+                String oid = registries.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;
+        
+        for ( String key:filteredAttrs.keySet() )
+        {
+            newAttributesList[pos++] = filteredAttrs.get( key );
+        }
+        
+        searchCtls.setReturningAttributes( newAttributesList );
+    }
+
 
     /**
      * 
@@ -391,6 +458,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