org.apache.directory.api.ldap.model.message.DeleteResponse Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.message.DeleteResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * deletes the entry with the given Dn, and all its children
 *
 * @param dn the target entry's Dn
 * @throws LdapException If the Dn is not valid or if the deletion failed
 */
public void deleteTree( Dn dn ) throws LdapException
{
    if ( isControlSupported( TreeDelete.OID ) )
    {
        DeleteRequest deleteRequest = new DeleteRequestImpl();
        deleteRequest.setName( dn );
        deleteRequest.addControl( new TreeDeleteImpl() );
        DeleteResponse deleteResponse = delete( deleteRequest );

        processResponse( deleteResponse );
    }
    else
    {
        String msg = I18n.err( I18n.ERR_04148_SUBTREE_CONTROL_NOT_SUPPORTED );
        LOG.error( msg );
        throw new LdapException( msg );
    }
}
 
Example #2
Source File: ApacheLdapProviderImpl.java    From ldapchai with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void deleteEntry( final String entryDN )
        throws ChaiOperationException, ChaiUnavailableException, IllegalStateException
{
    activityPreCheck();
    getInputValidator().deleteEntry( entryDN );

    try
    {
        final DeleteRequest deleteRequest = new DeleteRequestImpl();
        deleteRequest.setName( new Dn( entryDN ) );
        final DeleteResponse response = connection.delete( deleteRequest );
        processResponse( response );
    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }
}
 
Example #3
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of a DelResponse with no LdapResult
 */
