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

The following examples show how to use org.apache.directory.api.ldap.model.message.ModifyDnRequest. 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: ApacheLdapProviderImpl.java    From ldapchai with GNU Lesser General Public License v2.1 6 votes vote down vote up
@ChaiProvider.LdapOperation
@ChaiProvider.ModifyOperation
public void renameEntry( final String entryDN, final String newRDN, final String newParentDN )
        throws ChaiOperationException, ChaiUnavailableException, IllegalStateException
{
    try
    {
        final ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
        modifyDnRequest.setName( new Dn(  entryDN ) );
        modifyDnRequest.setDeleteOldRdn( true );
        modifyDnRequest.setNewRdn( new Rdn( newRDN ) );
        modifyDnRequest.setNewSuperior( new Dn( newParentDN ) );
        final ModifyDnResponse response = connection.modifyDn( modifyDnRequest );
        processResponse( response );
    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }
}
 
Example #2
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with deleteoldrdn to 0
 */
@Test
public void testRequestWithDeleteOldRdn0()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_0.xml" ).openStream(),
            "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();

    assertFalse( modifyDNRequest.getDeleteOldRdn() );
}
 
Example #3
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with deleteoldrdn to false
 */
@Test
public void testRequestWithDeleteOldRdnFalse()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_false.xml" )
            .openStream(), "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();

    assertFalse( modifyDNRequest.getDeleteOldRdn() );
}
 
Example #4
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with deleteoldrdn to 1
 */
@Test
public void testRequestWithDeleteOldRdn1()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_1.xml" ).openStream(),
            "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();

    assertTrue( modifyDNRequest.getDeleteOldRdn() );
}
 
Example #5
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with deleteoldrdn to true
 */
@Test
public void testRequestWithDeleteOldRdnTrue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput(
            ModifyDNRequestTest.class.getResource( "request_with_deleteoldrdn_true.xml" ).openStream(), "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();

    assertTrue( modifyDNRequest.getDeleteOldRdn() );
}
 
Example #6
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request without dn and newrdn attributes
 */
@Test
public void testRequestWithDnAndNewRdnAttributes()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyDNRequestTest.class.getResource( "request_with_dn_and_newrdn_attributes.xml" )
            .openStream(), "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();

    assertTrue( modifyDNRequest.getName().equals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM" ) );

    assertEquals( "CN=Steve Jobs", modifyDNRequest.getNewRdn().getName() );
}
 
Example #7
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with newSuperior attribute
 */
@Test
public void testRequestWithNewSuperior()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyDNRequestTest.class.getResource( "request_with_newSuperior_attribute.xml" )
            .openStream(), "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();

    assertTrue( modifyDNRequest.getNewSuperior().equals( "cn=Steve Jobs,ou=Dev,dc=apple,dc=com" ) );
}
 
Example #8
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of a ModifyDNRequest with an empty body
 */
@Test
public void testDecodeModifyDNRequestEmptyBody() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x07 );

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

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<ModifyDnRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    // Decode a ModifyDNRequest PDU
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, ldapMessageContainer );
    } );
}
 
Example #9
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of a ModifyDNRequest with an empty entry
 */
@Test
public void testDecodeModifyDNRequestEmptyEntry() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x09 );

    stream.put( new byte[]
        {
            0x30, 0x07,             // LDAPMessage ::= SEQUENCE {
              0x02, 0x01, 0x01,     // messageID MessageID
              0x6C, 0x02,           // CHOICE { ..., modifyDNRequest ModifyDNRequest,
                                    // ...
                0x04, 0x00          // ldapDN
        } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<ModifyDnRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    // Decode a ModifyDNRequest PDU
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, ldapMessageContainer );
    } );
}
 
Example #10
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with the (optional) requestID attribute
 */
@Test
public void testRequestWithRequestId()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyDNRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
            .openStream(), "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();

    assertEquals( 456, modifyDNRequest.getMessageId() );
}
 
