Skip to content

Commit

Permalink
o Added a NoD factory
Browse files Browse the repository at this point in the history
o Renamed the ExtendedResponseImpl to AbstractyExtendedResponse
o Fixed the StartTransaction encoding and decoding
o Passed the OID for extended response that don't have one. It's removed
while encoding the response
o Handled OpaqueExtendedResponse properly in the LdapNetworkConnection
class (copying controls and LdapResult)
o The ExtendedFuture now hold the extendedRequest to be able to matrch
the response when it has no OID
o Fixed the API<->JNDI conversions
o Registered the NoDFactory in the LdapApiService
  • Loading branch information
elecharny committed Dec 31, 2018
1 parent e7e2049 commit 8c30eec
Show file tree
Hide file tree
Showing 30 changed files with 351 additions and 342 deletions.
Expand Up @@ -51,11 +51,11 @@
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.DeleteResponseImpl;
import org.apache.directory.api.ldap.model.message.ExtendedResponse;
import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
import org.apache.directory.api.ldap.model.message.LdapResult;
import org.apache.directory.api.ldap.model.message.Message;
import org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl;
import org.apache.directory.api.ldap.model.message.ModifyResponseImpl;
import org.apache.directory.api.ldap.model.message.OpaqueExtendedResponse;
import org.apache.directory.api.ldap.model.message.ReferralImpl;
import org.apache.directory.api.ldap.model.message.Response;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
Expand Down Expand Up @@ -459,13 +459,13 @@ public void action( Dsmlv2Container container ) throws XmlPullParserException
if ( attributeValue != null )
{
extendedResponse = new ExtendedResponseDsml(
container.getLdapCodecService(), new ExtendedResponseImpl(
container.getLdapCodecService(), new OpaqueExtendedResponse(
ParserUtils.parseAndVerifyRequestID( attributeValue, xpp ) ) );
}
else
{
extendedResponse = new ExtendedResponseDsml(
container.getLdapCodecService(), new ExtendedResponseImpl( -1 ) );
container.getLdapCodecService(), new OpaqueExtendedResponse( -1 ) );
}

container.getBatchResponse().addResponse( extendedResponse );
Expand Down
Expand Up @@ -24,8 +24,8 @@
import org.apache.directory.api.dsmlv2.ParserUtils;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.model.message.ExtendedResponse;
import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
import org.apache.directory.api.ldap.model.message.OpaqueExtendedResponse;
import org.apache.directory.api.util.Strings;
import org.dom4j.Element;
import org.dom4j.Namespace;
Expand All @@ -52,7 +52,7 @@ public class ExtendedResponseDsml extends AbstractResultResponseDsml<ExtendedRes
*/
public ExtendedResponseDsml( LdapApiService codec )
{
super( codec, new ExtendedResponseImpl( "" ) );
super( codec, new OpaqueExtendedResponse( "" ) );
}


Expand Down
Expand Up @@ -113,6 +113,7 @@
import org.apache.directory.api.ldap.model.message.ModifyRequestImpl;
import org.apache.directory.api.ldap.model.message.ModifyResponse;
import org.apache.directory.api.ldap.model.message.OpaqueExtendedRequest;
import org.apache.directory.api.ldap.model.message.OpaqueExtendedResponse;
import org.apache.directory.api.ldap.model.message.Request;
import org.apache.directory.api.ldap.model.message.Response;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
Expand Down Expand Up @@ -1482,6 +1483,7 @@ public BindResponse bind( BindRequest bindRequest ) throws LdapException
{
// Catch all other exceptions
LOG.error( NO_RESPONSE_ERROR, ie );

throw new LdapException( NO_RESPONSE_ERROR, ie );
}
}
Expand Down Expand Up @@ -2644,6 +2646,8 @@ public void messageReceived( IoSession session, Object message ) throws Exceptio
LOG.debug( I18n.msg( I18n.MSG_04117_EXTENDED_FAILED, extendedResponse ) );
}
}

extendedResponse = handleOpaqueResponse( extendedResponse, extendedFuture );

// Store the response into the future
extendedFuture.set( extendedResponse );
Expand Down Expand Up @@ -2808,6 +2812,37 @@ else if ( responseFuture instanceof ExtendedFuture )
}
}


