directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r366700 - in /directory/trunk: apacheds-server-unit/src/test/java/org/apache/ldap/server/ ldap-common/ ldap-protocol/src/main/java/org/apache/ldap/server/protocol/ ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/
Date Sat, 07 Jan 2006 09:45:32 GMT
Author: akarasulu
Date: Sat Jan  7 01:45:27 2006
New Revision: 366700

URL: http://svn.apache.org/viewcvs?rev=366700&view=rev
Log:
server now responds to unsupport controls with an UNAVAILABLECITICALEXTENSION response: added
tests for fix to DIREVE-318

Modified:
    directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/MiscTest.java
    directory/trunk/ldap-common/   (props changed)
    directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java
    directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/HandlerUtil.java

Modified: directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/MiscTest.java
URL: http://svn.apache.org/viewcvs/directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/MiscTest.java?rev=366700&r1=366699&r2=366700&view=diff
==============================================================================
--- directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/MiscTest.java
(original)
+++ directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/MiscTest.java
Sat Jan  7 01:45:27 2006
@@ -17,8 +17,12 @@
 package org.apache.ldap.server;
 
 
+import org.apache.asn1.util.Asn1StringUtils;
 import org.apache.ldap.server.configuration.MutableDirectoryPartitionConfiguration;
+import org.apache.ldap.common.message.Control;
+import org.apache.ldap.common.util.ArrayUtils;
 import org.apache.ldap.common.util.EmptyEnumeration;
+import org.apache.ldap.common.util.StringTools;
 
 import java.util.Hashtable;
 import java.util.Set;
@@ -28,7 +32,9 @@
 import javax.naming.Context;
 import javax.naming.NoPermissionException;
 import javax.naming.NamingEnumeration;
+import javax.naming.OperationNotSupportedException;
 import javax.naming.directory.*;
+import javax.naming.ldap.InitialLdapContext;
 
 
 /**
@@ -313,5 +319,85 @@
         e = sysRoot.search( "", "(objectclass=*)", cons );
         assertNotNull( e );
         assertFalse( e.getClass().equals( EmptyEnumeration.class ) );
+    }
+    
+    
+    public void testFailureWithUnsupportedControl() throws Exception
+    {
+        Control unsupported = new Control()
+        {
+            boolean isCritical = true;
+            private static final long serialVersionUID = 1L;
+
+            public String getType()
+            {
+                return "1.1.1.1";
+            }
+
+            public void setType(String oid)
+            {
+            }
+
+            public byte[] getValue()
+            {
+                return new byte[0];
+            }
+
+            public void setValue(byte[] value)
+            {
+            }
+
+            public boolean isCritical()
+            {
+                return isCritical;
+            }
+
+            public void setCritical(boolean isCritical)
+            {
+                this.isCritical = isCritical;
+            }
+
+            public String getID()
+            {
+                return "1.1.1.1";
+            }
+
+            public byte[] getEncodedValue()
+            {
+                return new byte[0];
+            }
+        };
+        final Hashtable env = new Hashtable();
+
+        env.put( Context.PROVIDER_URL, "ldap://localhost:" + port + "/ou=system" );
+        env.put("java.naming.ldap.version", "3");
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+        env.put( Context.SECURITY_CREDENTIALS, "secret" );
+        env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+        InitialLdapContext ctx = new InitialLdapContext( env, null );
+
+        Attributes user = new BasicAttributes( "cn", "Kate Bush", true );
+        Attribute oc = new BasicAttribute( "objectClass" );
+        oc.add( "top" );
+        oc.add( "person" );
+        oc.add( "organizationalPerson" );
+        oc.add( "inetOrgPerson" );
+        user.put( oc );
+        user.put( "sn", "Bush" );
+        user.put( "userPassword", "Aerial" );
+        ctx.setRequestControls( new Control[] { unsupported } );
+        
+        try
+        {
+            ctx.createSubcontext( "cn=Kate Bush", user );
+        }
+        catch( OperationNotSupportedException e ) {}
+        
+        unsupported.setCritical( false );
+        DirContext kate = ctx.createSubcontext( "cn=Kate Bush", user );
+        assertNotNull( kate );
+        assertTrue( ArrayUtils.isEquals( Asn1StringUtils.getBytesUtf8( "Aerial" ), 
+            kate.getAttributes( "" ).get( "userPassword" ).get() ) );
     }
 }

Propchange: directory/trunk/ldap-common/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sat Jan  7 01:45:27 2006
@@ -1,4 +1,5 @@
 *.ipr
+.cdtproject
 *.iml
 .deployables
 *.iws

Modified: directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java
URL: http://svn.apache.org/viewcvs/directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java?rev=366700&r1=366699&r2=366700&view=diff
==============================================================================
--- directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java
(original)
+++ directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java
Sat Jan  7 01:45:27 2006
@@ -19,9 +19,11 @@
 
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 import javax.naming.Context;
 
@@ -36,6 +38,7 @@
 import org.apache.ldap.common.message.BindRequestImpl;
 import org.apache.ldap.common.message.CompareRequest;
 import org.apache.ldap.common.message.CompareRequestImpl;
+import org.apache.ldap.common.message.Control;
 import org.apache.ldap.common.message.DeleteRequest;
 import org.apache.ldap.common.message.DeleteRequestImpl;
 import org.apache.ldap.common.message.ExtendedRequest;
@@ -46,7 +49,10 @@
 import org.apache.ldap.common.message.ModifyDnRequestImpl;
 import org.apache.ldap.common.message.ModifyRequest;
 import org.apache.ldap.common.message.ModifyRequestImpl;
+import org.apache.ldap.common.message.Request;
 import org.apache.ldap.common.message.ResultCodeEnum;
+import org.apache.ldap.common.message.ResultResponse;
+import org.apache.ldap.common.message.ResultResponseRequest;
 import org.apache.ldap.common.message.SearchRequest;
 import org.apache.ldap.common.message.SearchRequestImpl;
 import org.apache.ldap.common.message.UnbindRequest;
@@ -86,10 +92,11 @@
 {
     /** the constant service name of this ldap protocol provider **/
     public static final String SERVICE_NAME = "ldap";
