Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 7210 invoked from network); 7 Oct 2008 11:28:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Oct 2008 11:28:15 -0000 Received: (qmail 84246 invoked by uid 500); 7 Oct 2008 11:28:14 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 84195 invoked by uid 500); 7 Oct 2008 11:28:13 -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 84186 invoked by uid 99); 7 Oct 2008 11:28:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Oct 2008 04:28:13 -0700 X-ASF-Spam-Status: No, hits=-1999.9 required=10.0 tests=ALL_TRUSTED,DNS_FROM_SECURITYSAGE 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; Tue, 07 Oct 2008 11:27:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CB32923889C0; Tue, 7 Oct 2008 04:27:12 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r702434 [5/5] - in /directory: apacheds/trunk/ apacheds/trunk/all/ apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/ apached... Date: Tue, 07 Oct 2008 11:27:01 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081007112712.CB32923889C0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ReferralAwareRequestHandler.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ReferralAwareRequestHandler.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ReferralAwareRequestHandler.java (original) +++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ReferralAwareRequestHandler.java Tue Oct 7 04:26:55 2008 @@ -24,6 +24,7 @@ import javax.naming.NameNotFoundException; import javax.naming.NamingException; +import org.apache.directory.server.core.ReferralManager; import org.apache.directory.server.core.entry.ClonedServerEntry; import org.apache.directory.server.core.entry.ServerAttribute; import org.apache.directory.server.ldap.LdapSession; @@ -32,13 +33,7 @@ import org.apache.directory.shared.ldap.entry.EntryAttribute; import org.apache.directory.shared.ldap.entry.Value; import org.apache.directory.shared.ldap.exception.LdapException; -import org.apache.directory.shared.ldap.message.AddRequest; -import org.apache.directory.shared.ldap.message.BindRequest; -import org.apache.directory.shared.ldap.message.CompareRequest; -import org.apache.directory.shared.ldap.message.DeleteRequest; import org.apache.directory.shared.ldap.message.LdapResult; -import org.apache.directory.shared.ldap.message.ModifyDnRequest; -import org.apache.directory.shared.ldap.message.ModifyRequest; import org.apache.directory.shared.ldap.message.Referral; import org.apache.directory.shared.ldap.message.ReferralImpl; import org.apache.directory.shared.ldap.message.ResultCodeEnum; @@ -79,76 +74,36 @@ { LOG.debug( "Handling single reply request: {}", req ); - LdapDN reqTargetDn = null; - - switch ( req.getType() ) - { - case ADD_REQUEST: - reqTargetDn = ( ( AddRequest ) req ).getEntryDn(); - break; - case BIND_REQUEST: - // not used for bind but may be in future - reqTargetDn = ( ( BindRequest ) req ).getName(); - break; - case COMPARE_REQUEST: - reqTargetDn = ( ( CompareRequest ) req ).getName(); - break; - case DEL_REQUEST: - reqTargetDn = ( ( DeleteRequest ) req ).getName(); - break; - case EXTENDED_REQ: - throw new IllegalStateException( - "Although ExtendedRequests are SingleReplyRequests they're not handled" + - " using this base class. They have no target entry unlike the rest of" + - " the SingleReplyRequests" ); - case MOD_DN_REQUEST: - /* - * Special handling needed because of the new superior entry - * as specified in RFC 3296 section 5.6.2 here: - * - * http://www.faqs.org/rfcs/rfc3296.html - */ - if ( req.getControls().containsKey( ManageDsaITControl.CONTROL_OID ) ) - { - LOG.debug( "ManageDsaITControl detected." ); - handleIgnoringReferrals( session, ( ( ModifyDnRequest ) req ).getName(), null, req ); - } - else - { - LOG.debug( "ManageDsaITControl NOT detected." ); - - if ( ( ( ModifyDnRequest ) req ).getNewSuperior() == null ) - { - handleWithReferrals( session, ( ( ModifyDnRequest ) req ).getName(), req ); - } - else - { - // NOTE: call is to overload just for the ModifyDnRequest - handleModifyDnWithReferrals( session, req ); - } - } - return; - case MODIFY_REQUEST: - reqTargetDn = ( ( ModifyRequest ) req ).getName(); - break; - case SEARCH_REQUEST: - reqTargetDn = ( ( SearchRequest ) req ).getBase(); - break; - default: - throw new IllegalStateException( - "Unidentified single reply request/response type: " + req ); - } - + // First, if we have the ManageDSAIt control, go directly + // to the handling without pre-processing the request if ( req.getControls().containsKey( ManageDsaITControl.CONTROL_OID ) ) { LOG.debug( "ManageDsaITControl detected." ); - handleIgnoringReferrals( session, reqTargetDn, null, req ); + handleIgnoringReferrals( session, req ); } else { LOG.debug( "ManageDsaITControl NOT detected." ); - handleWithReferrals( session, reqTargetDn, req ); + + switch ( req.getType() ) + { + case SEARCH_REQUEST: + handleWithReferrals( session, ( ( SearchRequest ) req ).getBase(), req ); + break; + + case EXTENDED_REQ: + throw new IllegalStateException( + "Although ExtendedRequests are SingleReplyRequests they're not handled" + + " using this base class. They have no target entry unlike the rest of" + + " the SingleReplyRequests" ); + + default: + throw new IllegalStateException( + "Unidentified single reply request/response type: " + req ); + } + } + } @@ -220,182 +175,51 @@ } - private void handleModifyDnWithReferrals( LdapSession session, T modifyDnRequest ) + /** + * Handles processing with referrals without ManageDsaIT control. + */ + private void handleWithReferrals( LdapSession session, LdapDN reqTargetDn, T req ) throws NamingException { - ModifyDnRequest req = ( ModifyDnRequest ) modifyDnRequest; LdapResult result = req.getResultResponse().getLdapResult(); ClonedServerEntry entry = null; - ClonedServerEntry superiorEntry = null; - - // ------------------------------------------------------------------- - // Lookup Entry - // ------------------------------------------------------------------- - - // try to lookup the entry but ignore exceptions when it does not - // exist since entry may not exist but may have an ancestor that is a - // referral - would rather attempt a lookup that fails then do check - // for existence than have to do another lookup to get entry info - - try - { - entry = session.getCoreSession().lookup( req.getName() ); - LOG.debug( "Entry for {} was found: ", req.getName(), entry ); - } - catch ( NameNotFoundException e ) - { - /* ignore */ - LOG.debug( "Entry for {} not found.", req.getName() ); - } - catch ( Exception e ) - { - /* serious and needs handling */ - handleException( session, modifyDnRequest, e ); - return; - } + boolean isReferral = false; + boolean isparentReferral = false; + ReferralManager referralManager= session.getCoreSession().getDirectoryService().getReferralManager(); - try - { - superiorEntry = session.getCoreSession().lookup( req.getNewSuperior() ); - LOG.debug( "New superior entry for {} was found: ", req.getName(), entry ); - } - catch ( NameNotFoundException e ) - { - /* ignore */ - LOG.debug( "New superior entry for {} not found.", req.getName() ); - } - catch ( Exception e ) - { - /* serious and needs handling */ - handleException( session, modifyDnRequest, e ); - return; - } + reqTargetDn.normalize( session.getCoreSession().getDirectoryService().getRegistries().getAttributeTypeRegistry().getNormalizerMapping() ); + + // Check if the entry itself is a referral + referralManager.lockRead(); - // ------------------------------------------------------------------- - // Handle Existing Entry - // ------------------------------------------------------------------- + isReferral = referralManager.isReferral( reqTargetDn ); - if ( entry != null ) + if ( !isReferral ) { - try - { - if ( isEntryReferral( entry ) ) - { - LOG.debug( "Entry is a referral: {}", entry ); - handleReferralEntry( session, req.getName(), modifyDnRequest, entry ); - return; - } - else - { - if ( superiorEntry != null && isEntryReferral( superiorEntry ) ) - { - result.setErrorMessage( "Superior entry is a referral." ); - result.setMatchedDn( req.getNewSuperior() ); - result.setResultCode( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS ); - session.getIoSession().write( req.getResultResponse() ); - return; - } - else if ( superiorEntry == null ) - { - ClonedServerEntry referralAncestor = getFarthestReferralAncestor( session, - req.getNewSuperior() ); - - if ( referralAncestor != null ) - { - result.setErrorMessage( "Superior entry does has referral ancestor." ); - result.setResultCode( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS ); - session.getIoSession().write( req.getResultResponse() ); - return; - } - else - { - result.setErrorMessage( "Superior entry does not exist." ); - result.setResultCode( ResultCodeEnum.NO_SUCH_OBJECT ); - session.getIoSession().write( req.getResultResponse() ); - return; - } - } - - LOG.debug( "Entry is NOT a referral: {}", entry ); - handleIgnoringReferrals( session, req.getName(), entry, modifyDnRequest ); - return; - } - } - catch ( Exception e ) - { - handleException( session, modifyDnRequest, e ); - } + // Check if the entry has a parent which is a referral + isparentReferral = referralManager.hasParentReferral( reqTargetDn ); } - - // ------------------------------------------------------------------- - // Handle Non-existing Entry - // ------------------------------------------------------------------- - // if the entry is null we still have to check for a referral ancestor - // also the referrals need to be adjusted based on the ancestor's ref - // values to yield the correct path to the entry in the target DSAs + referralManager.unlock(); - if ( entry == null ) + if ( !isReferral && !isparentReferral ) { - ClonedServerEntry referralAncestor = null; - - try - { - referralAncestor = getFarthestReferralAncestor( session, req.getName() ); - } - catch ( Exception e ) - { - handleException( session, modifyDnRequest, e ); - return; - } - - if ( referralAncestor == null && ! ( req instanceof AddRequest ) ) - { - result.setErrorMessage( "Entry not found." ); - result.setResultCode( ResultCodeEnum.NO_SUCH_OBJECT ); - session.getIoSession().write( req.getResultResponse() ); - return; - } - else if ( ( req instanceof AddRequest ) && referralAncestor == null ) - { - handleIgnoringReferrals( session, req.getName(), entry, modifyDnRequest ); - return; - } - - // if we get here then we have a valid referral ancestor - try - { - Referral referral = getReferralOnAncestor( session, req.getName(), modifyDnRequest, referralAncestor ); - result.setResultCode( ResultCodeEnum.REFERRAL ); - result.setReferral( referral ); - session.getIoSession().write( req.getResultResponse() ); - } - catch ( Exception e ) - { - handleException( session, modifyDnRequest, e ); - } + // This is not a referral and it does not have a parent which + // is a referral : standard case, just deal with the request + LOG.debug( "Entry {} is NOT a referral.", reqTargetDn ); + handleIgnoringReferrals( session, req ); + return; } - } - - - /** - * Handles processing with referrals without ManageDsaIT control. - */ - private void handleWithReferrals( LdapSession session, LdapDN reqTargetDn, T req ) - { - LdapResult result = req.getResultResponse().getLdapResult(); - ClonedServerEntry entry = null; - - // ------------------------------------------------------------------- - // Lookup Entry - // ------------------------------------------------------------------- - - // try to lookup the entry but ignore exceptions when it does not - // exist since entry may not exist but may have an ancestor that is a - // referral - would rather attempt a lookup that fails then do check - // for existence than have to do another lookup to get entry info - - if ( ! ( req instanceof AddRequest ) ) + else { + // ------------------------------------------------------------------- + // Lookup Entry + // ------------------------------------------------------------------- + + // try to lookup the entry but ignore exceptions when it does not + // exist since entry may not exist but may have an ancestor that is a + // referral - would rather attempt a lookup that fails then do check + // for existence than have to do another lookup to get entry info + try { entry = session.getCoreSession().lookup( reqTargetDn ); @@ -412,99 +236,94 @@ handleException( session, req, e ); return; } - } - - // ------------------------------------------------------------------- - // Handle Existing Entry - // ------------------------------------------------------------------- - - if ( entry != null ) - { - try + + // ------------------------------------------------------------------- + // Handle Existing Entry + // ------------------------------------------------------------------- + + if ( entry != null ) { - if ( isEntryReferral( entry ) ) + try { - LOG.debug( "Entry is a referral: {}", entry ); - - if ( req instanceof SearchRequest ) + if ( isEntryReferral( entry ) ) { - handleReferralEntryForSearch( session, ( SearchRequest ) req, entry ); + LOG.debug( "Entry is a referral: {}", entry ); + + if ( req instanceof SearchRequest ) + { + handleReferralEntryForSearch( session, ( SearchRequest ) req, entry ); + } + else + { + handleReferralEntry( session, reqTargetDn, req, entry ); + } + return; } else { - handleReferralEntry( session, reqTargetDn, req, entry ); + LOG.debug( "Entry is NOT a referral: {}", entry ); + handleIgnoringReferrals( session, req ); + return; } - return; } - else + catch ( Exception e ) { - LOG.debug( "Entry is NOT a referral: {}", entry ); - handleIgnoringReferrals( session, reqTargetDn, entry, req ); - return; + handleException( session, req, e ); } } - catch ( Exception e ) - { - handleException( session, req, e ); - } - } - - // ------------------------------------------------------------------- - // Handle Non-existing Entry - // ------------------------------------------------------------------- - - // if the entry is null we still have to check for a referral ancestor - // also the referrals need to be adjusted based on the ancestor's ref - // values to yield the correct path to the entry in the target DSAs - - if ( entry == null ) - { - ClonedServerEntry referralAncestor = null; - - try - { - referralAncestor = getFarthestReferralAncestor( session, reqTargetDn ); - } - catch ( Exception e ) - { - handleException( session, req, e ); - return; - } - - if ( referralAncestor == null && ! ( req instanceof AddRequest ) ) - { - result.setErrorMessage( "Entry not found." ); - result.setResultCode( ResultCodeEnum.NO_SUCH_OBJECT ); - session.getIoSession().write( req.getResultResponse() ); - return; - } - else if ( ( req instanceof AddRequest ) && referralAncestor == null ) - { - handleIgnoringReferrals( session, reqTargetDn, entry, req ); - return; - } - - // if we get here then we have a valid referral ancestor - try + + // ------------------------------------------------------------------- + // Handle Non-existing Entry + // ------------------------------------------------------------------- + + // if the entry is null we still have to check for a referral ancestor + // also the referrals need to be adjusted based on the ancestor's ref + // values to yield the correct path to the entry in the target DSAs + + if ( entry == null ) { - Referral referral = null; - - if ( req instanceof SearchRequest ) + ClonedServerEntry referralAncestor = null; + + try { - referral = getReferralOnAncestorForSearch( session, ( SearchRequest ) req, referralAncestor ); + referralAncestor = getFarthestReferralAncestor( session, reqTargetDn ); } - else + catch ( Exception e ) { - referral = getReferralOnAncestor( session, reqTargetDn, req, referralAncestor ); + handleException( session, req, e ); + return; + } + + if ( referralAncestor == null ) + { + result.setErrorMessage( "Entry not found." ); + result.setResultCode( ResultCodeEnum.NO_SUCH_OBJECT ); + session.getIoSession().write( req.getResultResponse() ); + return; + } + + // if we get here then we have a valid referral ancestor + try + { + Referral referral = null; + + if ( req instanceof SearchRequest ) + { + referral = getReferralOnAncestorForSearch( session, ( SearchRequest ) req, referralAncestor ); + } + else + { + referral = getReferralOnAncestor( session, reqTargetDn, req, referralAncestor ); + } + + result.setResultCode( ResultCodeEnum.REFERRAL ); + result.setReferral( referral ); + session.getIoSession().write( req.getResultResponse() ); + } + catch ( Exception e ) + { + handleException( session, req, e ); } - - result.setResultCode( ResultCodeEnum.REFERRAL ); - result.setReferral( referral ); - session.getIoSession().write( req.getResultResponse() ); - } - catch ( Exception e ) - { - handleException( session, req, e ); } } } @@ -777,7 +596,7 @@ /** * Handles processing with referrals without ManageDsaIT control. */ - public void handleException( LdapSession session, T req, Exception e ) + public void handleException( LdapSession session, ResultResponseRequest req, Exception e ) { LdapResult result = req.getResultResponse().getLdapResult(); @@ -848,6 +667,5 @@ * exist. * @param req the request to be handled */ - public abstract void handleIgnoringReferrals( LdapSession session, LdapDN reqTargetDn, - ClonedServerEntry entry, T req ); + public abstract void handleIgnoringReferrals( LdapSession session, T req ); } Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java (original) +++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java Tue Oct 7 04:26:55 2008 @@ -564,8 +564,7 @@ * @param session the associated session * @param req the received SearchRequest */ - public void handleIgnoringReferrals( LdapSession session, LdapDN reqTargetDn, - ClonedServerEntry entry, SearchRequest req ) + public void handleIgnoringReferrals( LdapSession session, SearchRequest req ) { if ( IS_DEBUG ) { Added: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchCookie.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchCookie.java?rev=702434&view=auto ============================================================================== --- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchCookie.java (added) +++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchCookie.java Tue Oct 7 04:26:55 2008 @@ -0,0 +1,126 @@ +/* + * 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.server.ldap.handlers.controls; + +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; + +/** + * + * A container for the Page search cookie. We store multiple informations : + * - + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class PagedSearchCookie +{ + /** The total number of entries already returned */ + private int cumulativeSize; + + /** The original MessageId */ + private int messageId; + /** + * + * Creates a new instance of PagedSearchCookie. + * + */ + public PagedSearchCookie() + { + cumulativeSize = 0; + messageId = -1; + } + + + /** + * + * Creates a new instance of PagedSearchCookie, + * deserializing the cookie. + * + * @throws BufferUnderflowException if the buffer is not large enough to + * contain correct values + * + */ + public PagedSearchCookie( byte[] cookie ) throws BufferUnderflowException + { + ByteBuffer bb = ByteBuffer.allocate( cookie.length ); + bb.put( cookie ); + + cumulativeSize = bb.getInt(); + messageId = bb.getInt(); + } + + + /** + * @return The current number of entries returned since the first request + */ + public int getCumulativeSize() + { + return cumulativeSize; + } + + + /** + * Increment the cumulativeSize field with the number of + * entries returned with the last request + * + * @param size + */ + public void incrementCumulativeSize() + { + cumulativeSize ++; + } + + + /** + * @return The cookie associated messageId + */ + public int getMessageId() + { + return messageId; + } + + + /** + * Assign the message ID to this cookie + * + * @param messageId The request message ID + */ + public void setMessageId( int messageId ) + { + this.messageId = messageId; + } + + + /** + * Serialize the cookie + * + * @return A byte array containing the data returned to the client + */ + public byte[] serialize() + { + ByteBuffer bb = ByteBuffer.allocate( 12 ); + + bb.putInt( cumulativeSize ); + bb.putInt( messageId ); + + return bb.array(); + } +} Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/extended/LaunchDiagnosticUiHandler.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/extended/LaunchDiagnosticUiHandler.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/extended/LaunchDiagnosticUiHandler.java (original) +++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/extended/LaunchDiagnosticUiHandler.java Tue Oct 7 04:26:55 2008 @@ -25,7 +25,6 @@ import java.awt.Toolkit; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import javax.swing.JFrame; @@ -95,12 +94,12 @@ adminDn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() ); LdapPrincipal principal = new LdapPrincipal( adminDn, AuthenticationLevel.STRONG ); CoreSession session = service.getSession( principal ); - Iterator list = nexus.listSuffixes( new ListSuffixOperationContext( session ) ); + Set suffixes = nexus.listSuffixes( new ListSuffixOperationContext( session ) ); int launchedWindowCount = 0; - while ( list.hasNext() ) + for ( String suffix:suffixes ) { - LdapDN dn = new LdapDN( list.next() ); + LdapDN dn = new LdapDN( suffix ); Partition partition = nexus.getPartition( dn ); if ( partition instanceof BTreePartition ) Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java (original) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java Tue Oct 7 04:26:55 2008 @@ -20,8 +20,10 @@ package org.apache.directory.server.operations.add; +import javax.naming.Context; import javax.naming.NamingEnumeration; import javax.naming.NamingException; +import javax.naming.PartialResultException; import javax.naming.ReferralException; import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; @@ -45,18 +47,26 @@ import netscape.ldap.LDAPResponseListener; import netscape.ldap.LDAPSearchConstraints; +import org.apache.directory.server.constants.ServerDNConstants; +import org.apache.directory.server.core.CoreSession; +import org.apache.directory.server.core.DirectoryService; +import org.apache.directory.server.core.authn.LdapPrincipal; import org.apache.directory.server.core.integ.Level; import org.apache.directory.server.core.integ.annotations.ApplyLdifs; import org.apache.directory.server.core.integ.annotations.CleanupLevel; +import org.apache.directory.server.core.jndi.ServerLdapContext; import org.apache.directory.server.integ.SiRunner; + import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredConnection; import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext; import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal; import org.apache.directory.server.ldap.LdapService; +import org.apache.directory.shared.ldap.constants.AuthenticationLevel; import org.apache.directory.shared.ldap.constants.SchemaConstants; import org.apache.directory.shared.ldap.message.ResultCodeEnum; +import org.apache.directory.shared.ldap.name.LdapDN; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -85,6 +95,7 @@ "cn: The Person\n" + "description: this is a person\n" + "sn: Person\n\n" + + // Entry # 1 "dn: uid=akarasulu,ou=users,ou=system\n" + "objectClass: uidObject\n" + @@ -93,6 +104,7 @@ "uid: akarasulu\n" + "cn: Alex Karasulu\n" + "sn: karasulu\n\n" + + // Entry # 2 "dn: ou=Computers,uid=akarasulu,ou=users,ou=system\n" + "objectClass: organizationalUnit\n" + @@ -100,6 +112,7 @@ "ou: computers\n" + "description: Computers for Alex\n" + "seeAlso: ou=Machines,uid=akarasulu,ou=users,ou=system\n\n" + + // Entry # 3 "dn: uid=akarasuluref,ou=users,ou=system\n" + "objectClass: uidObject\n" + @@ -564,16 +577,83 @@ attrSet.add( new LDAPAttribute( "ou", "UnderReferral" ) ); LDAPEntry entry = new LDAPEntry( "ou=UnderReferral,uid=akarasuluref,ou=users,ou=system", attrSet ); - conn.add( entry, constraints ); + try + { + conn.add( entry, constraints ); + fail(); + } + catch ( LDAPException le ) + { + assertEquals( 80, le.getLDAPResultCode() ); + } - LDAPEntry reread = conn.read( "ou=UnderReferral,uid=akarasuluref,ou=users,ou=system", - ( LDAPSearchConstraints ) constraints ); - assertEquals( "ou=UnderReferral,uid=akarasuluref,ou=users,ou=system", reread.getDN() ); + try + { + conn.read( "ou=UnderReferral,uid=akarasuluref,ou=users,ou=system", + ( LDAPSearchConstraints ) constraints ); + fail(); + } + catch ( LDAPException le ) + { + + } conn.disconnect(); } + public static LdapContext getContext( String principalDn, DirectoryService service, String dn ) + throws Exception + { + if ( principalDn == null ) + { + principalDn = ""; + } + + LdapDN userDn = new LdapDN( principalDn ); + userDn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() ); + LdapPrincipal principal = new LdapPrincipal( userDn, AuthenticationLevel.SIMPLE ); + + if ( dn == null ) + { + dn = ""; + } + + CoreSession session = service.getSession( principal ); + LdapContext ctx = new ServerLdapContext( service, session, new LdapDN( dn ) ); + return ctx; + } + + + /** + * Tests add operation on referral entry with the ManageDsaIT control. + */ + @Test + public void testOnReferralWitJNDIIgnore() throws Exception + { + LdapContext MNNCtx = getContext( ServerDNConstants.ADMIN_SYSTEM_DN, ldapService.getDirectoryService(), "uid=akarasuluref,ou=users,ou=system" ); + + // Set to 'ignore' + MNNCtx.addToEnvironment( Context.REFERRAL, "ignore" ); + + try + { + // JNDI entry + Attributes userEntry = new BasicAttributes( "objectClass", "top", true ); + userEntry.get( "objectClass" ).add( "person" ); + userEntry.put( "sn", "elecharny" ); + userEntry.put( "cn", "Emmanuel Lecharny" ); + + MNNCtx.createSubcontext( "cn=Emmanuel Lecharny, ou=apache, ou=people", userEntry ); + fail(); + } + catch ( PartialResultException pre ) + { + assertTrue( true ); + } + } + + /** * Tests referral handling when an ancestor is a referral. */ Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java (original) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java Tue Oct 7 04:26:55 2008 @@ -67,6 +67,7 @@ "uid: akarasulu\n" + "cn: Alex Karasulu\n" + "sn: karasulu\n\n" + + // Entry # 2 "dn: ou=Computers,uid=akarasulu,ou=users,ou=system\n" + "objectClass: organizationalUnit\n" + @@ -74,6 +75,7 @@ "ou: computers\n" + "description: Computers for Alex\n" + "seeAlso: ou=Machines,uid=akarasulu,ou=users,ou=system\n\n" + + // Entry # 3 "dn: uid=akarasuluref,ou=users,ou=system\n" + "objectClass: uidObject\n" + Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyDnReferralIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyDnReferralIT.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyDnReferralIT.java (original) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyDnReferralIT.java Tue Oct 7 04:26:55 2008 @@ -67,6 +67,7 @@ "uid: akarasulu\n" + "cn: Alex Karasulu\n" + "sn: karasulu\n\n" + + // Entry # 2 "dn: ou=Computers,uid=akarasulu,ou=users,ou=system\n" + "objectClass: organizationalUnit\n" + @@ -74,6 +75,7 @@ "ou: computers\n" + "description: Computers for Alex\n" + "seeAlso: ou=Machines,uid=akarasulu,ou=users,ou=system\n\n" + + // Entry # 3 "dn: uid=akarasuluref,ou=users,ou=system\n" + "objectClass: uidObject\n" + @@ -83,6 +85,7 @@ "ref: ldap://localhost:10389/uid=akarasulu,ou=users,ou=system\n" + "ref: ldap://foo:10389/uid=akarasulu,ou=users,ou=system\n" + "ref: ldap://bar:10389/uid=akarasulu,ou=users,ou=system\n\n" + + // Entry # 4 "dn: uid=elecharny,ou=users,ou=system\n" + "objectClass: uidObject\n" + @@ -136,12 +139,15 @@ conn.setConstraints( constraints ); // ModifyDN success - conn.rename( "uid=elecharny,ou=users,ou=system", "uid=newuser", - "uid=akarasuluref,ou=users,ou=system", true, constraints ); - LDAPEntry entry = conn.read( "uid=newuser,uid=akarasuluref,ou=users,ou=system", - ( LDAPSearchConstraints ) constraints ); - assertNotNull( entry ); - assertEquals( "uid=newuser,uid=akarasuluref,ou=users,ou=system", entry.getDN() ); + try + { + conn.rename( "uid=elecharny,ou=users,ou=system", "uid=newuser", + "uid=akarasuluref,ou=users,ou=system", true, constraints ); + } + catch ( LDAPException le ) + { + assertEquals ( LDAPException.AFFECTS_MULTIPLE_DSAS, le.getLDAPResultCode() ); + } conn.disconnect(); } Modified: directory/installers/trunk/apacheds-noarch/pom.xml URL: http://svn.apache.org/viewvc/directory/installers/trunk/apacheds-noarch/pom.xml?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/installers/trunk/apacheds-noarch/pom.xml (original) +++ directory/installers/trunk/apacheds-noarch/pom.xml Tue Oct 7 04:26:55 2008 @@ -43,78 +43,6 @@ org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - true - app - - - - bouncycastle:bcprov-jdk15 - - - - - - - - - - - org.apache.maven.plugins maven-jar-plugin 2.2 Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java Tue Oct 7 04:26:55 2008 @@ -1102,7 +1102,7 @@ StringBuilder sb = new StringBuilder(); sb.append( "ClientEntry\n" ); - sb.append( " dn: " ).append( dn ).append( '\n' ); + sb.append( " dn: " ).append( dn.getUpName() ).append( '\n' ); // First dump the ObjectClass attribute if ( containsAttribute( "objectClass" ) ) Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LdapURL.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LdapURL.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LdapURL.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LdapURL.java Tue Oct 7 04:26:55 2008 @@ -1351,7 +1351,7 @@ if ( dn != null ) { - sb.append( '/' ).append( urlEncode( dn.toString(), false ) ); + sb.append( '/' ).append( urlEncode( dn.getUpName(), false ) ); if ( attributes.size() != 0 || forceScopeRendering || ( ( scope != SearchControls.OBJECT_SCOPE ) || ( filter != null ) || ( extensionList.size() != 0 ) ) ) Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.java Tue Oct 7 04:26:55 2008 @@ -27,6 +27,7 @@ import javax.naming.NamingException; import org.apache.directory.shared.ldap.name.LdapDN; +import org.apache.directory.shared.ldap.name.Rdn; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,8 +35,10 @@ /** * * The Hierarchical Container holds elements ordered by their DN. - * + *
* We can see them as directories, where the leaves are the files. + *
+ * This class is *not* thread safe * * @author Apache Directory Project */ @@ -47,6 +50,8 @@ /** Stores the list of all the descendant */ private Map> children; + /** Stores the number of descendents */ + private int size; /** * Creates a new instance of a DnBranchNode. @@ -54,6 +59,7 @@ public DnBranchNode() { children = new HashMap>(3); + size = 0; } @@ -83,7 +89,14 @@ if ( index == dn.size() - 1 ) { - return current.addNode( rdnAtIndex, new DnLeafNode( element ) ); + if ( !current.contains( rdnAtIndex ) ) + { + return current.addNode( rdnAtIndex, new DnLeafNode( element ) ); + } + else + { + return null; + } } else { @@ -102,7 +115,15 @@ } DnNode child = recursivelyAddElement( (DnBranchNode)newNode, dn, index + 1, element ); - return current.addNode( rdnAtIndex, child ); + + if ( child != null ) + { + return current.addNode( rdnAtIndex, child ); + } + else + { + return null; + } } } @@ -117,6 +138,7 @@ public DnNode addNode( String rdn, DnNode child ) { children.put( rdn, child ); + size++; return this; } @@ -217,7 +239,7 @@ */ public boolean hasParentElement( LdapDN dn ) { - Enumeration rdns = dn.getAll(); + Enumeration rdns = dn.getAllRdn(); // This is synchronized so that we can't read the // partitionList when it is modified. @@ -228,7 +250,7 @@ // Iterate through all the RDN until we find the associated partition while ( rdns.hasMoreElements() ) { - String rdn = rdns.nextElement(); + Rdn rdn = rdns.nextElement(); if ( currentNode == null ) { @@ -242,9 +264,9 @@ DnBranchNode currentBranch = ( DnBranchNode ) currentNode; - if ( currentBranch.contains( rdn ) ) + if ( currentBranch.contains( rdn.getNormName() ) ) { - currentNode = currentBranch.getChild( rdn ); + currentNode = currentBranch.getChild( rdn.getNormName() ); if ( currentNode instanceof DnLeafNode ) { @@ -287,6 +309,7 @@ { // found ! Remove it from the children currentNode.children.remove( key ); + currentNode.size--; return true; } } @@ -298,8 +321,14 @@ { // If there are no more children, we can remove the node currentNode.children.remove( key ); - return true; + currentNode.size--; + } + else + { + currentNode.size--; } + + return true; } } } @@ -336,10 +365,15 @@ { recursivelyRemoveElement( currentNode, element ); } - else - { - - } + } + + + /** + * {@inheritDoc} + */ + public int size() + { + return size; } Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnLeafNode.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnLeafNode.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnLeafNode.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnLeafNode.java Tue Oct 7 04:26:55 2008 @@ -51,6 +51,9 @@ } + /** + * @return Return the stored element + */ public N getElement() { return element; @@ -58,6 +61,15 @@ /** + * {@inheritDoc} + */ + public int size() + { + return 1; + } + + + /** * @see Object#toString() */ public String toString() Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java Tue Oct 7 04:26:55 2008 @@ -37,4 +37,13 @@ * @return true if the class is a leaf node, false otherwise. */ boolean isLeaf(); + + + /** + * Returns the number of entries under this node. It includes + * the node itself, plus the sum of all it children and descendents. + * + * @return The number of descendents + */ + int size(); } Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/tree/TestDnNode.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/tree/TestDnNode.java?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/tree/TestDnNode.java (original) +++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/tree/TestDnNode.java Tue Oct 7 04:26:55 2008 @@ -125,6 +125,22 @@ assertTrue( dnLookupTree.hasParentElement( new LdapDN( "dc=nothing,dc=empty" ) ) ); assertFalse( dnLookupTree.hasParentElement( new LdapDN( "dc=directory,dc=apache,dc=root" ) ) ); } + + + /** + * Test that we can add an entry twice without any problem + * TODO testAddEntryTwice. + * + */ + @Test + public void testAddEntryTwice() throws NamingException + { + assertEquals( 6, dnLookupTree.size() ); + + dnLookupTree.add( dn1, dn1 ); + + assertEquals( 6, dnLookupTree.size() ); + } /** * test the deletion of elements in a tree @@ -133,6 +149,7 @@ public void testComplexTreeDeletion() throws NamingException { dnLookupTree.remove( dn3 ); + assertEquals( 5, dnLookupTree.size() ); assertTrue( dnLookupTree.hasParentElement( dn1 ) ); assertTrue( dnLookupTree.hasParentElement( dn2 ) ); assertTrue( dnLookupTree.hasParentElement( dn4 ) ); @@ -142,6 +159,7 @@ assertFalse( dnLookupTree.hasParentElement( new LdapDN( "dc=directory,dc=apache,dc=root" ) ) ); dnLookupTree.remove( dn6 ); + assertEquals( 4, dnLookupTree.size() ); assertTrue( dnLookupTree.hasParentElement( dn1 ) ); assertTrue( dnLookupTree.hasParentElement( dn2 ) ); assertTrue( dnLookupTree.hasParentElement( dn4 ) ); @@ -150,6 +168,7 @@ assertFalse( dnLookupTree.hasParentElement( new LdapDN( "dc=directory,dc=apache,dc=root" ) ) ); dnLookupTree.remove( dn1 ); + assertEquals( 3, dnLookupTree.size() ); assertTrue( dnLookupTree.hasParentElement( dn2 ) ); assertTrue( dnLookupTree.hasParentElement( dn4 ) ); assertTrue( dnLookupTree.hasParentElement( dn5 ) ); @@ -158,6 +177,7 @@ // Should not change anything dnLookupTree.remove( dn3 ); + assertEquals( 3, dnLookupTree.size() ); assertTrue( dnLookupTree.hasParentElement( dn2 ) ); assertTrue( dnLookupTree.hasParentElement( dn4 ) ); assertTrue( dnLookupTree.hasParentElement( dn5 ) ); @@ -165,17 +185,20 @@ assertFalse( dnLookupTree.hasParentElement( new LdapDN( "dc=directory,dc=apache,dc=root" ) ) ); dnLookupTree.remove( dn5 ); + assertEquals( 2, dnLookupTree.size() ); assertTrue( dnLookupTree.hasParentElement( dn2 ) ); assertTrue( dnLookupTree.hasParentElement( dn4 ) ); assertFalse( dnLookupTree.hasParentElement( new LdapDN( "dc=nothing,dc=empty" ) ) ); assertFalse( dnLookupTree.hasParentElement( new LdapDN( "dc=directory,dc=apache,dc=root" ) ) ); dnLookupTree.remove( dn2 ); + assertEquals( 1, dnLookupTree.size() ); assertTrue( dnLookupTree.hasParentElement( dn4 ) ); assertFalse( dnLookupTree.hasParentElement( new LdapDN( "dc=nothing,dc=empty" ) ) ); assertFalse( dnLookupTree.hasParentElement( new LdapDN( "dc=directory,dc=apache,dc=root" ) ) ); dnLookupTree.remove( dn4 ); + assertEquals( 0, dnLookupTree.size() ); assertFalse( dnLookupTree.hasParentElement( new LdapDN( "dc=nothing,dc=empty" ) ) ); assertFalse( dnLookupTree.hasParentElement( new LdapDN( "dc=directory,dc=apache,dc=root" ) ) ); } Modified: directory/shared/trunk/pom.xml URL: http://svn.apache.org/viewvc/directory/shared/trunk/pom.xml?rev=702434&r1=702433&r2=702434&view=diff ============================================================================== --- directory/shared/trunk/pom.xml (original) +++ directory/shared/trunk/pom.xml Tue Oct 7 04:26:55 2008 @@ -55,7 +55,6 @@ ldap-constants asn1-codec convert - bouncycastle-reduced