directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r370008 - in /directory/trunks: apacheds/core-unit/src/test/java/org/apache/ldap/server/subtree/ apacheds/core/src/main/java/org/apache/ldap/server/subtree/ common/ldap/src/main/java/org/apache/ldap/common/message/
Date Wed, 18 Jan 2006 02:10:56 GMT
Author: akarasulu
Date: Tue Jan 17 18:10:49 2006
New Revision: 370008

URL: http://svn.apache.org/viewcvs?rev=370008&view=rev
Log:
added subentries control logic: now all of rfc 3672 is implemented

Added:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/SubentriesControl.java
  (with props)
Removed:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/SubentryRequestControl.java
Modified:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/subtree/SubentryServiceTest.java
    directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/subtree/SubentryService.java

Modified: directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/subtree/SubentryServiceTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/subtree/SubentryServiceTest.java?rev=370008&r1=370007&r2=370008&view=diff
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/subtree/SubentryServiceTest.java
(original)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/subtree/SubentryServiceTest.java
Tue Jan 17 18:10:49 2006
@@ -20,11 +20,14 @@
 import org.apache.ldap.server.unit.AbstractAdminTestCase;
 import org.apache.ldap.common.message.LockableAttributesImpl;
 import org.apache.ldap.common.message.LockableAttributeImpl;
+import org.apache.ldap.common.message.SubentriesControl;
 import org.apache.ldap.common.exception.LdapNoSuchAttributeException;
 
 import javax.naming.NamingException;
 import javax.naming.NamingEnumeration;
 import javax.naming.directory.*;
+import javax.naming.ldap.Control;
+
 import java.util.Map;
 import java.util.HashMap;
 
@@ -856,5 +859,35 @@
         assertNotNull( "cn=marked,ou=services,ou=configuration should be marked", autonomousSubentry
);
         assertEquals( "cn=testsubentry,ou=system", autonomousSubentry.get() );
         assertEquals( 1, autonomousSubentry.size() );
+    }
+    
+    
+    public void testSubentriesControl() throws Exception
+    {
+        addAdministrativeRole( "autonomousArea" );
+        super.sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion()
);
+        SearchControls searchControls = new SearchControls();
+        searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+
+        // perform the search without the control
+        Map entries = new HashMap();
+        NamingEnumeration list = super.sysRoot.search( "", "(objectClass=*)", searchControls
);
+        while ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+            entries.put( result.getName(), result );
+        }
+        assertTrue( entries.size() > 1  );
+        assertNull( entries.get( "cn=testsubentry,ou=system" ) );
+        
+        // now add the control with visibility set to true where all entries 
+        // except subentries disappear
+        SubentriesControl ctl = new SubentriesControl();
+        ctl.setVisibility( true );
+        super.sysRoot.setRequestControls( new Control[] { ctl } );
+        list = super.sysRoot.search( "", "(objectClass=*)", searchControls );
+        SearchResult result = ( SearchResult ) list.next();
+        assertFalse( list.hasMore() );
+        assertEquals( "cn=testsubentry,ou=system", result.getName() );
     }
 }

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/subtree/SubentryService.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/subtree/SubentryService.java?rev=370008&r1=370007&r2=370008&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/subtree/SubentryService.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/subtree/SubentryService.java
Tue Jan 17 18:10:49 2006
@@ -27,7 +27,7 @@
 import org.apache.ldap.server.configuration.InterceptorConfiguration;
 import org.apache.ldap.server.partition.DirectoryPartitionNexus;
 import org.apache.ldap.server.schema.ConcreteNameComponentNormalizer;
-import org.apache.ldap.common.message.SubentryRequestControl;
+import org.apache.ldap.common.message.SubentriesControl;
 import org.apache.ldap.common.message.ResultCodeEnum;
 import org.apache.ldap.common.message.LockableAttributesImpl;
 import org.apache.ldap.common.message.LockableAttributeImpl;
@@ -39,6 +39,7 @@
 import org.apache.ldap.common.exception.LdapNoSuchAttributeException;
 import org.apache.ldap.common.exception.LdapInvalidAttributeValueException;
 import org.apache.ldap.common.exception.LdapSchemaViolationException;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -61,7 +62,7 @@
 public class SubentryService extends BaseInterceptor
 {
     /** the subentry control OID */
-    private static final String SUBENTRY_CONTROL = "1.3.6.1.4.1.4203.1.10.1";
+    private static final String SUBENTRY_CONTROL = SubentriesControl.CONTROL_OID;
     /** the objectClass value for a subentry */
     private static final String SUBENTRY_OBJECTCLASS = "subentry";
     /** the objectClass OID for a subentry */
@@ -89,27 +90,6 @@
         COLLECTIVE_ATTRIBUTE_SUBENTRIES
     };
 
