Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 69865 invoked from network); 31 Mar 2008 13:15:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 31 Mar 2008 13:15:22 -0000 Received: (qmail 96217 invoked by uid 500); 31 Mar 2008 13:15:22 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 96174 invoked by uid 500); 31 Mar 2008 13:15:22 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 96163 invoked by uid 99); 31 Mar 2008 13:15:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Mar 2008 06:15:22 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Mar 2008 13:14:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6704B1A9838; Mon, 31 Mar 2008 06:14:58 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r642984 - in /directory/apacheds/branches/bigbang: core-entry/src/main/java/org/apache/directory/server/core/entry/ core/src/main/java/org/apache/directory/server/core/schema/ server-unit/src/test/java/org/apache/directory/server/ Date: Mon, 31 Mar 2008 13:14:55 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080331131458.6704B1A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: akarasulu Date: Mon Mar 31 06:14:52 2008 New Revision: 642984 URL: http://svn.apache.org/viewvc?rev=642984&view=rev Log: DIRSERVER-646 fix: moved changes in schema interceptor to new location where we transform JNDI parameters into Server expected parameters based on ServerAttribute. This stuff will need to be moved again. Added additional test to Stefan Zoerners test case to test for condition where multiple mods exist. Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java?rev=642984&r1=642983&r2=642984&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java (original) +++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java Mon Mar 31 06:14:52 2008 @@ -31,6 +31,7 @@ import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttribute; import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; import javax.naming.directory.InvalidAttributeIdentifierException; import javax.naming.directory.ModificationItem; import javax.naming.directory.SearchResult; @@ -466,8 +467,8 @@ } - public static List toServerModification( ModificationItem[] modifications, AttributeTypeRegistry atRegistry ) - throws NamingException + public static List toServerModification( ModificationItem[] modifications, + AttributeTypeRegistry atRegistry ) throws NamingException { if ( modifications != null ) { @@ -478,6 +479,27 @@ String attributeId = modification.getAttribute().getID(); String id = stripOptions( attributeId ); Set options = getOptions( attributeId ); + + // ------------------------------------------------------------------- + // DIRSERVER-646 Fix: Replacing an unknown attribute with no values + // (deletion) causes an error + // ------------------------------------------------------------------- + + // TODO - after removing JNDI we need to make the server handle + // this in the codec + + if ( ! atRegistry.hasAttributeType( id ) + && modification.getAttribute().size() == 0 + && modification.getModificationOp() == DirContext.REPLACE_ATTRIBUTE ) + { + continue; + } + + // ------------------------------------------------------------------- + // END DIRSERVER-646 Fix + // ------------------------------------------------------------------- + + // TODO : handle options AttributeType attributeType = atRegistry.lookup( id ); modificationsList.add( toModification( (ModificationItemImpl)modification, attributeType ) ); Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=642984&r1=642983&r2=642984&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java (original) +++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java Mon Mar 31 06:14:52 2008 @@ -1236,19 +1236,6 @@ ObjectClassRegistry ocRegistry = this.registries.getObjectClassRegistry(); - // ------------------------------------------------------------------- - // DIRSERVER-646 Fix: Replacing an unknown attribute with no values - // (deletion) causes an error - // ------------------------------------------------------------------- - - if ( ( mods.size() == 1 ) && - ( mods.get( 0 ).getAttribute().size() == 0 ) && - ( mods.get( 0 ).getOperation() == ModificationOperation.REPLACE_ATTRIBUTE ) && - ! atRegistry.hasAttributeType( mods.get( 0 ).getAttribute().getId() ) ) - { - return; - } - // Now, apply the modifications on the cloned entry before applying it on the // real object. for ( Modification mod:mods ) Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java?rev=642984&r1=642983&r2=642984&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java (original) +++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java Mon Mar 31 06:14:52 2008 @@ -20,22 +20,18 @@ package org.apache.directory.server; -import java.util.Hashtable; - -import javax.naming.Context; 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.InitialDirContext; +import javax.naming.directory.ModificationItem; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; import org.apache.directory.server.unit.AbstractServerTest; -import org.apache.directory.shared.ldap.message.AttributeImpl; -import org.apache.directory.shared.ldap.message.AttributesImpl; -import org.apache.directory.shared.ldap.message.ModificationItemImpl; /** @@ -46,69 +42,74 @@ */ public class ModifyReplaceITest extends AbstractServerTest { - DirContext ctx = null; - - - protected Attributes getPersonAttributes( String sn, String cn ) + protected Attributes getPersonAttributes( String sn, String cn ) { - Attributes attrs = new AttributesImpl(); - Attribute ocls = new AttributeImpl( "objectClass" ); - ocls.add( "top" ); - ocls.add( "person" ); - attrs.put( ocls ); - attrs.put( "cn", cn ); - attrs.put( "sn", sn ); + 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; } - - protected void setUp() throws Exception + + /** + * Create a person entry and try to remove a not present attribute + */ + public void testReplaceNotPresentAttribute() throws NamingException { - super.setUp(); - - Hashtable env = new Hashtable(); - env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" ); - env.put( Context.PROVIDER_URL, "ldap://localhost:" + super.port + "/ou=system" ); - env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" ); - env.put( Context.SECURITY_CREDENTIALS, "secret" ); - env.put( Context.SECURITY_AUTHENTICATION, "simple" ); + Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" ); + String rdn = "cn=Kate Bush"; + sysRoot.createSubcontext( rdn, attrs ); - ctx = new InitialDirContext( env ); - } + Attribute attr = new BasicAttribute( "description" ); + ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr ); + sysRoot.modifyAttributes( rdn, new ModificationItem[] { item } ); - protected void tearDown() throws Exception - { - ctx.close(); - super.tearDown(); - } + 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 ); + } + /** - * Create a person entry and try to remove a not present attribute - * - * @throws NamingException + * Create a person entry and try to remove a non existing attribute */ - public void testReplaceNotPresentAttribute() throws NamingException + public void testReplaceNonExistingAttribute() throws NamingException { Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" ); String rdn = "cn=Kate Bush"; - ctx.createSubcontext( rdn, attrs ); + sysRoot.createSubcontext( rdn, attrs ); - Attribute attr = new AttributeImpl( "description" ); - ModificationItemImpl item = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr ); + Attribute attr = new BasicAttribute( "numberOfOctaves" ); + ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr ); - ctx.modifyAttributes( rdn, new ModificationItemImpl[] - { item } ); + sysRoot.modifyAttributes(rdn, new ModificationItem[] { item }); SearchControls sctls = new SearchControls(); sctls.setSearchScope( SearchControls.SUBTREE_SCOPE ); String filter = "(sn=Bush)"; String base = ""; - NamingEnumeration enm = ctx.search( base, filter, sctls ); - while ( enm.hasMore() ) + NamingEnumeration enm = sysRoot.search( base, filter, sctls ); + while ( enm.hasMore() ) { SearchResult sr = ( SearchResult ) enm.next(); attrs = sr.getAttributes(); @@ -117,34 +118,33 @@ assertTrue( cn.contains( "Kate Bush" ) ); } - ctx.destroySubcontext( rdn ); + sysRoot.destroySubcontext( rdn ); } /** * Create a person entry and try to remove a non existing attribute - * - * @throws NamingException */ - public void testReplaceNonExistingAttribute() throws NamingException + public void testReplaceNonExistingAttributeManyMods() throws NamingException { Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" ); String rdn = "cn=Kate Bush"; - ctx.createSubcontext( rdn, attrs ); + sysRoot.createSubcontext( rdn, attrs ); - Attribute attr = new AttributeImpl( "l" ); - ModificationItemImpl item = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr ); + Attribute attr = new BasicAttribute( "numberOfOctaves" ); + ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr ); + Attribute attr2 = new BasicAttribute( "description", "blah blah blah" ); + ModificationItem item2 = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr2 ); - ctx.modifyAttributes( rdn, new ModificationItemImpl[] - { item } ); + sysRoot.modifyAttributes(rdn, new ModificationItem[] { item, item2 }); SearchControls sctls = new SearchControls(); sctls.setSearchScope( SearchControls.SUBTREE_SCOPE ); String filter = "(sn=Bush)"; String base = ""; - NamingEnumeration enm = ctx.search( base, filter, sctls ); - while ( enm.hasMore() ) + NamingEnumeration enm = sysRoot.search( base, filter, sctls ); + while ( enm.hasMore() ) { SearchResult sr = ( SearchResult ) enm.next(); attrs = sr.getAttributes(); @@ -153,6 +153,6 @@ assertTrue( cn.contains( "Kate Bush" ) ); } - ctx.destroySubcontext( rdn ); + sysRoot.destroySubcontext( rdn ); } }