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/10/07 02:30:21 UTC
svn commit: r1005304 - in /directory:
apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/
apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/
shared/trunk/ldap-client-api/src/main/j...
Author: elecharny
Date: Thu Oct 7 00:30:20 2010
New Revision: 1005304
URL: http://svn.apache.org/viewvc?rev=1005304&view=rev
Log:
o Added a test for big PDU using the LDAP API
o Added a cancel() method in the ResponseFuture
o Added a Modify<DoN>response : this is a dedicated response to add in the Modify queue when we get a NoticeOfDisconnect
o Correctly handle the NoD in the LdapNetworkConnection class
Added:
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/extended/ModifyNoDResponse.java
Modified:
directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/IllegalModificationIT.java
directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/future/ResponseFuture.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/extended/NoticeOfDisconnect.java
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=1005304&r1=1005303&r2=1005304&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 Thu Oct 7 00:30:20 2010
@@ -63,6 +63,7 @@ import netscape.ldap.LDAPResponseListene
import netscape.ldap.LDAPSearchConstraints;
import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.constants.ServerDNConstants;
@@ -82,8 +83,12 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.csn.Csn;
import org.apache.directory.shared.ldap.csn.CsnFactory;
import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.entry.DefaultModification;
import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.ldif.LdifUtils;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.name.DN;
@@ -1082,7 +1087,7 @@ public class AddIT extends AbstractLdapT
* @throws NamingException
*/
@Test
- public void testAddPDUExceedingMaxSize() throws Exception
+ public void testAddPDUExceedingMaxSizeJNDI() throws Exception
{
// Limit the PDU size to 1024
ldapServer.getDirectoryService().setMaxPDUSize( 1024 );
@@ -1145,6 +1150,45 @@ public class AddIT extends AbstractLdapT
/**
+ * Test that if we inject a PDU above the max allowed size,
+ * the connection is closed.
+ *
+ * @throws NamingException
+ */
+ @Test
+ public void testAddPDUExceedingMaxSizeLdapApi() throws Exception
+ {
+ // Limit the PDU size to 1024
+ ldapServer.getDirectoryService().setMaxPDUSize( 1024 );
+ LdapConnection connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+ connection.setTimeOut( Integer.MAX_VALUE );
+ connection.bind( "uid=admin,ou=system", "secret" );
+
+ // Inject a 1024 bytes long description
+ StringBuilder sb = new StringBuilder();
+
+ for ( int i = 0; i < 128; i++ )
+ {
+ sb.append( "0123456789ABCDEF" );
+ }
+
+ EntryAttribute description = new DefaultEntryAttribute( "description", sb.toString() );
+
+ try
+ {
+ Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, description );
+ connection.modify( "cn=the person, ou=system", modification );
+ fail();
+ }
+ catch ( Exception e )
+ {
+ // We are expecting the session to be close here.
+ assertFalse( connection.isConnected() );
+ }
+ }
+
+
+ /**
* Test for DIRSERVER-1311: If the RDN attribute+value is not present
* in the entry the server should implicit add this attribute+value to
* the entry. Additionally, if the RDN value is escaped or a hexstring
Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/IllegalModificationIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/IllegalModificationIT.java?rev=1005304&r1=1005303&r2=1005304&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/IllegalModificationIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/IllegalModificationIT.java Thu Oct 7 00:30:20 2010
@@ -41,7 +41,6 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.message.ModifyRequestImpl;
import org.apache.directory.shared.ldap.message.ModifyResponse;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.message.SearchResultEntry;
import org.apache.directory.shared.ldap.name.DN;
import org.junit.Test;
import org.junit.runner.RunWith;
Modified: directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1005304&r1=1005303&r2=1005304&view=diff
==============================================================================
--- directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Thu Oct 7 00:30:20 2010
@@ -114,6 +114,8 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.message.UnbindRequest;
import org.apache.directory.shared.ldap.message.UnbindRequestImpl;
import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.extended.ModifyNoDResponse;
+import org.apache.directory.shared.ldap.message.extended.NoticeOfDisconnect;
import org.apache.directory.shared.ldap.name.DN;
import org.apache.directory.shared.ldap.name.RDN;
import org.apache.directory.shared.ldap.schema.AttributeType;
@@ -129,6 +131,8 @@ import org.apache.directory.shared.ldap.
import org.apache.mina.core.filterchain.IoFilter;
import org.apache.mina.core.future.CloseFuture;
import org.apache.mina.core.future.ConnectFuture;
+import org.apache.mina.core.future.IoFuture;
+import org.apache.mina.core.future.IoFutureListener;
import org.apache.mina.core.future.WriteFuture;
import org.apache.mina.core.service.IoConnector;
import org.apache.mina.core.service.IoHandlerAdapter;
@@ -511,6 +515,42 @@ public class LdapNetworkConnection exten
return false;
}
+ // Get the close future for this session
+ CloseFuture closeFuture = connectionFuture.getSession().getCloseFuture();
+
+ // Add a listener to close the session in the session.
+ closeFuture.addListener( ( IoFutureListener<?> ) new IoFutureListener<IoFuture>()
+ {
+ public void operationComplete( IoFuture future )
+ {
+ // Nothing to do here
+ //System.out.println( "received a NoD, closing everything" );
+
+ for ( int messageId : futureMap.keySet() )
+ {
+ ResponseFuture<?> responseFuture = futureMap.get( messageId );
+ //System.out.println( "closing " + responseFuture );
+
+ try
+ {
+ if ( responseFuture instanceof ModifyFuture )
+ {
+ responseFuture.cancel();
+ ( ( ModifyFuture ) responseFuture ).set( ModifyNoDResponse.PROTOCOLERROR );
+ }
+ }
+ catch ( Exception e )
+ {
+
+ }
+
+ futureMap.remove( messageId );
+ }
+
+ futureMap.clear();
+ }
+ } );
+
// Get back the session
ldapSession = connectionFuture.getSession();
connected.set( true );
@@ -788,7 +828,7 @@ public class LdapNetworkConnection exten
// this shouldn't happen
LOG
.error(
- "There is no future asscoiated with operation message ID {}, perhaps the operation would have been completed",
+ "There is no future associated with operation message ID {}, perhaps the operation would have been completed",
abandonId );
}
}
@@ -1496,7 +1536,14 @@ public class LdapNetworkConnection exten
*/
public void setTimeOut( long timeout )
{
- this.timeout = timeout;
+ if ( timeout <= 0 )
+ {
+ this.timeout = Long.MAX_VALUE;
+ }
+ else
+ {
+ this.timeout = timeout;
+ }
}
@@ -1526,6 +1573,25 @@ public class LdapNetworkConnection exten
/**
+ * Check if the message is a NoticeOfDisconnect message
+ */
+ private boolean isNoticeOfDisconnect( Message message )
+ {
+ if ( message instanceof ExtendedResponse )
+ {
+ ExtendedResponse response = ( ExtendedResponse ) message;
+
+ if ( response.getResponseName().equals( NoticeOfDisconnect.EXTENSION_OID ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+ /**
* Handle the incoming LDAP messages. This is where we feed the cursor for search
* requests, or call the listener.
*
@@ -1544,12 +1610,22 @@ public class LdapNetworkConnection exten
// result(s) to corresponding queue
ResponseFuture<? extends Response> responseFuture = peekFromFutureMap( messageId );
- if ( responseFuture == null )
+ boolean isNoD = isNoticeOfDisconnect( response );
+
+ if ( ( responseFuture == null ) && !isNoD )
{
LOG.info( "There is no future associated with the messageId {}, ignoring the message", messageId );
return;
}
+ if ( isNoD )
+ {
+ // close the session
+ session.close( true );
+
+ return;
+ }
+
switch ( response.getType() )
{
case ADD_RESPONSE:
@@ -1947,6 +2023,12 @@ public class LdapNetworkConnection exten
}
else
{
+ if ( modifyResponse instanceof ModifyNoDResponse )
+ {
+ // A NoticeOfDisconnect : deserves a special treatment
+ throw new LdapException( modifyResponse.getLdapResult().getErrorMessage() );
+ }
+
// We have had an error
LOG.debug( "Modify failed : {}", modifyResponse );
}
@@ -1969,7 +2051,7 @@ public class LdapNetworkConnection exten
{
// Catch all other exceptions
LOG.error( NO_RESPONSE_ERROR, ie );
- LdapException ldapException = new LdapException( NO_RESPONSE_ERROR );
+ LdapException ldapException = new LdapException( ie.getMessage() );
ldapException.initCause( ie );
// Send an abandon request
@@ -3275,7 +3357,6 @@ public class LdapNetworkConnection exten
if ( result.getResultCode() == ResultCodeEnum.SUCCESS )
{
- System.out.println( "received successful result code " + result );
addSslFilter();
}
else
Modified: directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/future/ResponseFuture.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/future/ResponseFuture.java?rev=1005304&r1=1005303&r2=1005304&view=diff
==============================================================================
--- directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/future/ResponseFuture.java (original)
+++ directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/future/ResponseFuture.java Thu Oct 7 00:30:20 2010
@@ -171,6 +171,13 @@ public class ResponseFuture<R extends Re
}
+ public void cancel()
+ {
+ // set the cancel flag first
+ cancelled = true;
+ }
+
+
@Override
public String toString()
{
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/extended/ModifyNoDResponse.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/extended/ModifyNoDResponse.java?rev=1005304&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/extended/ModifyNoDResponse.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/extended/ModifyNoDResponse.java Thu Oct 7 00:30:20 2010
@@ -0,0 +1,138 @@
+/*
+ * 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.message.extended;
+
+
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.message.ModifyResponseImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+
+
+/**
+ * An extended operation intended for notifying clients of upcoming
+ * disconnection. * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyNoDResponse extends ModifyResponseImpl
+{
+ /** The OID of the NotiveOfDisconnect extended operation. */
+ public static final String EXTENSION_OID = "1.3.6.1.4.1.1466.20036";
+
+ /** The empty response */
+ private static final byte[] EMPTY_RESPONSE = new byte[0];
+
+ /** The single instance with unavailable result code. */
+ public static final ModifyNoDResponse UNAVAILABLE = new ModifyNoDResponse( ResultCodeEnum.UNAVAILABLE );
+
+ /** The single instance with protocolError result code. */
+ public static final ModifyNoDResponse PROTOCOLERROR = new ModifyNoDResponse( ResultCodeEnum.PROTOCOL_ERROR );
+
+ /** The single instance with strongAuthRequired result code. */
+ public static final ModifyNoDResponse STRONGAUTHREQUIRED = new ModifyNoDResponse(
+ ResultCodeEnum.STRONG_AUTH_REQUIRED );
+
+
+ /**
+ * Creates a new instance of NoticeOfDisconnect.
+ */
+ private ModifyNoDResponse( ResultCodeEnum rcode )
+ {
+ super();
+
+ switch ( rcode )
+ {
+ case UNAVAILABLE:
+ break;
+
+ case PROTOCOL_ERROR:
+ break;
+
+ case STRONG_AUTH_REQUIRED:
+ break;
+
+ default:
+ throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.UNAVAILABLE,
+ ResultCodeEnum.PROTOCOL_ERROR, ResultCodeEnum.STRONG_AUTH_REQUIRED ) );
+ }
+
+ super.getLdapResult().setErrorMessage( rcode.toString() + ": The server will disconnect!" );
+ super.getLdapResult().setMatchedDn( null );
+ super.getLdapResult().setResultCode( rcode );
+ }
+
+
+ // ------------------------------------------------------------------------
+ // ExtendedResponse Interface Method Implementations
+ // ------------------------------------------------------------------------
+ /**
+ * Gets the reponse OID specific encoded response values.
+ *
+ * @return the response specific encoded response values.
+ */
+ public byte[] getResponse()
+ {
+ return EMPTY_RESPONSE;
+ }
+
+
+ /**
+ * Gets the OID uniquely identifying this extended response (a.k.a. its
+ * name).
+ *
+ * @return the OID of the extended response type.
+ */
+ public String getResponseName()
+ {
+ return EXTENSION_OID;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ int hash = 37;
+ // Seems simple but look at the equals() method ...
+ hash = hash * 17 + getClass().getName().hashCode();
+
+ return hash;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( obj == this )
+ {
+ return true;
+ }
+
+ if ( obj instanceof ModifyNoDResponse )
+ {
+ return true;
+ }
+
+ return false;
+ }
+}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/extended/NoticeOfDisconnect.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/extended/NoticeOfDisconnect.java?rev=1005304&r1=1005303&r2=1005304&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/extended/NoticeOfDisconnect.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/extended/NoticeOfDisconnect.java Thu Oct 7 00:30:20 2010
@@ -103,7 +103,6 @@ import org.apache.directory.shared.ldap.
*/
public final class NoticeOfDisconnect extends ExtendedResponseImpl
{
-
/** The serialVersionUID. */
private static final long serialVersionUID = -4682291068700593492L;
@@ -124,6 +123,9 @@ public final class NoticeOfDisconnect ex
ResultCodeEnum.STRONG_AUTH_REQUIRED );
+ /**
+ * Creates a new instance of NoticeOfDisconnect.
+ */
private NoticeOfDisconnect( ResultCodeEnum rcode )
{
super( 0, EXTENSION_OID );
@@ -166,10 +168,9 @@ public final class NoticeOfDisconnect ex
/**
- * Sets the reponse OID specific encoded response values.
+ * Sets the response OID specific encoded response values.
*
- * @param value
- * the response specific encoded response values.
+ * @param value the response specific encoded response values.
*/
public void setResponse( byte[] value )
{