-
     /** a map of the default request object class name to the handler class name */
     private static final Map DEFAULT_HANDLERS;
-
+    /** a set of supported controls */
+    private static final Set SUPPORTED_CONTROLS;
+    
     static
     {
         HashMap map = new HashMap();
@@ -135,6 +142,11 @@
         map.put( UnbindRequestImpl.class.getName(), UnbindHandler.class );
 
         DEFAULT_HANDLERS = Collections.unmodifiableMap( map );
+        
+        HashSet set = new HashSet();
+        set.add( "2.16.840.1.113730.3.4.3" );  // PersistentSearch control
+        set.add( "2.16.840.1.113730.3.4.7" );  // EntryChangeNotification control
+        SUPPORTED_CONTROLS = Collections.unmodifiableSet( set );
     }
 
     /** the underlying provider codec factory */
@@ -390,6 +402,24 @@
                 req.setOid( "1.3.6.1.4.1.1466.20037" );
                 req.setPayload( "UNSECURED".getBytes( "ISO-8859-1" ) );
                 message = req;
+            }
+            
+            if ( ( ( Request ) message ).getControls().size() > 0 && message instanceof
ResultResponseRequest )
+            {
+                ResultResponseRequest req = ( ResultResponseRequest ) message;
+                Iterator controls = req.getControls().values().iterator();
+                while ( controls.hasNext() )
+                {
+                    Control control = ( Control ) controls.next();
+                    if ( control.isCritical() && ! SUPPORTED_CONTROLS.contains( control.getID()
) )
+                    {
+                        ResultResponse resp = req.getResultResponse();
+                        resp.getLdapResult().setErrorMessage( "Unsupport critical control:
" + control.getID() );
+                        resp.getLdapResult().setResultCode( ResultCodeEnum.UNAVAILABLECRITICALEXTENSION
);
+                        session.write( resp );
+                        return;
+                    }
+                }
             }
             
             super.messageReceived( session, message );

Modified: directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/HandlerUtil.java
URL: http://svn.apache.org/viewcvs/directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/HandlerUtil.java?rev=366700&r1=366699&r2=366700&view=diff
==============================================================================
--- directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/HandlerUtil.java
(original)
+++ directory/trunk/ldap-protocol/src/main/java/org/apache/ldap/server/protocol/support/HandlerUtil.java
Sat Jan  7 01:45:27 2006
@@ -20,7 +20,6 @@
                 }
             }
         }
-        
     }
     */
 }



Mime
View raw message