Example #11
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void move( ModifyDnRequest modifyDnRequest, LogChange log ) throws LdapException
{
    MoveOperationContext moveContext = new MoveOperationContext( this, modifyDnRequest );

    moveContext.setLogChange( log );

    OperationManager operationManager = directoryService.getOperationManager();

    try
    {
        operationManager.move( moveContext );
    }
    catch ( LdapException e )
    {
        modifyDnRequest.getResultResponse().addAllControls( moveContext.getResponseControls() );
        throw e;
    }

    modifyDnRequest.getResultResponse().addAllControls( moveContext.getResponseControls() );
}
 
Example #12
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void moveAndRename( ModifyDnRequest modifyDnRequest, LogChange log ) throws LdapException
{
    MoveAndRenameOperationContext moveAndRenameContext = new MoveAndRenameOperationContext( this, modifyDnRequest );

    moveAndRenameContext.setLogChange( log );

    OperationManager operationManager = directoryService.getOperationManager();

    try
    {
        operationManager.moveAndRename( moveAndRenameContext );
    }
    catch ( LdapException e )
    {
        modifyDnRequest.getResultResponse().addAllControls( moveAndRenameContext.getResponseControls() );
        throw e;
    }

    modifyDnRequest.getResultResponse().addAllControls( moveAndRenameContext.getResponseControls() );
}
 
Example #13
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void rename( ModifyDnRequest modifyDnRequest, LogChange log ) throws LdapException
{
    RenameOperationContext renameContext = new RenameOperationContext( this, modifyDnRequest );

    renameContext.setLogChange( log );

    OperationManager operationManager = directoryService.getOperationManager();

    try
    {
        operationManager.rename( renameContext );
    }
    catch ( LdapException e )
    {
        modifyDnRequest.getResultResponse().addAllControls( renameContext.getResponseControls() );
        throw e;
    }

    modifyDnRequest.getResultResponse().addAllControls( renameContext.getResponseControls() );
}
 
Example #14
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void move( ModifyDnRequest modifyDnRequest, LogChange log ) throws LdapException
{
    MoveOperationContext moveContext = new MoveOperationContext( this, modifyDnRequest );

    moveContext.setLogChange( log );

    OperationManager operationManager = directoryService.getOperationManager();

    try
    {
        operationManager.move( moveContext );
    }
    catch ( LdapException e )
    {
        modifyDnRequest.getResultResponse().addAllControls( moveContext.getResponseControls() );
        throw e;
    }

    modifyDnRequest.getResultResponse().addAllControls( moveContext.getResponseControls() );
}
 
Example #15
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void moveAndRename( ModifyDnRequest modifyDnRequest, LogChange log ) throws LdapException
{
    MoveAndRenameOperationContext moveAndRenameContext = new MoveAndRenameOperationContext( this, modifyDnRequest );

    moveAndRenameContext.setLogChange( log );

    OperationManager operationManager = directoryService.getOperationManager();

    try
    {
        operationManager.moveAndRename( moveAndRenameContext );
    }
    catch ( LdapException e )
    {
        modifyDnRequest.getResultResponse().addAllControls( moveAndRenameContext.getResponseControls() );
        throw e;
    }

    modifyDnRequest.getResultResponse().addAllControls( moveAndRenameContext.getResponseControls() );
}
 
Example #16
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void rename( ModifyDnRequest modifyDnRequest, LogChange log ) throws LdapException
{
    RenameOperationContext renameContext = new RenameOperationContext( this, modifyDnRequest );

    renameContext.setLogChange( log );

    OperationManager operationManager = directoryService.getOperationManager();

    try
    {
        operationManager.rename( renameContext );
    }
    catch ( LdapException e )
    {
        modifyDnRequest.getResultResponse().addAllControls( renameContext.getResponseControls() );
        throw e;
    }

    modifyDnRequest.getResultResponse().addAllControls( renameContext.getResponseControls() );
}
 
Example #17
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 3 (optional) Control elements without value
 */
