directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r915970 - in /directory/apacheds/trunk: core-api/src/main/java/org/apache/directory/server/core/filtering/ core-api/src/main/java/org/apache/directory/server/core/interceptor/context/ core-integ/src/test/java/org/apache/directory/server/cor...
Date Wed, 24 Feb 2010 20:36:55 GMT
Author: kayyagari
Date: Wed Feb 24 20:36:54 2010
New Revision: 915970

URL: http://svn.apache.org/viewvc?rev=915970&view=rev
Log:
o fix for DIRSERVER-1380
o also fixed the way noAttributes flag is handled
o added test cases

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/filtering/BaseEntryFilteringCursor.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchOperationContext.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchingOperationContext.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
    directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/filtering/BaseEntryFilteringCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/filtering/BaseEntryFilteringCursor.java?rev=915970&r1=915969&r2=915970&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/filtering/BaseEntryFilteringCursor.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/filtering/BaseEntryFilteringCursor.java
Wed Feb 24 20:36:54 2010
@@ -371,13 +371,26 @@
     
     private void filterContents( ClonedServerEntry entry ) throws Exception
     {
+        boolean typesOnly = getOperationContext().isTypesOnly();
+
         boolean returnAll = getOperationContext().getReturningAttributes() == null ||
-            ( getOperationContext().isAllOperationalAttributes() && getOperationContext().isAllUserAttributes()
);
+            ( getOperationContext().isAllOperationalAttributes() && getOperationContext().isAllUserAttributes()
&& ( ! typesOnly ) );
         
         if ( returnAll )
         {
             return;
         }
+
+        if ( getOperationContext().isNoAttributes() )
+        {
+            for ( AttributeType at : entry.getOriginalEntry().getAttributeTypes() )
+            {
+                entry.remove( entry.get( at ) );
+            }
+            
+            return;
+        }
+        
         
         if ( getOperationContext().isAllUserAttributes() )
         {
@@ -400,6 +413,10 @@
                 {
                     entry.removeAttributes( at );
                 }
+                else if( typesOnly )
+                {
+                    entry.get( at ).clear();
+                }
             }
             
             return;
@@ -426,29 +443,9 @@
                 {
                     entry.removeAttributes( at );
                 }
-            }
-            
-            return;
-        }
-
-        if ( getOperationContext().isNoAttributes() )
-        {
-            for ( AttributeType at : entry.getOriginalEntry().getAttributeTypes() )
-            {
-                boolean isNotRequested = true;
-                
-                for ( AttributeTypeOptions attrOptions:getOperationContext().getReturningAttributes()
)
-                {
-                    if ( attrOptions.getAttributeType().equals( at ) || attrOptions.getAttributeType().isAncestorOf(
at ) )
-                    {
-                        isNotRequested = false;
-                        break;
-                    }
-                }
-
-                if ( isNotRequested )
+                else if( typesOnly )
                 {
-                    entry.removeAttributes( at );
+                    entry.get( at ).clear();
                 }
             }
             
@@ -474,6 +471,10 @@
                 {
                     entry.removeAttributes( at );
                 }
+                else if( typesOnly )
+                {
+                    entry.get( at ).clear();
+                }
             }
         }
     }

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchOperationContext.java?rev=915970&r1=915969&r2=915970&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchOperationContext.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchOperationContext.java
Wed Feb 24 20:36:54 2010
@@ -74,7 +74,7 @@
         this.scope = searchRequest.getScope();
         this.sizeLimit = searchRequest.getSizeLimit();
         this.timeLimit = searchRequest.getTimeLimit();
-        this.noAttributes = searchRequest.getTypesOnly();
+        this.typesOnly = searchRequest.getTypesOnly();
         setReturningAttributes( searchRequest.getAttributes() );
         
         if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchingOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchingOperationContext.java?rev=915970&r1=915969&r2=915970&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchingOperationContext.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/SearchingOperationContext.java