-    /**
-     * the search result filter to filter out subentries based on objectClass values.
-     */
-    private static final SearchResultFilter SUBENTRY_FILTER = new SearchResultFilter()
-    {
-        public boolean accept( Invocation invocation, SearchResult result, SearchControls
controls )
-        {
-            Attribute objectClasses = result.getAttributes().get( "objectClass" );
-
-            if ( objectClasses == null )
-            {
-                return true;
-            }
-
-//            String[] SUBENTRY_DESC = new String[] { SUBENTRY_OBJECTCLASS, SUBENTRY_OBJECTCLASS_OID
};
-//
-//            boolean isSubentry = AttributeUtils.containsAnyValues( objectClasses, SUBENTRY_DESC,
type );
-            return !( objectClasses.contains(SUBENTRY_OBJECTCLASS) || objectClasses.contains(SUBENTRY_OBJECTCLASS_OID)
);
-        }
-    };
-
     private static final Logger log = LoggerFactory.getLogger( SubentryService.class );
 
     /** the hash mapping the DN of a subentry to its SubtreeSpecification */
@@ -180,7 +160,8 @@
 
         if ( ! isSubentryVisible( invocation ) )
         {
-            return new SearchResultFilteringEnumeration( e, new SearchControls(), invocation,
SUBENTRY_FILTER );
+            return new SearchResultFilteringEnumeration( e, new SearchControls(), 
+                invocation, new HideSubentriesFilter() );
         }
 
         return e;
@@ -202,10 +183,12 @@
         // for subtree and one level scope we filter
         if ( ! isSubentryVisible( invocation ) )
         {
-            return new SearchResultFilteringEnumeration( e, searchCtls, invocation, SUBENTRY_FILTER
);
+            return new SearchResultFilteringEnumeration( e, searchCtls, invocation, new HideSubentriesFilter()
);
+        }
+        else
+        {            
+            return new SearchResultFilteringEnumeration( e, searchCtls, invocation, new HideEntriesFilter()
);
         }
-
-        return e;
     }
 
 
@@ -232,8 +215,8 @@
             // found the subentry request control so we return its value
             if ( reqControls[ii].getID().equals( SUBENTRY_CONTROL ) )
             {
-                SubentryRequestControl subentryControl = ( SubentryRequestControl ) reqControls[ii];
-                return subentryControl.getSubentryVisibility();
+                SubentriesControl subentriesControl = ( SubentriesControl ) reqControls[ii];
+                return subentriesControl.isVisible();
             }
         }
 
@@ -1263,5 +1246,114 @@
         ModificationItem[] mods = new ModificationItem[modList.size()];
         mods = ( ModificationItem[] ) modList.toArray( mods );
         return mods;
+    }
+
+
+    /**
+     * SearchResultFilter used to filter out subentries based on objectClass values.
+     */
+    public class HideSubentriesFilter implements SearchResultFilter
+    {
+        public boolean accept(Invocation invocation, SearchResult result, SearchControls
controls) throws NamingException
+        {
+            String dn = result.getName();
+            
+            // see if we can get a match without normalization
+            if ( subtrees.containsKey( dn ) )
+            {
+                return false;
+            }
+            
+            // see if we can use objectclass if present
+            Attribute objectClasses = result.getAttributes().get( "objectClass" );
+            if ( objectClasses != null )
+            {
+                if ( objectClasses.contains( SUBENTRY_OBJECTCLASS ) )
+                {
+                    return false;
+                }
+                
+                if ( objectClasses.contains( SUBENTRY_OBJECTCLASS_OID ) )
+                {
+                    return false;
+                }
+                
+                for ( int ii = 0; ii < objectClasses.size(); ii++ )
+                {
+                    String oc = ( String ) objectClasses.get( ii );
+                    if ( oc.equalsIgnoreCase( SUBENTRY_OBJECTCLASS ) )
+                    {
+                        return false;
+                    }
+                }
+                
+                return true;
+            }
+
+            if ( ! result.isRelative() )
+            {
+                String normalizedDn = dnParser.parse( dn ).toString();
+                return !subtrees.containsKey( normalizedDn );
+            }
+            
+            Name name = dnParser.parse( invocation.getCaller().getNameInNamespace() );
+            name.addAll( dnParser.parse( result.getName() ) );
+            return !subtrees.containsKey( name.toString() );
+        }
+    }
+
+
+    /**
+     * SearchResultFilter used to filter out normal entries but shows subentries based on

+     * objectClass values.
+     */
+    public class HideEntriesFilter implements SearchResultFilter
+    {
+        public boolean accept(Invocation invocation, SearchResult result, SearchControls
controls) throws NamingException
+        {
+            String dn = result.getName();
+            
+            // see if we can get a match without normalization
+            if ( subtrees.containsKey( dn ) )
+            {
+                return true;
+            }
+            
+            // see if we can use objectclass if present
+            Attribute objectClasses = result.getAttributes().get( "objectClass" );
+            if ( objectClasses != null )
+            {
+                if ( objectClasses.contains( SUBENTRY_OBJECTCLASS ) )
+                {
+                    return true;
+                }
+                
+                if ( objectClasses.contains( SUBENTRY_OBJECTCLASS_OID ) )
+                {
+                    return true;
+                }
+                
+                for ( int ii = 0; ii < objectClasses.size(); ii++ )
+                {
+                    String oc = ( String ) objectClasses.get( ii );
+                    if ( oc.equalsIgnoreCase( SUBENTRY_OBJECTCLASS ) )
+                    {
+                        return true;
+                    }
+                }
+                
+                return false;
+            }
+
+            if ( ! result.isRelative() )
+            {
+                String normalizedDn = dnParser.parse( dn ).toString();
+                return subtrees.containsKey( normalizedDn );
+            }
+            
+            Name name = dnParser.parse( invocation.getCaller().getNameInNamespace() );
+            name.addAll( dnParser.parse( result.getName() ) );
+            return subtrees.containsKey( name.toString() );
+        }
     }
 }

