directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r428107 - in /directory/trunks/apacheds: core-unit/src/test/java/org/apache/directory/server/core/jndi/ core/src/main/java/org/apache/directory/server/core/jndi/
Date Wed, 02 Aug 2006 19:29:44 GMT
Author: akarasulu
Date: Wed Aug  2 12:29:44 2006
New Revision: 428107

URL: http://svn.apache.org/viewvc?rev=428107&view=rev
Log:
fix for DIRSERVER-628

Modified:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/jndi/CreateContextITest.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java

Modified: directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/jndi/CreateContextITest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/jndi/CreateContextITest.java?rev=428107&r1=428106&r2=428107&view=diff
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/jndi/CreateContextITest.java
(original)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/jndi/CreateContextITest.java
Wed Aug  2 12:29:44 2006
@@ -17,12 +17,15 @@
 package org.apache.directory.server.core.jndi;
 
 
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
 
 import org.apache.directory.server.core.unit.AbstractAdminTestCase;
 
@@ -35,6 +38,50 @@
  */
 public class CreateContextITest extends AbstractAdminTestCase
 {
+    protected Attributes getPersonAttributes( String sn, String cn )
+    {
+        Attributes attrs = new BasicAttributes();
+        Attribute ocls = new BasicAttribute( "objectClass" );
+        ocls.add( "top" );
+        ocls.add( "person" );
+        attrs.put( ocls );
+        attrs.put( "cn", cn );
+        attrs.put( "sn", sn );
+
+        return attrs;
+    }
+
+
+    /**
+     * DIRSERVER-628: Creation of entry with multivalued RDN leads to wrong
+     * attribute value.
+     */
+    public void testMultiValuedRdn() throws NamingException
+    {
+
+        Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+        String rdn = "cn=Kate Bush+sn=Bush";
+        super.sysRoot.createSubcontext( rdn, attrs );
+
+        SearchControls sctls = new SearchControls();
+        sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        String filter = "(sn=Bush)";
+        String base = "";
+
+        NamingEnumeration enm = sysRoot.search( base, filter, sctls );
+        while ( enm.hasMore() )
+        {
+            SearchResult sr = ( SearchResult ) enm.next();
+            attrs = sr.getAttributes();
+            Attribute cn = sr.getAttributes().get( "cn" );
+            assertNotNull( cn );
+            assertTrue( cn.contains( "Kate Bush" ) );
+        }
+
+        sysRoot.destroySubcontext( rdn );
+    }
+    
+    
     /**
      * Tests the creation and subsequent read of a new JNDI context under the
      * system context root.

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java?rev=428107&r1=428106&r2=428107&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
Wed Aug  2 12:29:44 2006
@@ -52,8 +52,9 @@
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
+import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
 import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.util.NamespaceTools;
+import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 
@@ -296,11 +297,20 @@
         Attributes attributes = new LockableAttributesImpl();
         LdapDN target = buildTarget( name );
 
-        String rdn = name.get( name.size() - 1 );
-        String rdnAttribute = NamespaceTools.getRdnAttribute( rdn );
-        String rdnValue = NamespaceTools.getRdnValue( rdn );
-
-        attributes.put( rdnAttribute, rdnValue );
+        Rdn rdn = target.getRdn( target.size() - 1 );
+        if ( rdn.size() == 1 )
+        {
+            attributes.put( rdn.getType(), rdn.getValue() );
+        }
+        else
+        {
+            for ( Iterator ii = rdn.iterator(); ii.hasNext(); /**/ )
+            {
+                AttributeTypeAndValue atav = ( AttributeTypeAndValue ) ii.next();
+                attributes.put( atav.getType(), atav.getValue() );
+            }
+        }
+        
         attributes.put( JavaLdapSupport.OBJECTCLASS_ATTR, JavaLdapSupport.JCONTAINER_ATTR
);
         attributes.put( JavaLdapSupport.OBJECTCLASS_ATTR, JavaLdapSupport.TOP_ATTR );
 

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java?rev=428107&r1=428106&r2=428107&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
Wed Aug  2 12:29:44 2006
@@ -21,6 +21,7 @@
 import java.io.Serializable;
 import java.text.ParseException;
 import java.util.Hashtable;
+import java.util.Iterator;
 
 import javax.naming.Name;
 import javax.naming.NamingEnumeration;
@@ -46,8 +47,9 @@
 import org.apache.directory.shared.ldap.filter.FilterParserImpl;
 import org.apache.directory.shared.ldap.filter.PresenceNode;
 import org.apache.directory.shared.ldap.filter.SimpleNode;
+import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
 import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.util.NamespaceTools;
+import org.apache.directory.shared.ldap.name.Rdn;
 
 
 /**
@@ -330,19 +332,40 @@
         }
 
         LdapDN target = buildTarget( name );
-        String rdn = name.get( name.size() - 1 );
-        String rdnAttribute = NamespaceTools.getRdnAttribute( rdn );
-        String rdnValue = NamespaceTools.getRdnValue( rdn );
-
-        // Clone the attributes and add the Rdn attributes
+        Rdn rdn = target.getRdn( target.size() - 1 );
+        
         Attributes attributes = ( Attributes ) attrs.clone();
-        boolean doRdnPut = attributes.get( rdnAttribute ) == null;
-        doRdnPut = doRdnPut || attributes.get( rdnAttribute ).size() == 0;
-        doRdnPut = doRdnPut || !attributes.get( rdnAttribute ).contains( rdnValue );
+        if ( rdn.size() == 1 )
+        {
+            String rdnAttribute = rdn.getType();
+            String rdnValue = rdn.getValue();
 
-        if ( doRdnPut )
+            // Add the Rdn attribute
+            boolean doRdnPut = attributes.get( rdnAttribute ) == null;
+            doRdnPut = doRdnPut || attributes.get( rdnAttribute ).size() == 0;
+            doRdnPut = doRdnPut || !attributes.get( rdnAttribute ).contains( rdnValue );
+    
+            if ( doRdnPut )
+            {
+                attributes.put( rdnAttribute, rdnValue );
+            }
+        }
+        else
         {
-            attributes.put( rdnAttribute, rdnValue );
+            for ( Iterator ii = rdn.iterator(); ii.hasNext(); /**/ )
+            {
+                AttributeTypeAndValue atav = ( AttributeTypeAndValue ) ii.next();
+
+                // Add the Rdn attribute
+                boolean doRdnPut = attributes.get( atav.getType() ) == null;
+                doRdnPut = doRdnPut || attributes.get( atav.getType() ).size() == 0;
+                doRdnPut = doRdnPut || !attributes.get( atav.getType() ).contains( atav.getValue()
);
+        
+                if ( doRdnPut )
+                {
+                    attributes.put( atav.getType(), atav.getValue() );
+                }
+            }
         }
 
         // Add the new context to the server which as a side effect adds



Mime
View raw message