harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r660155 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/internal/nls/ main/java/org/apache/harmony/jndi/provider/ldap/ test/java/org/apache/harmony/jndi/provider/ldap/
Date Mon, 26 May 2008 10:23:11 GMT
Author: tellison
Date: Mon May 26 03:23:09 2008
New Revision: 660155

URL: http://svn.apache.org/viewvc?rev=660155&view=rev
Log:
Apply patch HARMONY-5842 ([classlib][jndi][ldap] - LdapSchemaContextImpl.rename() and modifyAttributes()
doesn't deal with name correctly)

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties?rev=660155&r1=660154&r2=660155&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/nls/messages.properties
Mon May 26 03:23:09 2008
@@ -219,3 +219,5 @@
 ldap.37=Can't delete schema root
 ldap.38=Can't modify schema root
 ldap.39=Can't rename schema
+ldap.3A=Can't rename empty name
+ldap.3B=Can't rename across contexts

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java?rev=660155&r1=660154&r2=660155&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextImpl.java
Mon May 26 03:23:09 2008
@@ -21,6 +21,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.Map.Entry;
 
 import javax.naming.Binding;
 import javax.naming.CompositeName;
@@ -257,7 +258,7 @@
             // jndi.2E=The name is null
             throw new NullPointerException(Messages.getString("jndi.2E")); //$NON-NLS-1$
         }
-        
+
         if (attributes == null) {
             // jndi.13=Non-null attribute is required for modification
             throw new NullPointerException(Messages.getString("jndi.13")); //$NON-NLS-1$
@@ -283,7 +284,8 @@
         modifyAttributes(name, items);
     }
 
-    // Mapping from DirContext's attribute operation code to server's operation code. 
+    // Mapping from DirContext's attribute operation code to server's operation
+    // code.
     private static final int OperationJndi2Ldap[] = { -1, 0, 2, 1, };
 
     @Override
@@ -291,6 +293,12 @@
             throws NamingException {
         // First get the old schema.
         int size = name.size();
+
+        if (size < 1) {
+            // ldap.38=Can't modify schema root
+            throw new SchemaViolationException(Messages.getString("ldap.38")); //$NON-NLS-1$
+        }
+
         Hashtable<String, Object> subSchemaTree = doLookup(name
                 .getPrefix(size - 1), size - 1);
 
@@ -366,17 +374,41 @@
         ModifyOp op = new ModifyOp(ldapContext.subschemasubentry);
         Name modifySchemaName = name.getPrefix(size - 1).addAll(rdn);
         BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute(
-                jndi2ldap(modifySchemaName.toString()), schemaLine), ldapContext);
+                jndi2ldap(modifySchemaName.toString()), schemaLine),
+                ldapContext);
         op.addModification(OperationJndi2Ldap[DirContext.REMOVE_ATTRIBUTE],
                 new LdapAttribute(schemaEntry, ldapContext));
         BasicAttribute addSchemaEntry = new LdapAttribute(new BasicAttribute(
-                jndi2ldap(modifySchemaName.toString()), newSchemaLine), ldapContext);
+                jndi2ldap(modifySchemaName.toString()), newSchemaLine),
+                ldapContext);
         op.addModification(OperationJndi2Ldap[DirContext.ADD_ATTRIBUTE],
                 new LdapAttribute(addSchemaEntry, ldapContext));
 
         doBasicOperation(op);
-        subSchemaTree.remove(subSchemaType);
-        subSchemaTree.put(subSchemaType, newSchemaLine);
+
+        // Modify the hashtable to reflect the modification.
+        Object subSchema = subSchemaTree.get(subSchemaType);
+        if (subSchema instanceof String) {
+            subSchemaTree.remove(subSchemaType);
+            subSchemaTree.put(subSchemaType, newSchemaLine);
+        } else {
+            /*
+             * Here we can only change the content of subSchemaTable, instead of
+             * change the reference. Because in other ldapSchemaContext, there
+             * may be reference to this table. And they should also reflect the
+             * changes.
+             */
+            Hashtable<String, Object> subSchemaTable = (Hashtable<String, Object>)
subSchema;
+            subSchemaTable.clear();
+            Hashtable<String, Object> parsedTable = SchemaParser
+                    .parseValue(newSchemaLine);
+            Iterator<Entry<String, Object>> it = parsedTable.entrySet()
+                    .iterator();
+            while (it.hasNext()) {
+                Entry<String, Object> entry = it.next();
+                subSchemaTable.put(entry.getKey(), entry.getValue());
+            }
+        }
     }
 
     @Override
