Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 47901 invoked from network); 14 Jul 2010 22:56:02 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 14 Jul 2010 22:56:02 -0000 Received: (qmail 88986 invoked by uid 500); 14 Jul 2010 22:56:02 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 88930 invoked by uid 500); 14 Jul 2010 22:56:01 -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 88923 invoked by uid 99); 14 Jul 2010 22:56:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Jul 2010 22:56:01 +0000 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.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Jul 2010 22:55:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C40D023889F1; Wed, 14 Jul 2010 22:55:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r964243 - in /directory: apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/ shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ Date: Wed, 14 Jul 2010 22:55:03 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100714225503.C40D023889F1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Wed Jul 14 22:55:03 2010 New Revision: 964243 URL: http://svn.apache.org/viewvc?rev=964243&view=rev Log: o Created an UndefinedNode to be used when parsing a Filter and having a unknown AttributeType o Modified the FilterParser to fix DIRSERVER-971/1525 o Removed the @Ignored tests in SearchIT class Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/UndefinedNode.java Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AssertionType.java directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java?rev=964243&r1=964242&r2=964243&view=diff ============================================================================== --- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java (original) +++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java Wed Jul 14 22:55:03 2010 @@ -71,7 +71,6 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.name.DN; import org.apache.directory.shared.ldap.schema.AttributeType; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -412,7 +411,6 @@ public class SearchIT extends AbstractLd * result in exceptions. */ @Test - @Ignore( "Fix DIRSERVER-1525/955" ) public void testBogusAttributeInSearchFilter() throws Exception { boolean oldSetAllowAnnonymousAccess = service.isAllowAnonymousAccess(); @@ -1886,7 +1884,6 @@ public class SearchIT extends AbstractLd @Test - @Ignore( "Fix DIRSERVER-1525/955" ) public void testSearchFilterWithBadAttributeType() throws Exception { SearchControls controls = new SearchControls(); @@ -1911,7 +1908,6 @@ public class SearchIT extends AbstractLd @Test - @Ignore( "Fix DIRSERVER-1525/955" ) public void testSearchFilterBadAttributeType() throws Exception { SearchControls controls = new SearchControls(); Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AssertionType.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AssertionType.java?rev=964243&r1=964242&r2=964243&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AssertionType.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AssertionType.java Wed Jul 14 22:55:03 2010 @@ -60,5 +60,8 @@ public enum AssertionType AND, /** NOT operator constant */ - NOT + NOT, + + /** Undefined operation */ + UNDEFINED; } Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java?rev=964243&r1=964242&r2=964243&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java Wed Jul 14 22:55:03 2010 @@ -26,6 +26,7 @@ import org.apache.directory.shared.i18n. import org.apache.directory.shared.ldap.entry.BinaryValue; import org.apache.directory.shared.ldap.entry.Value; import org.apache.directory.shared.ldap.exception.LdapException; +import org.apache.directory.shared.ldap.schema.AttributeType; import org.apache.directory.shared.ldap.schema.SchemaManager; import org.apache.directory.shared.ldap.util.AttributeUtils; import org.apache.directory.shared.ldap.util.Position; @@ -60,7 +61,16 @@ public class FilterParser if ( schemaManager != null ) { - node = new ExtensibleNode( schemaManager.lookupAttributeTypeRegistry( attribute ) ); + AttributeType attributeType = schemaManager.getAttributeType( attribute ); + + if ( attributeType != null ) + { + node = new ExtensibleNode( attributeType ); + } + else + { + return UndefinedNode.UNDEFINED_NODE; + } } else { @@ -297,14 +307,23 @@ public class FilterParser if ( schemaManager != null ) { - node = new SubstringNode( schemaManager.lookupAttributeTypeRegistry( attribute ) ); + AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute ); + + if ( attributeType != null ) + { + node = new SubstringNode( schemaManager.lookupAttributeTypeRegistry( attribute ) ); + } + else + { + return null; + } } else { node = new SubstringNode( attribute ); } - if ( initial != null && !initial.isNull() ) + if ( ( initial != null ) && !initial.isNull() ) { // We have a substring starting with a value : val*... // Set the initial value. It must be a String @@ -397,7 +416,16 @@ public class FilterParser // This is a present node if ( schemaManager != null ) { - return new PresenceNode( schemaManager.lookupAttributeTypeRegistry( attribute ) ); + AttributeType attributeType = schemaManager.getAttributeType( attribute ); + + if ( attributeType != null ) + { + return new PresenceNode( attributeType ); + } + else + { + return null; + } } else { @@ -417,7 +445,17 @@ public class FilterParser // An empty equality Node if ( schemaManager != null ) { - return new EqualityNode( schemaManager.lookupAttributeTypeRegistry( attribute ), new BinaryValue() ); + AttributeType attributeType = schemaManager.getAttributeType( attribute ); + + if ( attributeType != null ) + { + return new EqualityNode( attributeType, new BinaryValue() ); + } + + else + { + return null; + } } else { @@ -435,7 +473,16 @@ public class FilterParser // This is an equality node if ( schemaManager != null ) { - return new EqualityNode( schemaManager.lookupAttributeTypeRegistry( attribute ), value ); + AttributeType attributeType = schemaManager.getAttributeType( attribute ); + + if ( attributeType != null ) + { + return new EqualityNode( attributeType, value ); + } + else + { + return null; + } } else { @@ -507,16 +554,22 @@ public class FilterParser // Parse the value and create the node if ( schemaManager == null ) { - node = new ApproximateNode( attribute, parseAssertionValue( filter, pos ) ); + return new ApproximateNode( attribute, parseAssertionValue( filter, pos ) ); } else { - node = new ApproximateNode( schemaManager.lookupAttributeTypeRegistry( attribute ), - parseAssertionValue( filter, pos ) ); + AttributeType attributeType = schemaManager.getAttributeType( attribute ); + + if ( attributeType != null ) + { + return new ApproximateNode( attributeType, parseAssertionValue( filter, pos ) ); + } + else + { + return UndefinedNode.UNDEFINED_NODE; + } } - return node; - case '>': // Greater or equal node pos.start++; @@ -532,14 +585,21 @@ public class FilterParser // Parse the value and create the node if ( schemaManager == null ) { - node = new GreaterEqNode( attribute, parseAssertionValue( filter, pos ) ); + return new GreaterEqNode( attribute, parseAssertionValue( filter, pos ) ); } else { - node = new GreaterEqNode( schemaManager.lookupAttributeTypeRegistry( attribute ), - parseAssertionValue( filter, pos ) ); + AttributeType attributeType = schemaManager.getAttributeType( attribute ); + + if ( attributeType != null ) + { + return new GreaterEqNode( attributeType, parseAssertionValue( filter, pos ) ); + } + else + { + return UndefinedNode.UNDEFINED_NODE; + } } - return node; case '<': // Less or equal node @@ -556,16 +616,22 @@ public class FilterParser // Parse the value and create the node if ( schemaManager == null ) { - node = new LessEqNode( attribute, parseAssertionValue( filter, pos ) ); + return new LessEqNode( attribute, parseAssertionValue( filter, pos ) ); } else { - node = new LessEqNode( schemaManager.lookupAttributeTypeRegistry( attribute ), parseAssertionValue( filter, pos ) ); + AttributeType attributeType = schemaManager.getAttributeType( attribute ); + if ( attributeType != null ) + { + return new LessEqNode( attributeType, parseAssertionValue( filter, pos ) ); + } + else + { + return UndefinedNode.UNDEFINED_NODE; + } } - return node; - case ':': // An extensible node pos.start++; @@ -592,22 +658,46 @@ public class FilterParser private static ExprNode parseBranchNode( SchemaManager schemaManager, ExprNode node, String filter, Position pos ) throws ParseException, LdapException { - BranchNode bNode = ( BranchNode ) node; + BranchNode branchNode = ( BranchNode ) node; + int nbChildren = 0; // We must have at least one filter ExprNode child = parseFilterInternal( schemaManager, filter, pos ); - - // Add the child to the node children - bNode.addNode( child ); + + if ( child != UndefinedNode.UNDEFINED_NODE ) + { + // Add the child to the node children + branchNode.addNode( child ); + nbChildren++; + } + else if ( node instanceof AndNode ) + { + return UndefinedNode.UNDEFINED_NODE; + } // Now, iterate recusively though all the remaining filters, if any - while ( ( child = parseFilterInternal( schemaManager, filter, pos ) ) != null ) + while ( ( child = parseFilterInternal( schemaManager, filter, pos ) ) != UndefinedNode.UNDEFINED_NODE ) { - // Add the child to the node children - bNode.addNode( child ); + // Add the child to the node children if not null + if ( child != null ) + { + branchNode.addNode( child ); + nbChildren++; + } + else if ( node instanceof AndNode ) + { + return UndefinedNode.UNDEFINED_NODE; + } } - return node; + if ( nbChildren > 0 ) + { + return node; + } + else + { + return UndefinedNode.UNDEFINED_NODE; + } } @@ -643,21 +733,21 @@ public class FilterParser // This is a AND node pos.start++; node = new AndNode(); - parseBranchNode( schemaManager, node, filter, pos ); + node = parseBranchNode( schemaManager, node, filter, pos ); break; case '|': // This is an OR node pos.start++; node = new OrNode(); - parseBranchNode( schemaManager, node, filter, pos ); + node = parseBranchNode( schemaManager, node, filter, pos ); break; case '!': // This is a NOT node pos.start++; node = new NotNode(); - parseBranchNode( schemaManager, node, filter, pos ); + node = parseBranchNode( schemaManager, node, filter, pos ); break; default: @@ -688,7 +778,7 @@ public class FilterParser } else { - return null; + return UndefinedNode.UNDEFINED_NODE; } } @@ -697,9 +787,9 @@ public class FilterParser // parse the filter component ExprNode node = parseFilterComp( schemaManager, filter, pos ); - if ( node == null ) + if ( node == UndefinedNode.UNDEFINED_NODE ) { - throw new ParseException( I18n.err( I18n.ERR_04156 ), pos.start ); + return UndefinedNode.UNDEFINED_NODE; } // Check that we have a right ')' Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/UndefinedNode.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/UndefinedNode.java?rev=964243&view=auto ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/UndefinedNode.java (added) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/UndefinedNode.java Wed Jul 14 22:55:03 2010 @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.filter; + +/** + * An empty class used for Undefined Nodes. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class UndefinedNode extends AbstractExprNode +{ + /** A static instance of this node */ + public static final ExprNode UNDEFINED_NODE = new UndefinedNode(); + + + /** + * Creates a new instance of UndefinedNode. + */ + private UndefinedNode() + { + super( AssertionType.UNDEFINED ); + } + + + @Override + public boolean isLeaf() + { + return false; + } + + + public Object accept( FilterVisitor visitor ) + { + return null; + } + + + /** + * @see Object#toString() + */ + public String toString() + { + return "Undefined"; + } +}