private ExtendedResponse handleOpaqueResponse( ExtendedResponse extendedResponse, ExtendedFuture extendedFuture )
throws DecoderException
{
if ( ( extendedResponse instanceof OpaqueExtendedResponse )
&& ( Strings.isEmpty( extendedResponse.getResponseName() ) ) )
{
ExtendedOperationFactory factory = codec.getExtendedResponseFactories().
get( extendedFuture.getExtendedRequest().getRequestName() );

ExtendedResponse response = factory.newResponse( ( ( OpaqueExtendedResponse ) extendedResponse ).getResponseValue() );

// Copy the controls
for ( Control control : extendedResponse.getControls().values() )
{
response.addControl( control );
}

// copy the LDAPResult
response.getLdapResult().setDiagnosticMessage( extendedResponse.getLdapResult().getDiagnosticMessage() );
response.getLdapResult().setMatchedDn( extendedResponse.getLdapResult().getMatchedDn() );
response.getLdapResult().setReferral( extendedResponse.getLdapResult().getReferral() );
response.getLdapResult().setResultCode( extendedResponse.getLdapResult().getResultCode() );

return response;
}
else
{
return extendedResponse;
}
}

/**
* {@inheritDoc}
Expand Down Expand Up @@ -3901,8 +3936,15 @@ public ExtendedResponse extended( Oid oid, byte[] value ) throws LdapException
if ( factory != null )
{
try
{
return extended( factory.newRequest( value ) );
{
if ( value == null )
{
return extended( factory.newRequest() );
}
else
{
return extended( factory.newRequest( value ) );
}
}
catch ( DecoderException de )
{
Expand Down Expand Up @@ -4024,6 +4066,7 @@ public ExtendedFuture extendedAsync( ExtendedRequest extendedRequest ) throws Ld

extendedRequest.setMessageId( newId );
ExtendedFuture extendedFuture = new ExtendedFuture( this, newId );
extendedFuture.setExtendedRequest( extendedRequest );
addToFutureMap( newId, extendedFuture );

// Send the request to the server
Expand Down Expand Up @@ -4453,25 +4496,6 @@ public LdapConnectionConfig getConfig()
}


private void addControls( Message codec, Message message )
{
Map<String, Control> controls = codec.getControls();

if ( controls != null )
{
for ( Control cc : controls.values() )
{
if ( cc == null )
{
continue;
}

message.addControl( cc );
}
}
}


/**
* removes the Objects associated with the given message ID
* from future and response queue maps
Expand Down
Expand Up @@ -20,6 +20,8 @@
package org.apache.directory.ldap.client.api.future;


import org.apache.directory.api.ldap.model.message.ExtendedRequest;
import org.apache.directory.api.ldap.model.message.ExtendedResponse;
import org.apache.directory.api.ldap.model.message.Response;
import org.apache.directory.ldap.client.api.LdapConnection;

Expand All @@ -31,6 +33,11 @@
*/
public class ExtendedFuture extends MultipleResponseFuture<Response>
{
/**
* The extendedRequest : we need it to find which request is associated
* with a response, when this response has no name */
ExtendedRequest extendedRequest;

/**
* Creates a new instance of ExtendedFuture.
*
Expand All @@ -43,6 +50,42 @@ public ExtendedFuture( LdapConnection connection, int messageId )
}


/**
* @return the extendedRequest
*/
public ExtendedRequest getExtendedRequest()
{
return extendedRequest;
}


/**
* @param extendedRequest the extendedRequest to set
*/
public void setExtendedRequest( ExtendedRequest extendedRequest )
{
this.extendedRequest = extendedRequest;
}


/**
* Set the associated Response in this Future
*
* @param response The response to add into the Future
* @throws InterruptedException if the operation has been cancelled by client
*/
public void set( ExtendedResponse response ) throws InterruptedException
{
if ( response.getResponseName() == null )
{
// Feed the response with the request's OID
response.setResponseName( extendedRequest.getRequestName() );
}

queue.add( response );
}


/**
* {@inheritDoc}
*/
Expand Down
Expand Up @@ -103,7 +103,7 @@ public void action( LdapMessageContainerDirect<ExtendedResponse> container ) thr

if ( factory != null )
{
// Create the extended request
// Create the extended response
extendedResponse = factory.newResponse();

// Move the LDAPResult in the newly created response
Expand Down
Expand Up @@ -23,6 +23,8 @@
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.model.message.ExtendedRequest;
import org.apache.directory.api.ldap.model.message.ExtendedResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A Factory to encode Extended Request and Response messages
Expand All @@ -31,6 +33,9 @@
*/
public abstract class AbstractExtendedOperationFactory implements ExtendedOperationFactory
{
/** logger for reporting errors that might not be handled properly upstream */
protected static final Logger LOG = LoggerFactory.getLogger( AbstractExtendedOperationFactory.class );

/** The LDAP codec responsible for encoding and decoding */
protected LdapApiService codec;

Expand Down
Expand Up @@ -349,10 +349,25 @@ public javax.naming.ldap.Control toJndiControl( Control control ) throws Encoder
{
// We don't know if it's a request or a response control. Test with request contriols
ControlFactory<?> factory = requestControlFactories.get( control.getOid() );
Asn1Buffer asn1Buffer = new Asn1Buffer();
factory.encodeValue( asn1Buffer, control );

return new BasicControl( control.getOid(), control.isCritical(), asn1Buffer.getBytes().array() );

if ( factory == null )
{
if ( control instanceof OpaqueControl )
{
return new BasicControl( control.getOid(), control.isCritical(), ( ( OpaqueControl ) control ).getEncodedValue() );
}
else
{
return new BasicControl( control.getOid(), control.isCritical(), null );
}
}
else
{
Asn1Buffer asn1Buffer = new Asn1Buffer();
factory.encodeValue( asn1Buffer, control );

return new BasicControl( control.getOid(), control.isCritical(), asn1Buffer.getBytes().array() );
}
}


Expand Down
Expand Up @@ -69,6 +69,7 @@
import org.apache.directory.api.ldap.extras.extended.ads_impl.endTransaction.EndTransactionFactory;
import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectFactory;
import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownFactory;
import org.apache.directory.api.ldap.extras.extended.ads_impl.nod.NoDFactory;
import org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyFactory;
import org.apache.directory.api.ldap.extras.extended.ads_impl.startTls.StartTlsFactory;
import org.apache.directory.api.ldap.extras.extended.ads_impl.startTransaction.StartTransactionFactory;
Expand Down Expand Up @@ -388,11 +389,20 @@ public static void loadStockExtendedOperations(
extendendRequestFactories.put( gracefulShutdownFactory.getOid(), gracefulShutdownFactory );
extendendResponseFactories.put( gracefulShutdownFactory.getOid(), gracefulShutdownFactory );


if ( LOG.isInfoEnabled() )
{
LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, gracefulShutdownFactory.getOid() ) );
}

NoDFactory noticeOfDisconnectFactory = new NoDFactory( apiService );
extendendResponseFactories.put( noticeOfDisconnectFactory.getOid(), noticeOfDisconnectFactory );

if ( LOG.isInfoEnabled() )
{
LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, noticeOfDisconnectFactory.getOid() ) );
}