@@ -579,14 +611,26 @@
 
     @Override
     public void rename(Name nOld, Name nNew) throws NamingException {
+        if (nOld == null || nNew == null) {
+            throw new NullPointerException();
+        }
+
+        if (nOld.size() == 0 || nNew.size() == 0) {
+            // ldap.3A=Can't rename empty name
+            throw new InvalidNameException(Messages.getString("ldap.3A")); //$NON-NLS-1$
+        }
+
+        if (nOld.size() > 1 || nNew.size() > 1) {
+            // ldap.3B=Can't rename across contexts
+            throw new InvalidNameException(Messages.getString("ldap.3B")); //$NON-NLS-1$
+        }
         // ldap.39=Can't rename schema
         throw new SchemaViolationException(Messages.getString("ldap.39")); //$NON-NLS-1$
     }
 
     @Override
     public void rename(String sOld, String sNew) throws NamingException {
-        // ldap.39=Can't rename schema
-        throw new SchemaViolationException(Messages.getString("ldap.39")); //$NON-NLS-1$
+        rename(new CompositeName(sOld), new CompositeName(sNew));
     }
 
     @Override
@@ -720,7 +764,7 @@
     public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls
searchControls) throws NamingException {
         return search(new CompositeName(name), filter, searchControls);
     }
-    
+
     protected DirContext getClassDefinition(Attribute objectclassAttr)
             throws NamingException {
         Hashtable<String, Object> definitionTable = new Hashtable<String, Object>();

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java?rev=660155&r1=660154&r2=660155&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapSchemaContextTest.java
Mon May 26 03:23:09 2008
@@ -1105,6 +1105,36 @@
         }
     }
 
+    public void testModifyAttributes_WatchSubSchema() throws NamingException {
+        // Creates the attributes.
+        Attributes attrs = new BasicAttributes(false); // Ignore case
+        attrs.put("NAME", "ListObjectClass");
+        attrs.put("SUP", "top");
+        attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.77");
+        attrs.put("DESC", "for test");
+        attrs.put("STRUCTURAL", "fds");
+
+        Attribute must = new BasicAttribute("MUST", "cn");
+        must.add("objectclass");
+        attrs.put(must);
+
+        DirContext dir = schema.createSubcontext(new CompositeName(
+                "ClassDefinition/ListObjectClass"), attrs);
+
+        Attributes newAttrs = new BasicAttributes(false);
+        newAttrs.put("NAME", "Modified");
+        newAttrs.put("SUP", "top");
+        newAttrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.77");
+        newAttrs.put("DESC", "for test");
+        newAttrs.put("STRUCTURAL", "fds");
+
+        schema.modifyAttributes("ClassDefinition/ListObjectClass",
+                DirContext.REPLACE_ATTRIBUTE, newAttrs);
+
+        Attributes subSchemaAttrs = dir.getAttributes("");
+        assertEquals("Modified", subSchemaAttrs.get("NAME").get());
+    }
+
     public void testModifyAttributes_Exception() throws NamingException {
         Attributes attrs = new BasicAttributes(true); // Ignore case
         attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.88.11");
@@ -1157,6 +1187,21 @@
         } catch (NameNotFoundException e) {
             // Expected.
         }
+
+        try {
+            schema.modifyAttributes("", new ModificationItem[] {});
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // expected
+        }
+
+        try {
+            schema.modifyAttributes(new CompositeName(""),
+                    new ModificationItem[] {});
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // expected
+        }
     }
 
     public void testCreateAndDeleteSubContext() throws NamingException {
@@ -2075,6 +2120,165 @@
         assertEquals(2, count);
     }
 
+    public void testRename() throws NamingException {
+        Name name1 = new CompositeName("test1");
+        Name name2 = new CompositeName("/");
+        Name invalidName1 = new CompositeName("");
+        try {
+            schema.rename(name1, name2);
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(invalidName1, name2);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(name2, invalidName1);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("test1", "test2");
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("", "test2");
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("test1", "");
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("classdefinition/javaClass", "test");
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("classdefinition\\javaClass", "test");
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(new CompositeName("classdefinition/javaClass"),
+                    new CompositeName("test"));
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(new CompositeName("classdefinition\\javaClass"),
+                    new CompositeName("test"));
+            fail("Should throw SchemaViolationException");
+        } catch (SchemaViolationException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("classdefinition/javaClass", "");
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("", "classdefinition/javaClass");
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+    }
+
+    public void testRename_Exception() throws NamingException {
+        Name name = new CompositeName("test");
+        Name nullName = null;
+        String nullString = null;
+        try {
+            schema.rename(nullName, name);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(name, nullName);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(nullName, nullName);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(nullString, "test");
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("test", nullString);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(nullString, nullString);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("\\", nullString);
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename("/", nullString);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+
+        try {
+            schema.rename(null, "");
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+    }
+
     public void testClassDefinition() throws NamingException {
         MockLdapSchemaContext mockSchema = new MockLdapSchemaContext(context,
                 null, name, schemaTable,



Mime
View raw message