Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 13904 invoked from network); 25 Jan 2007 10:55:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Jan 2007 10:55:54 -0000 Received: (qmail 61804 invoked by uid 500); 25 Jan 2007 10:56:00 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 61754 invoked by uid 500); 25 Jan 2007 10:56:00 -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 61743 invoked by uid 99); 25 Jan 2007 10:56:00 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Jan 2007 02:56:00 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME 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; Thu, 25 Jan 2007 02:55:53 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 6B4E11A981A; Thu, 25 Jan 2007 02:55:33 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r499731 - /directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java Date: Thu, 25 Jan 2007 10:55:33 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070125105533.6B4E11A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Thu Jan 25 02:55:32 2007 New Revision: 499731 URL: http://svn.apache.org/viewvc?view=rev&rev=499731 Log: Fixed DIRSERVER-836 Modified: directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java Modified: directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?view=diff&rev=499731&r1=499730&r2=499731 ============================================================================== --- directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java (original) +++ directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java Thu Jan 25 02:55:32 2007 @@ -370,6 +370,73 @@ return new SearchResultFilteringEnumeration( e, new SearchControls(), invocation, binaryAttributeFilter ); } + /** + * Remove all unknown attributes from the searchControls, to avoid an exception. + * + * RFC 2251 states that : + * " Attributes MUST be named at most once in the list, and are returned " + * " at most once in an entry. " + * " If there are attribute descriptions in " + * " the list which are not recognized, they are ignored by the server." + * + * @param searchCtls The SearchControls we will filter + */ + private void filterAttributesToReturn( SearchControls searchCtls ) throws NamingException + { + String[] attributes = searchCtls.getReturningAttributes(); + + if ( ( attributes == null ) || ( attributes.length == 0 ) ) + { + return; + } + + Map filteredAttrs = new HashMap(); + + for ( int i = 0; i < attributes.length; i++ ) + { + String attribute = attributes[i]; + + // Skip special attributes + if ( ( "*".equals( attribute ) ) || ( "+".equals( attribute ) ) || ( "1.1".equals( attribute ) ) ) + { + if ( !filteredAttrs.containsKey( attribute ) ) + { + filteredAttrs.put( attribute, attribute ); + } + + continue; + } + + if ( globalRegistries.getAttributeTypeRegistry().hasAttributeType( attribute ) ) + { + String oid = globalRegistries.getOidRegistry().getOid( attribute ); + + if ( !filteredAttrs.containsKey( oid ) ) + { + filteredAttrs.put( oid, attribute ); + } + } + } + + // If we still have the same attribute number, then we can just get out the method + if ( filteredAttrs.size() == attributes.length ) + { + return; + } + + // Some attributes have been removed. let's modify the searchControl + String[] newAttributesList = new String[filteredAttrs.size()]; + + int pos = 0; + Iterator keys = filteredAttrs.keySet().iterator(); + + while ( keys.hasNext() ) + { + newAttributesList[pos++] = (String)filteredAttrs.get( keys.next() ); + } + + searchCtls.setReturningAttributes( newAttributesList ); + } /** * @@ -379,6 +446,12 @@ { // check to make sure the DN searched for is a subentry Invocation invocation = InvocationStack.getInstance().peek(); + + // We have to eliminate bad attributes from the request, accordingly + // to RFC 2251, chap. 4.5.1. Basically, all unknown attributes are removed + // from the list + filterAttributesToReturn( searchCtls ); + if ( !subschemaSubentryDn.toNormName().equals( base.toNormName() ) ) { NamingEnumeration e = nextInterceptor.search( base, env, filter, searchCtls );