@Test
public void testDecodeDelResponseEmptyResult() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x07 );

    stream.put( new byte[]
        {
            0x30, 0x05,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x6B, 0x00,               // CHOICE { ..., delResponse DelResponse, ...
        } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<DeleteResponse> container = new LdapMessageContainer<>( codec );

    // Decode a DelResponse message
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #4
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DeleteResponse delete( DeleteRequest deleteRequest )
{
    LdapConnection connection = null;
    try
    {
        connection = connectionPool.getConnection();
        return connection.delete( deleteRequest );
    }
    catch ( LdapException e )
    {
        throw new LdapRuntimeException( e );
    }
    finally
    {
        returnLdapConnection( connection );
    }
}
 
Example #5
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DeleteResponse delete( Dn dn, RequestBuilder<DeleteRequest> requestBuilder )
{
    DeleteRequest deleteRequest = newDeleteRequest( dn );
    if ( requestBuilder != null )
    {
        try
        {
            requestBuilder.buildRequest( deleteRequest );
        }
        catch ( LdapException e )
        {
            throw new LdapRuntimeException( e );
        }
    }
    return delete( deleteRequest );
}
 
Example #6
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Process the DeleteResponse received from the server
 * 
 * @param deleteResponse The DeleteResponse to process
 * @param deleteFuture The DeleteFuture to feed
 * @param responseId The associated request message ID
 * @throws InterruptedException If the Future is interrupted
 */
private void deleteReceived( DeleteResponse deleteResponse, DeleteFuture deleteFuture, int responseId ) 
    throws InterruptedException
{
    if ( LOG.isDebugEnabled() )
    {
        if ( deleteResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
        {
            // Everything is fine, return the response
            LOG.debug( I18n.msg( I18n.MSG_04116_DELETE_SUCCESSFUL, deleteResponse ) );
        }
        else
        {
            // We have had an error
            LOG.debug( I18n.msg( I18n.MSG_04115_DELETE_FAILED, deleteResponse ) );
        }
    }

    // Store the response into the future
    deleteFuture.set( deleteResponse );

    // Remove the future from the map
    removeFromFutureMaps( responseId );
}
 
Example #7
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with MatchedDN attribute
 */
@Test
public void testResponseWithMatchedDNAttribute()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( DelResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = delResponse.getLdapResult();

    assertTrue( ldapResult.getMatchedDn().equals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM" ) );
}
 
Example #8
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with empty Error Message
 */
@Test
public void testResponseWithEmptyErrorMessage()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( DelResponseTest.class.getResource( "response_with_empty_error_message.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = delResponse.getLdapResult();

    assertNull( ldapResult.getDiagnosticMessage() );
}
 
Example #9
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with Error Message
 */
@Test
public void testResponseWithErrorMessage()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( DelResponseTest.class.getResource( "response_with_error_message.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = delResponse.getLdapResult();

    assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult
        .getDiagnosticMessage() );
}
 
Example #10
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with Result Code
 */
@Test
public void testResponseWithResultCode()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser
            .setInput( DelResponseTest.class.getResource( "response_with_result_code.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = delResponse.getLdapResult();

    assertEquals( ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode() );
}
 
Example #11
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a Response with the (optional) requestID attribute
 */
@Test
public void testResponseWithRequestId()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( DelResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();

    assertEquals( 456, delResponse.getMessageId() );
}
 
Example #12
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 3 (optional) Control elements without value
 */
@Test
public void testResponseWith3ControlsWithoutValue()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( DelResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = delResponse.getControls();

    assertEquals( 3, delResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.456" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.456", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #13
Source File: BatchResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a Response with the 1 DelResponse
 */
@Test
public void testResponseWith1DelResponse()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( BatchResponseTest.class.getResource( "response_with_1_DelResponse.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    BatchResponseDsml batchResponse = parser.getBatchResponse();

    assertEquals( 1, batchResponse.getResponses().size() );

    DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();

    if ( response instanceof DeleteResponse )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #14
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Inject the MessageReceived and MessageSent handler into the IoHandler
 * 
 * @param deleteRequestHandler The DeleteRequest message received handler
 * @param deleteResponseHandler The DeleteResponse message sent handler
 */
public void setDeleteHandlers( LdapRequestHandler<DeleteRequest> deleteRequestHandler,
    LdapResponseHandler<DeleteResponse> deleteResponseHandler )
{
    handler.removeReceivedMessageHandler( DeleteRequest.class );
    this.deleteRequestHandler = deleteRequestHandler;
    this.deleteRequestHandler.setLdapServer( this );
    this.handler.addReceivedMessageHandler( DeleteRequest.class, this.deleteRequestHandler );

    handler.removeSentMessageHandler( DeleteResponse.class );
    this.deleteResponseHandler = deleteResponseHandler;
    this.deleteResponseHandler.setLdapServer( this );
    this.handler.addSentMessageHandler( DeleteResponse.class, this.deleteResponseHandler );
}
 
Example #15
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Inject the MessageReceived and MessageSent handler into the IoHandler
 * 
 * @param deleteRequestHandler The DeleteRequest message received handler
 * @param deleteResponseHandler The DeleteResponse message sent handler
 */
public void setDeleteHandlers( LdapRequestHandler<DeleteRequest> deleteRequestHandler,
    LdapResponseHandler<DeleteResponse> deleteResponseHandler )
{
    handler.removeReceivedMessageHandler( DeleteRequest.class );
    this.deleteRequestHandler = deleteRequestHandler;
    this.deleteRequestHandler.setLdapServer( this );
    this.handler.addReceivedMessageHandler( DeleteRequest.class, this.deleteRequestHandler );

    handler.removeSentMessageHandler( DeleteResponse.class );
    this.deleteResponseHandler = deleteResponseHandler;
    this.deleteResponseHandler.setLdapServer( this );
    this.handler.addSentMessageHandler( DeleteResponse.class, this.deleteResponseHandler );
}
 
Example #16
Source File: BatchResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a Response with the 2 DelResponse
 */
@Test
public void testResponseWith2DelResponse()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( BatchResponseTest.class.getResource( "response_with_2_DelResponse.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    BatchResponseDsml batchResponse = parser.getBatchResponse();

    assertEquals( 2, batchResponse.getResponses().size() );

    DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();

    if ( response instanceof DeleteResponse )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #17
Source File: InitDelResponse.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<DeleteResponse> container )
{
    // Now, we can allocate the DelResponse Object
    DeleteResponse delResponse = new DeleteResponseImpl( container.getMessageId() );
    container.setMessage( delResponse );

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05170_DEL_RESPONSE ) );
    }
}
 
Example #18
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element
 */
@Test
public void testResponseWith1Control()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( DelResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = delResponse.getControls();

    assertEquals( 1, delResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertEquals( "Some text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #19
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element with empty value
 */
@Test
public void testResponseWith1ControlemptyValue()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( DelResponseTest.class.getResource( "response_with_1_control_empty_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = delResponse.getControls();

    assertEquals( 1, delResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #20
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with an empty Referral
 */
@Test
public void testResponseWith1EmptyReferral()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( DelResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = delResponse.getLdapResult();

    Collection<String> referrals = ldapResult.getReferral().getLdapUrls();

    assertEquals( 0, referrals.size() );
}
 
Example #21
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 2 (optional) Control elements
 */
@Test
public void testResponseWith2Controls()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( DelResponseTest.class.getResource( "response_with_2_controls.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    DeleteResponse delResponse = ( DeleteResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = delResponse.getControls();

    assertEquals( 2, delResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.789" );

    assertNotNull( control );
    assertFalse( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.789", control.getOid() );
    assertEquals( "Some other text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #22
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * deletes the entry with the given Dn, and all its children
 *
 * @param dn the target entry's Dn as a String
 * @throws LdapException If the Dn is not valid or if the deletion failed
 */
public void deleteTree( String dn ) throws LdapException
{
    try
    {
        String treeDeleteOid = "1.2.840.113556.1.4.805";
        Dn newDn = new Dn( dn );

        if ( isControlSupported( treeDeleteOid ) )
        {
            DeleteRequest deleteRequest = new DeleteRequestImpl();
            deleteRequest.setName( newDn );
            deleteRequest.addControl( new OpaqueControl( treeDeleteOid ) );
            DeleteResponse deleteResponse = delete( deleteRequest );

            processResponse( deleteResponse );
        }
        else
        {
            String msg = I18n.err( I18n.ERR_04148_SUBTREE_CONTROL_NOT_SUPPORTED );
            LOG.error( msg );
            throw new LdapException( msg );
        }
    }
    catch ( LdapInvalidDnException e )
    {
        LOG.error( e.getMessage(), e );
        throw new LdapException( e.getMessage(), e );
    }
}
 
Example #23
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void delete( Dn dn ) throws LdapException
{
    DeleteRequest deleteRequest = new DeleteRequestImpl();
    deleteRequest.setName( dn );

    DeleteResponse deleteResponse = delete( deleteRequest );

    processResponse( deleteResponse );
}
 
Example #24
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DeleteResponse delete( Dn dn )
{
    return delete( dn, null );
}
 
Example #25
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a DelResponse
 */
@Test
public void testDecodeDelResponseSuccess() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x2D );

    stream.put( new byte[]
        {
            0x30, 0x2B,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x6B, 0x26,               // CHOICE { ..., delResponse DelResponse, ...
                                        // DelResponse ::= [APPLICATION 11] LDAPResult
                0x0A, 0x01, 0x21,       // LDAPResult ::= SEQUENCE {
                                        // resultCode ENUMERATED {
                                        // aliasProblem (33), ...
                                        // },
                0x04, 0x1F,             // matchedDN LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x04, 0x00              // errorMessage
                                        // LDAPString,
                                        // referral [3] Referral OPTIONAL }
                                        // }
    } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<DeleteResponse> container = new LdapMessageContainer<>( codec );

    // Decode the DelResponse PDU
    Asn1Decoder.decode( stream, container );

    // Check the decoded DelResponse PDU
    DeleteResponse delResponse = container.getMessage();

    assertEquals( 1, delResponse.getMessageId() );
    assertEquals( ResultCodeEnum.ALIAS_PROBLEM, delResponse.getLdapResult().getResultCode() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", delResponse.getLdapResult().getMatchedDn().getName() );
    assertEquals( "", delResponse.getLdapResult().getDiagnosticMessage() );

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, delResponse );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #26
Source File: DelResponseTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a DelResponse with controls
 */
@Test
public void testDecodeDelResponseSuccessWithControls() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x51 );

    stream.put( new byte[]
        {
            0x30, 0x4F,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x6B, 0x26,               // CHOICE { ..., delResponse DelResponse, ...
                                        // DelResponse ::= [APPLICATION 11] LDAPResult
                0x0A, 0x01, 0x21,       // LDAPResult ::= SEQUENCE {
                                        // resultCode ENUMERATED {
                                        // success (21), ...
                                        // },
                0x04, 0x1F,             // matchedDN LDAPDN,
                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',',
                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
                0x04, 0x00,             // errorMessage
                                        // LDAPString,
                                        // referral [3] Referral OPTIONAL }
                                        // }
              ( byte ) 0xA0, 0x22,      // A control
                0x30, 0x20,
                  0x04, 0x17,
                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
                    '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '7',
                  0x04, 0x05,           // Control value
                    0x30, 0x03,         // EntryChangeNotification ::= SEQUENCE {
                      0x0A, 0x01, 0x01  //     changeType ENUMERATED {
    } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<DeleteResponse> container = new LdapMessageContainer<>( codec );

    // Decode the DelResponse PDU
    Asn1Decoder.decode( stream, container );

    // Check the decoded DelResponse PDU
    DeleteResponse delResponse = container.getMessage();

    assertEquals( 1, delResponse.getMessageId() );
    assertEquals( ResultCodeEnum.ALIAS_PROBLEM, delResponse.getLdapResult().getResultCode() );
    assertEquals( "uid=akarasulu,dc=example,dc=com", delResponse.getLdapResult().getMatchedDn().getName() );
    assertEquals( "", delResponse.getLdapResult().getDiagnosticMessage() );

    // Check the Control
    Map<String, Control> controls = delResponse.getControls();

    assertEquals( 1, controls.size() );

    Control control = controls.get( "2.16.840.1.113730.3.4.7" );
    assertEquals( "2.16.840.1.113730.3.4.7", control.getOid() );
    assertTrue( control instanceof EntryChange );

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, delResponse );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #27
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * @return The MessageSent handler for the DeleteResponse
 */
public LdapResponseHandler<DeleteResponse> getDeleteResponseHandler()
{
    return deleteResponseHandler;
}
 
Example #28
Source File: LdapConnectionWrapper.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DeleteResponse delete( DeleteRequest deleteRequest ) throws LdapException
{
    return connection.delete( deleteRequest );
}
 
Example #29
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * @return The MessageSent handler for the DeleteResponse
 */
public LdapResponseHandler<DeleteResponse> getDeleteResponseHandler()
{
    return deleteResponseHandler;
}
 
Example #30
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DeleteResponse delete( DeleteRequest deleteRequest ) throws LdapException
{
    if ( deleteRequest == null )
    {
        String msg = I18n.err( I18n.ERR_04149_CANNOT_PROCESS_NULL_DEL_REQ );

        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( msg );
        }
        
        throw new IllegalArgumentException( msg );
    }

    DeleteFuture deleteFuture = deleteAsync( deleteRequest );

    // Get the result from the future
    try
    {
        // Read the response, waiting for it if not available immediately
        // Get the response, blocking
        DeleteResponse delResponse = deleteFuture.get( timeout, TimeUnit.MILLISECONDS );

        if ( delResponse == null )
        {
            // We didn't received anything : this is an error
            if ( LOG.isErrorEnabled() )
            {
                LOG.error( I18n.err( I18n.ERR_04112_OP_FAILED_TIMEOUT, "Delete" ) );
            }
            
            throw new LdapException( TIME_OUT_ERROR );
        }

        if ( delResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
        {
            // Everything is fine, return the response
            if ( LOG.isDebugEnabled() )
            { 
                LOG.debug( I18n.msg( I18n.MSG_04116_DELETE_SUCCESSFUL, delResponse ) );
            }
        }
        else
        {
            // We have had an error
            if ( LOG.isDebugEnabled() )
            { 
                LOG.debug( I18n.msg( I18n.MSG_04115_DELETE_FAILED, delResponse ) );
            }
        }

        return delResponse;
    }
    catch ( Exception ie )
    {
        // Catch all other exceptions
        LOG.error( NO_RESPONSE_ERROR, ie );

        // Send an abandon request
        if ( !deleteFuture.isCancelled() )
        {
            abandon( deleteRequest.getMessageId() );
        }

        throw new LdapException( NO_RESPONSE_ERROR, ie );
    }
}