Wed Feb 24 20:36:54 2010
@@ -84,6 +84,8 @@
     /** A flag if the search operation is abandoned */
     protected boolean abandoned = false;
     
+    /** A flag to tell if only the attribute names to be returned */
+    protected boolean typesOnly = false;
     
     /**
      * Creates a new instance of ListOperationContext.
@@ -159,7 +161,7 @@
                     AttributeType attributeType = session.getDirectoryService()
                         .getSchemaManager().lookupAttributeTypeRegistry( id );
                     AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType,
options );
-                    
+                   
                     returningAttributes.add( attrOptions );
                 }
                 catch ( NoSuchAttributeException nsae )
@@ -168,6 +170,12 @@
                     // Unknown attributes should be silently ignored, as RFC 2251 states
                 }
             }
+            
+            // reset the noAttrubte flag if it is already set cause that will be ignored
if any other AT is requested
+            if( noAttributes && ( allUserAttributes || allOperationalAttributes ||
( ! returningAttributes.isEmpty() ) ) )
+            {
+                noAttributes = false;
+            }   
         }
     }
     
@@ -336,6 +344,21 @@
 
 
     /**
+     * @return true, if attribute descriptions alone need to be returned
+     */
+    public boolean isTypesOnly()
+    {
+        return typesOnly;
+    }
+
+
+    public void setTypesOnly( boolean typesOnly )
+    {
+        this.typesOnly = typesOnly;
+    }
+
+
+    /**
      * @param returningAttributes the returningAttributes to set
      */
     public void setReturningAttributes( Set<AttributeTypeOptions> returningAttributes
)

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java?rev=915970&r1=915969&r2=915970&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
Wed Feb 24 20:36:54 2010
@@ -50,10 +50,13 @@
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.shared.ldap.constants.JndiPropertyConstants;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapSizeLimitExceededException;
 import org.apache.directory.shared.ldap.exception.LdapTimeLimitExceededException;
 import org.apache.directory.shared.ldap.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.message.SearchRequestImpl;
+import org.apache.directory.shared.ldap.message.internal.InternalSearchRequest;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -352,7 +355,6 @@
         assertEquals( "Expected number of results returned was incorrect", 1, map.size()
);
         assertTrue( map.containsKey( "ou=testing02,ou=system" ) );
         Attributes attrs = map.get( "ou=testing02,ou=system" );
-        
         assertEquals( 0, attrs.size() );
     }
 
@@ -1629,4 +1631,112 @@
        assertTrue( map.containsKey( "cn=testGroup5,ou=groups,ou=system" ) ); 
        assertFalse( map.containsKey( "cn=testGroup3,ou=groups,ou=system" ) ); 
    }