@Test
public void testRequestWith3ControlsWithoutValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyDNRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = modifyDNRequest.getControls();

    assertEquals( 3, modifyDNRequest.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 #18
Source File: ModifyDNRequestDsml.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ModifyDnRequest setDeleteOldRdn( boolean deleteOldRdn )
{
    getDecorated().setDeleteOldRdn( deleteOldRdn );

    return this;
}
 
Example #19
Source File: ModifyDNRequestDsml.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ModifyDnRequest setMessageId( int messageId )
{
    super.setMessageId( messageId );

    return this;
}
 
Example #20
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a (optional) Control element with empty value
 */
@Test
public void testRequestWith1ControlEmptyValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyDNRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
            .openStream(), "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = modifyDNRequest.getControls();

    assertEquals( 1, modifyDNRequest.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 #21
Source File: BatchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a Request with 2 ModDNRequest
 */
@Test
public void testResponseWith2ModDNRequest()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( BatchRequestTest.class.getResource( "request_with_2_ModDNRequest.xml" ).openStream(),
            "UTF-8" );

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

    BatchRequestDsml batchRequest = parser.getBatchRequest();

    assertEquals( 2, batchRequest.getRequests().size() );

    if ( batchRequest.getCurrentRequest() instanceof ModifyDnRequest )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #22
Source File: ModifyDNRequestDsml.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Element toDsml( Element root )
{
    Element element = super.toDsml( root );

    ModifyDnRequest request = getDecorated();

    // Dn
    if ( request.getName() != null )
    {
        element.addAttribute( "dn", request.getName().getName() );
    }

    // NewRDN
    if ( request.getNewRdn() != null )
    {
        element.addAttribute( "newrdn", request.getNewRdn().getName() );
    }

    // DeleteOldRDN
    element.addAttribute( "deleteoldrdn", request.getDeleteOldRdn() ? "true" : "false" );

    // NewSuperior
    if ( request.getNewRdn() != null )
    {
        element.addAttribute( "newSuperior", request.getNewSuperior().getName() );
    }

    return element;
}
 
Example #23
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a (optional) Control element with Base64 Value
 */
@Test
public void testRequestWith1ControlBase64Value()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyDNRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
            .openStream(), "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = modifyDNRequest.getControls();

    assertEquals( 1, modifyDNRequest.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( "DSMLv2.0 rocks!!", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #24
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a (optional) Control element
 */
@Test
public void testRequestWith1Control()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( ModifyDNRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(),
            "UTF-8" );

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

    ModifyDnRequest modifyDNRequest = ( ModifyDnRequest ) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = modifyDNRequest.getControls();

    assertEquals( 1, modifyDNRequest.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 #25
Source File: ModifyDnRequestFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Encode the ModifyDnRequest message to a PDU.
 * <br>
 * ModifyDNRequest :
 * <pre>
 * 0x6C LL
 *   0x04 LL entry
 *   0x04 LL newRDN
 *   0x01 0x01 deleteOldRDN
 *   [0x80 LL newSuperior]
 * </pre>
 *
 * @param codec The LdapApiService instance
 * @param buffer The buffer where to put the PDU
 * @param message the ModifyRequest to encode
 */
@Override
public void encodeReverse( LdapApiService codec, Asn1Buffer buffer, Message message )
{
    int start = buffer.getPos();
    ModifyDnRequest modifyDnRequest = ( ModifyDnRequest ) message;

    if ( modifyDnRequest.getNewSuperior() != null )
    {
        // Encode the new superior
        BerValue.encodeOctetString( buffer,
            ( byte ) LdapCodecConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG,
            Strings.getBytesUtf8( modifyDnRequest.getNewSuperior().getName() ) );
    }

    // The deleteOldRdn flag
    BerValue.encodeBoolean( buffer, modifyDnRequest.getDeleteOldRdn() );

    // The new RDN
    BerValue.encodeOctetString( buffer, modifyDnRequest.getNewRdn().getName() );

    // The entry DN
    BerValue.encodeOctetString( buffer, modifyDnRequest.getName().getName() );

    // The ModifyDnRequest tag
    BerValue.encodeSequence( buffer, LdapCodecConstants.MODIFY_DN_REQUEST_TAG, start );
}
 
Example #26
Source File: InitModifyDnRequest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<ModifyDnRequest> container )
{
    // Now, we can allocate the ModifyDNRequest Object
    ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
    modifyDnRequest.setMessageId( container.getMessageId() );
    container.setMessage( modifyDnRequest );

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05134_MODIFY_DN_REQUEST ) );
    }
}
 
Example #27
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test the decoding of a ModifyDNRequest with an empty newRdn
 */
@Test
public void testDecodeModifyDNRequestEmptyNewRdn() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x2D );

    stream.put( new byte[]
        {
            0x30, 0x2B,             // LDAPMessage ::= SEQUENCE {
              0x02, 0x01, 0x01,     // messageID MessageID
              0x6C, 0x26,           // CHOICE { ..., modifyDNRequest ModifyDNRequest,
                                    // ...
                0x04, 0x20,         // entry LDAPDN,
                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y',
                  ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',',
                  'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
                0x04, 0x00          // newRDN
        } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<ModifyDnRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    // Decode a ModifyDNRequest PDU
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, ldapMessageContainer );
    } );
}
 