PasswordModifyFactory passwordModifyFactory = new PasswordModifyFactory( apiService );
extendendRequestFactories.put( passwordModifyFactory.getOid(), passwordModifyFactory );
extendendResponseFactories.put( passwordModifyFactory.getOid(), passwordModifyFactory );
Expand Down
Expand Up @@ -21,7 +21,7 @@


import org.apache.directory.api.i18n.I18n;
import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
import org.apache.directory.api.ldap.model.message.AbstractExtendedResponse;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;


Expand All @@ -31,7 +31,7 @@
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class CancelResponseImpl extends ExtendedResponseImpl implements CancelResponse
public class CancelResponseImpl extends AbstractExtendedResponse implements CancelResponse
{
/**
* Create a new CancelResponse object
Expand Down
Expand Up @@ -21,7 +21,7 @@


import org.apache.directory.api.i18n.I18n;
import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
import org.apache.directory.api.ldap.model.message.AbstractExtendedResponse;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;


Expand All @@ -31,7 +31,7 @@
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class CertGenerationResponseImpl extends ExtendedResponseImpl implements CertGenerationResponse
public class CertGenerationResponseImpl extends AbstractExtendedResponse implements CertGenerationResponse
{
/**
* Create a new CertGenerationResponseImpl instance
Expand Down Expand Up @@ -84,19 +84,6 @@ public CertGenerationResponseImpl()
}


/**
* Gets the OID uniquely identifying this extended response (a.k.a. its
* name).
*
* @return the OID of the extended response type.
*/
@Override
public String getResponseName()
{
return EXTENSION_OID;
}


/**
* Sets the OID uniquely identifying this extended response (a.k.a. its
* name).
Expand Down

0 comments on commit 8c30eec

Please sign in to comment.