+   
+   
+   /**
+    *  NO attributes should be returned
+    */
+   @Test
+   public void testSearchTypesOnlyAndNoAttr() throws Exception
+   {
+       SearchControls controls = new SearchControls();
+       controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+       controls.setDerefLinkFlag( false );
+       controls.setReturningAttributes( new String[] { "1.1"  } );
+       sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES,
+               AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() );
+       sysRoot.addToEnvironment( "java.naming.ldap.typesOnly", "true");
+       
+       HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+
+       NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing01)",
controls );
+       
+       while ( list.hasMore() )
+       {
+           SearchResult result = list.next();
+           map.put( result.getName(), result.getAttributes() );
+       }
+
+       assertEquals( "Expected number of results returned was incorrect!", 1, map.size()
);
+
+       Attributes attrs = map.get( "ou=testing01,ou=system" );
+
+       assertEquals( 0, attrs.size() );
+   }
+
+   
+   /**
+    * operational attributes with no values must be returned
+    */
+   @Test
+   public void testSearchTypesOnlyWithNoAttrAndOperationalAttr() throws Exception
+   {
+       SearchControls controls = new SearchControls();
+       controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+       controls.setDerefLinkFlag( false );
+       controls.setReturningAttributes( new String[] { "1.1", "+"  } );
+       sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES,
+               AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() );
+       sysRoot.addToEnvironment( "java.naming.ldap.typesOnly", "true");
+       
+       HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+
+       NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing01)",
controls );
+       
+       while ( list.hasMore() )
+       {
+           SearchResult result = list.next();
+           map.put( result.getName(), result.getAttributes() );
+       }
+
+       assertEquals( "Expected number of results returned was incorrect!", 1, map.size()
);
+
+       Attributes attrs = map.get( "ou=testing01,ou=system" );
+
+       assertNotNull( attrs.get( SchemaConstants.ENTRY_UUID_AT ) );
+       assertNotNull( attrs.get( SchemaConstants.CREATORS_NAME_AT ) );
+       
+       assertEquals( 0, attrs.get( SchemaConstants.ENTRY_UUID_AT ).size() );
+       assertEquals( 0, attrs.get( SchemaConstants.CREATORS_NAME_AT ).size() );
+   }
+
+   
+   /**
+    * all user attributes with no values must be returned
+    */
+   @Test
+   public void testSearchTypesOnlyWithNullReturnAttr() throws Exception
+   {
+       SearchControls controls = new SearchControls();
+       controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+       controls.setDerefLinkFlag( false );
+       sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES,
+               AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() );
+       sysRoot.addToEnvironment( "java.naming.ldap.typesOnly", "true");
+       
+       HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+
+       NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing01)",
controls );
+       
+       while ( list.hasMore() )
+       {
+           SearchResult result = list.next();
+           map.put( result.getName(), result.getAttributes() );
+       }
+
+       assertEquals( "Expected number of results returned was incorrect!", 1, map.size()
);
+
+       Attributes attrs = map.get( "ou=testing01,ou=system" );
+
+       
+       assertNotNull( attrs.get( SchemaConstants.OU_AT ) );
+       assertNotNull( attrs.get( "integerAttribute" ) );
+
+       assertNotNull( attrs.get( SchemaConstants.OU_AT ).get() );
+       assertNotNull( attrs.get( "integerAttribute" ).get() );
+       
+       assertNull( attrs.get( SchemaConstants.ENTRY_UUID_AT ) );
+       assertNull( attrs.get( SchemaConstants.CREATORS_NAME_AT ) );
+   }
+   
 }

Modified: directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java?rev=915970&r1=915969&r2=915970&view=diff
==============================================================================
--- directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
(original)
+++ directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
Wed Feb 24 20:36:54 2010
@@ -315,6 +315,13 @@
         OperationManager operationManager = service.getOperationManager();
         EntryFilteringCursor results = null;
         OperationContext opContext;
+        
+        Object typesOnlyObj = getEnvironment().get( "java.naming.ldap.typesOnly" );
+        boolean typesOnly = false;
+        if( typesOnlyObj != null )
+        {
+            typesOnly = Boolean.parseBoolean( typesOnlyObj.toString() );
+        }
 
         // We have to check if it's a compare operation or a search. 
         // A compare operation has a OBJECT scope search, the filter must
@@ -338,6 +345,8 @@
                 searchControls );
             opContext.addRequestControls( JndiUtils.fromJndiControls( requestControls ) );
             
+            ( ( SearchOperationContext ) opContext ).setTypesOnly(  typesOnly );
+            
             if ( result )
             {
                 ServerEntry emptyEntry = new DefaultServerEntry( service.getSchemaManager(),
LdapDN.EMPTY_LDAPDN ); 
@@ -356,7 +365,8 @@
             opContext = new SearchOperationContext( session, dn, aliasDerefMode, filter,
                 searchControls );
             opContext.addRequestControls( JndiUtils.fromJndiControls( requestControls ) );
-
+            ( ( SearchOperationContext ) opContext ).setTypesOnly(  typesOnly );
+            
             // Inject the referral handling into the operation context
             injectReferralControl( opContext );
 



Mime
View raw message