Example #28
Source File: ModifyDNRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test the decoding of a ModifyDNRequest with an empty deleteOldRdn
 */
@Test
public void testDecodeModifyDNRequestEmptyDeleteOldRdnn() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x3C );

    stream.put( new byte[]
        {
            0x30, 0x3A,             // LDAPMessage ::= SEQUENCE {
              0x02, 0x01, 0x01,     // messageID MessageID
              0x6C, 0x35,           // CHOICE { ..., modifyDNRequest ModifyDNRequest,
                // ...
                0x04, 0x20,         // entry LDAPDN,
                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y',
                  ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',',
                  'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
                0x04, 0x0F,         // newRDN
                  'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y',
                0x01, 0x00          // deleteoldrdn BOOLEAN
    } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<ModifyDnRequest> ldapMessageContainer = new LdapMessageContainer<>( codec );

    // Decode a ModifyDNRequest PDU
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, ldapMessageContainer );
    } );
}
 
Example #29
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 modifyDnRequestHandler The ModifyDnRequest message received handler
 * @param modifyDnResponseHandler The ModifyDnResponse message sent handler
 */
public void setModifyDnHandlers( LdapRequestHandler<ModifyDnRequest> modifyDnRequestHandler,
    LdapResponseHandler<ModifyDnResponse> modifyDnResponseHandler )
{
    handler.removeReceivedMessageHandler( ModifyDnRequest.class );
    this.modifyDnRequestHandler = modifyDnRequestHandler;
    this.modifyDnRequestHandler.setLdapServer( this );
    this.handler.addReceivedMessageHandler( ModifyDnRequest.class, this.modifyDnRequestHandler );

    handler.removeSentMessageHandler( ModifyDnResponse.class );
    this.modifyDnResponseHandler = modifyDnResponseHandler;
    this.modifyDnResponseHandler.setLdapServer( this );
    this.handler.addSentMessageHandler( ModifyDnResponse.class, this.modifyDnResponseHandler );
}
 
Example #30
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 modifyDnRequestHandler The ModifyDnRequest message received handler
 * @param modifyDnResponseHandler The ModifyDnResponse message sent handler
 */
public void setModifyDnHandlers( LdapRequestHandler<ModifyDnRequest> modifyDnRequestHandler,
    LdapResponseHandler<ModifyDnResponse> modifyDnResponseHandler )
{
    handler.removeReceivedMessageHandler( ModifyDnRequest.class );
    this.modifyDnRequestHandler = modifyDnRequestHandler;
    this.modifyDnRequestHandler.setLdapServer( this );
    this.handler.addReceivedMessageHandler( ModifyDnRequest.class, this.modifyDnRequestHandler );

    handler.removeSentMessageHandler( ModifyDnResponse.class );
    this.modifyDnResponseHandler = modifyDnResponseHandler;
    this.modifyDnResponseHandler.setLdapServer( this );
    this.handler.addSentMessageHandler( ModifyDnResponse.class, this.modifyDnResponseHandler );
}