You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/07/15 00:55:03 UTC
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/
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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @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";
+ }
+}