Added: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/SubentriesControl.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/SubentriesControl.java?rev=370008&view=auto
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/SubentriesControl.java
(added)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/SubentriesControl.java
Tue Jan 17 18:10:49 2006
@@ -0,0 +1,113 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.common.message;
+
+
+import org.apache.asn1.codec.EncoderException;
+import org.apache.ldap.common.codec.search.controls.SubEntryControl;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The control for the visibility of subentries with search operations.  For
+ * convenience we attach section 3 from <a href="http://www.faqs.org/rfcs/rfc3672.html">
+ * RFC 3672</a> where the control is defined:
+ * <pre>
+ *  3.  Subentries Control
+ * 
+ *  The subentries control MAY be sent with a searchRequest to control
+ *  the visibility of entries and subentries which are within scope.
+ *  Non-visible entries or subentries are not returned in response to the
+ *  request.
+ * 
+ *  The subentries control is an LDAP Control whose controlType is
+ *  1.3.6.1.4.1.4203.1.10.1, criticality is TRUE or FALSE (hence absent),
+ *  and controlValue contains a BER-encoded BOOLEAN indicating
+ *  visibility.  A controlValue containing the value TRUE indicates that
+ *  subentries are visible and normal entries are not.  A controlValue
+ *  containing the value FALSE indicates that normal entries are visible
+ *  and subentries are not.
+ * 
+ *  Note that TRUE visibility has the three octet encoding { 01 01 FF }
+ *  and FALSE visibility has the three octet encoding { 01 01 00 }.
+ *  
+ *  The controlValue SHALL NOT be absent.
+ *  
+ *  In absence of this control, subentries are not visible to singleLevel
+ *  and wholeSubtree scope Search requests but are visible to baseObject
+ *  scope Search requests.
+ *  
+ *  There is no corresponding response control.
+ *  
+ *  This control is not appropriate for non-Search operations.
+ * </pre>
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SubentriesControl extends ControlImpl
+{
+    private static final long serialVersionUID = -2356861450876343999L;
+    private static final Logger log = LoggerFactory.getLogger( SubentriesControl.class );
+    public static final String CONTROL_OID = "1.3.6.1.4.1.4203.1.10.1";
+    
+    /** the visibility for this control */
+    private boolean visibility = false;
+
+    
+    public SubentriesControl()
+    {
+        super();
+        setType( CONTROL_OID );
+    }
+    
+    
+    public void setVisibility( boolean visibility )
+    {
+        this.visibility = visibility;
+    }
+
+    
+    public boolean isVisible()
+    {
+        return visibility;
+    }
+
+    
+    public byte[] getEncodedValue()
+    {
+        if ( getValue() == null )
+        {
+            SubEntryControl ctl = new SubEntryControl();
+            ctl.setVisibility( isVisible() );
+
+            try
+            {
+                setValue( ctl.encode( null ).array() );
+            }
+            catch ( EncoderException e )
+            {
+                log.error( "Failed to encode SubentriesControl", e );
+            }
+        }
+        
+        return getValue();
+    }
+}

Propchange: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/SubentriesControl.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message