org.apache.directory.api.ldap.model.message.ModifyResponse Java Examples
The following examples show how to use
org.apache.directory.api.ldap.model.message.ModifyResponse.
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: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test parsing of a Response with the (optional) requestID attribute */ @Test public void testResponseWithRequestId() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_requestID_attribute.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); assertEquals( 456, modifyResponse.getMessageId() ); }
Example #2
Source File: ApacheLdapProviderImpl.java From ldapchai with GNU Lesser General Public License v2.1 | 6 votes |
public void writeStringAttribute( final String entryDN, final String attributeName, final Set<String> values, final boolean overwrite ) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException { activityPreCheck(); getInputValidator().writeStringAttribute( entryDN, attributeName, values, overwrite ); try { final ModifyRequest modifyRequest = new ModifyRequestImpl(); modifyRequest.setName( new Dn( entryDN ) ); { final Modification modification = new DefaultModification(); modification.setOperation( overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE ); modification.setAttribute( new DefaultAttribute( attributeName, values.toArray( new String[values.size()] ) ) ); modifyRequest.addModification( modification ); } final ModifyResponse response = connection.modify( modifyRequest ); processResponse( response ); } catch ( LdapException e ) { throw ChaiOperationException.forErrorMessage( e.getMessage() ); } }
Example #3
Source File: ApacheLdapProviderImpl.java From ldapchai with GNU Lesser General Public License v2.1 | 6 votes |
public void writeBinaryAttribute( final String entryDN, final String attributeName, final byte[][] values, final boolean overwrite, final ChaiRequestControl[] controls ) throws ChaiUnavailableException, ChaiOperationException { try { final ModifyRequest modifyRequest = new ModifyRequestImpl(); modifyRequest.setName( new Dn( entryDN ) ); modifyRequest.addAllControls( figureControls( controls ) ); { final Modification modification = new DefaultModification(); modification.setOperation( overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE ); modification.setAttribute( new DefaultAttribute( attributeName, values ) ); modifyRequest.addModification( modification ); } final ModifyResponse response = connection.modify( modifyRequest ); processResponse( response ); } catch ( LdapException e ) { throw ChaiOperationException.forErrorMessage( e.getMessage() ); } }
Example #4
Source File: ApacheLdapProviderImpl.java From ldapchai with GNU Lesser General Public License v2.1 | 6 votes |
public void writeBinaryAttribute( final String entryDN, final String attributeName, final byte[][] values, final boolean overwrite ) throws ChaiUnavailableException, ChaiOperationException { activityPreCheck(); getInputValidator().writeBinaryAttribute( entryDN, attributeName, values, overwrite ); try { final ModifyRequest modifyRequest = new ModifyRequestImpl(); modifyRequest.setName( new Dn( entryDN ) ); { final Modification modification = new DefaultModification(); modification.setOperation( overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE ); modification.setAttribute( new DefaultAttribute( attributeName, values ) ); modifyRequest.addModification( modification ); } final ModifyResponse response = connection.modify( modifyRequest ); processResponse( response ); } catch ( LdapException e ) { throw ChaiOperationException.forErrorMessage( e.getMessage() ); } }
Example #5
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test parsing of a response with Result Code */ @Test public void testResponseWithResultCode() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_result_code.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); LdapResult ldapResult = modifyResponse.getLdapResult(); assertEquals( ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode() ); }
Example #6
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test parsing of a response with Error Message */ @Test public void testResponseWithErrorMessage() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_error_message.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); LdapResult ldapResult = modifyResponse.getLdapResult(); assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult .getDiagnosticMessage() ); }
Example #7
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test parsing of a response with empty Error Message */ @Test public void testResponseWithEmptyErrorMessage() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_empty_error_message.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); LdapResult ldapResult = modifyResponse.getLdapResult(); assertNull( ldapResult.getDiagnosticMessage() ); }
Example #8
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test parsing of a response with MatchedDN attribute */ @Test public void testResponseWithMatchedDNAttribute() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); LdapResult ldapResult = modifyResponse.getLdapResult(); assertTrue( ldapResult.getMatchedDn().equals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM" ) ); }
Example #9
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test the decoding of a ModifyResponse with no LdapResult */ @Test public void testDecodeModifyResponseEmptyResult() throws DecoderException { ByteBuffer stream = ByteBuffer.allocate( 0x07 ); stream.put( new byte[] { 0x30, 0x05, // LDAPMessage ::=SEQUENCE { 0x02, 0x01, 0x01, // messageID MessageID 0x67, 0x00, // CHOICE { ..., modifyResponse ModifyResponse, ... } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyResponse> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyResponse message assertThrows( DecoderException.class, ( ) -> { Asn1Decoder.decode( stream, ldapMessageContainer ); } ); }
Example #10
Source File: LdapConnectionTemplate.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public ModifyResponse modify( ModifyRequest modifyRequest ) { LdapConnection connection = null; try { connection = connectionPool.getConnection(); return connection.modify( modifyRequest ); } catch ( LdapException e ) { throw new LdapRuntimeException( e ); } finally { returnLdapConnection( connection ); } }
Example #11
Source File: ApacheLdapProviderImpl.java From ldapchai with GNU Lesser General Public License v2.1 | 5 votes |
public void writeStringAttributes( final String entryDN, final Map<String, String> attributeValueProps, final boolean overwrite ) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException { activityPreCheck(); getInputValidator().writeStringAttributes( entryDN, attributeValueProps, overwrite ); try { final ModifyRequest modifyRequest = new ModifyRequestImpl(); modifyRequest.setName( new Dn( entryDN ) ); for ( final Map.Entry<String, String> entry : attributeValueProps.entrySet() ) { final String name = entry.getKey(); final String value = entry.getValue(); final Modification modification = new DefaultModification(); modification.setOperation( overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE ); modification.setAttribute( new DefaultAttribute( name, value ) ); modifyRequest.addModification( modification ); } final ModifyResponse response = connection.modify( modifyRequest ); processResponse( response ); } catch ( LdapException e ) { throw ChaiOperationException.forErrorMessage( e.getMessage() ); } }
Example #12
Source File: LdapServer.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Inject the MessageReceived and MessageSent handler into the IoHandler * * @param modifyRequestHandler The ModifyRequest message received handler * @param modifyResponseHandler The ModifyResponse message sent handler */ public void setModifyHandlers( LdapRequestHandler<ModifyRequest> modifyRequestHandler, LdapResponseHandler<ModifyResponse> modifyResponseHandler ) { handler.removeReceivedMessageHandler( ModifyRequest.class ); this.modifyRequestHandler = modifyRequestHandler; this.modifyRequestHandler.setLdapServer( this ); this.handler.addReceivedMessageHandler( ModifyRequest.class, this.modifyRequestHandler ); handler.removeSentMessageHandler( ModifyResponse.class ); this.modifyResponseHandler = modifyResponseHandler; this.modifyResponseHandler.setLdapServer( this ); this.handler.addSentMessageHandler( ModifyResponse.class, this.modifyResponseHandler ); }
Example #13
Source File: LdapServer.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Inject the MessageReceived and MessageSent handler into the IoHandler * * @param modifyRequestHandler The ModifyRequest message received handler * @param modifyResponseHandler The ModifyResponse message sent handler */ public void setModifyHandlers( LdapRequestHandler<ModifyRequest> modifyRequestHandler, LdapResponseHandler<ModifyResponse> modifyResponseHandler ) { handler.removeReceivedMessageHandler( ModifyRequest.class ); this.modifyRequestHandler = modifyRequestHandler; this.modifyRequestHandler.setLdapServer( this ); this.handler.addReceivedMessageHandler( ModifyRequest.class, this.modifyRequestHandler ); handler.removeSentMessageHandler( ModifyResponse.class ); this.modifyResponseHandler = modifyResponseHandler; this.modifyResponseHandler.setLdapServer( this ); this.handler.addSentMessageHandler( ModifyResponse.class, this.modifyResponseHandler ); }
Example #14
Source File: InitModifyResponse.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void action( LdapMessageContainer<ModifyResponse> container ) { // Now, we can allocate the ModifyResponse Object ModifyResponse modifyResponse = new ModifyResponseImpl( container.getMessageId() ); container.setMessage( modifyResponse ); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_05176_MODIFY_RESPONSE ) ); } }
Example #15
Source File: LdapConnectionTemplate.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public ModifyResponse modify( Dn dn, RequestBuilder<ModifyRequest> requestBuilder ) { ModifyRequest modifyRequest = newModifyRequest( dn ); try { requestBuilder.buildRequest( modifyRequest ); } catch ( LdapException e ) { throw new LdapRuntimeException( e ); } return modify( modifyRequest ); }
Example #16
Source File: LdapNetworkConnection.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void modify( Entry entry, ModificationOperation modOp ) throws LdapException { if ( entry == null ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04140_NULL_ENTRY_MODIFY ) ); } throw new IllegalArgumentException( I18n.err( I18n.ERR_04133_NULL_MODIFIED_ENTRY ) ); } ModifyRequest modReq = new ModifyRequestImpl(); modReq.setName( entry.getDn() ); Iterator<Attribute> itr = entry.iterator(); while ( itr.hasNext() ) { modReq.addModification( itr.next(), modOp ); } ModifyResponse modifyResponse = modify( modReq ); processResponse( modifyResponse ); }
Example #17
Source File: LdapNetworkConnection.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Process the ModifyResponse received from the server * * @param modifyResponse The ModifyResponse to process * @param modifyFuture The ModifyFuture to feed * @param responseId The associated request message ID * @throws InterruptedException If the Future is interrupted */ private void modifyReceived( ModifyResponse modifyResponse, ModifyFuture modifyFuture, int responseId ) throws InterruptedException { if ( LOG.isDebugEnabled() ) { if ( modifyResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS ) { // Everything is fine, return the response if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04123_MODIFY_SUCCESSFUL, modifyResponse ) ); } } else { // We have had an error if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04122_MODIFY_FAILED, modifyResponse ) ); } } } // Store the response into the future modifyFuture.set( modifyResponse ); // Remove the future from the map removeFromFutureMaps( responseId ); }
Example #18
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a response with a (optional) Control element */ @Test public void testResponseWith1Control() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); Map<String, Control> controls = modifyResponse.getControls(); assertEquals( 1, modifyResponse.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: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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( ModifyResponseTest.class.getResource( "response_with_1_control_empty_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); Map<String, Control> controls = modifyResponse.getControls(); assertEquals( 1, modifyResponse.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: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a response with 2 (optional) Control elements */ @Test public void testResponseWith2Controls() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_2_controls.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); Map<String, Control> controls = modifyResponse.getControls(); assertEquals( 2, modifyResponse.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 #21
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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( ModifyResponseTest.class.getResource( "response_with_3_controls_without_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); Map<String, Control> controls = modifyResponse.getControls(); assertEquals( 3, modifyResponse.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 #22
Source File: BatchResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a Response with the 2 ModifyResponse */ @Test public void testResponseWith2ModifyResponse() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( BatchResponseTest.class.getResource( "response_with_2_ModifyResponse.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 ModifyResponse ) { assertTrue( true ); } else { fail(); } }
Example #23
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a response with an empty Referral */ @Test public void testResponseWith1EmptyReferral() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); LdapResult ldapResult = modifyResponse.getLdapResult(); Collection<String> referrals = ldapResult.getReferral().getLdapUrls(); assertEquals( 0, referrals.size() ); }
Example #24
Source File: BatchResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a Response with the 1 ModifyResponse */ @Test public void testResponseWith1ModifyResponse() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( BatchResponseTest.class.getResource( "response_with_1_ModifyResponse.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 ModifyResponse ) { assertTrue( true ); } else { fail(); } }
Example #25
Source File: LdapNetworkConnection.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public ModifyResponse modify( ModifyRequest modRequest ) throws LdapException { if ( modRequest == null ) { String msg = I18n.err( I18n.ERR_04136_CANNOT_PROCESS_NULL_MOD_REQ ); if ( LOG.isDebugEnabled() ) { LOG.debug( msg ); } throw new IllegalArgumentException( msg ); } ModifyFuture modifyFuture = modifyAsync( modRequest ); // Get the result from the future try { // Read the response, waiting for it if not available immediately // Get the response, blocking ModifyResponse modifyResponse = modifyFuture.get( timeout, TimeUnit.MILLISECONDS ); if ( modifyResponse == null ) { // We didn't received anything : this is an error if ( LOG.isErrorEnabled() ) { LOG.error( I18n.err( I18n.ERR_04112_OP_FAILED_TIMEOUT, "Modify" ) ); } throw new LdapException( TIME_OUT_ERROR ); } if ( modifyResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS ) { // Everything is fine, return the response if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04123_MODIFY_SUCCESSFUL, modifyResponse ) ); } } else { if ( modifyResponse instanceof ModifyNoDResponse ) { // A NoticeOfDisconnect : deserves a special treatment throw new LdapException( modifyResponse.getLdapResult().getDiagnosticMessage() ); } // We have had an error if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04122_MODIFY_FAILED, modifyResponse ) ); } } return modifyResponse; } catch ( Exception ie ) { // Catch all other exceptions LOG.error( NO_RESPONSE_ERROR, ie ); // Send an abandon request if ( !modifyFuture.isCancelled() ) { abandon( modRequest.getMessageId() ); } throw new LdapException( ie.getMessage(), ie ); } }
Example #26
Source File: LdapServer.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * @return The MessageSent handler for the ModifyResponse */ public LdapResponseHandler<ModifyResponse> getModifyResponseHandler() { return modifyResponseHandler; }
Example #27
Source File: LdapServer.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * @return The MessageSent handler for the ModifyResponse */ public LdapResponseHandler<ModifyResponse> getModifyResponseHandler() { return modifyResponseHandler; }
Example #28
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test the decoding of a ModifyResponse with controls */ @Test public void testDecodeModifyResponseSuccessWithControls() throws DecoderException, EncoderException { ByteBuffer stream = ByteBuffer.allocate( 0x32 ); stream.put( new byte[] { 0x30, 0x30, // LDAPMessage ::=SEQUENCE { 0x02, 0x01, 0x01, // messageID MessageID 0x67, 0x07, // CHOICE { ..., modifyResponse ModifyResponse, ... // ModifyResponse ::= [APPLICATION 7] LDAPResult 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE { // resultCode ENUMERATED { // success (0), ... // }, 0x04, 0x00, // matchedDN LDAPDN, 0x04, 0x00, // errorMessage LDAPString, // referral [3] Referral OPTIONAL } // } ( byte ) 0xA0, 0x22, // A control 0x30, 0x20, 0x04, 0x17, // EntryChange response control '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 { // add (1), } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyResponse> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyResponse PDU Asn1Decoder.decode( stream, ldapMessageContainer ); // Check the decoded ModifyResponse PDU ModifyResponse modifyResponse = ldapMessageContainer.getMessage(); assertEquals( 1, modifyResponse.getMessageId() ); assertEquals( ResultCodeEnum.SUCCESS, modifyResponse.getLdapResult().getResultCode() ); assertEquals( "", modifyResponse.getLdapResult().getMatchedDn().getName() ); assertEquals( "", modifyResponse.getLdapResult().getDiagnosticMessage() ); // Check the Control Map<String, Control> controls = modifyResponse.getControls(); assertEquals( 1, controls.size() ); Control control = controls.get( "2.16.840.1.113730.3.4.7" ); assertTrue( control instanceof EntryChange); assertEquals( "2.16.840.1.113730.3.4.7", control.getOid() ); // Check encode reverse Asn1Buffer buffer = new Asn1Buffer(); LdapEncoder.encodeMessage( buffer, codec, modifyResponse ); assertArrayEquals( stream.array(), buffer.getBytes().array() ); }
Example #29
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test the decoding of a ModifyResponse */ @Test public void testDecodeModifyResponseSuccess() throws DecoderException, EncoderException { ByteBuffer stream = ByteBuffer.allocate( 0x0E ); stream.put( new byte[] { 0x30, 0x0C, // LDAPMessage ::=SEQUENCE { 0x02, 0x01, 0x01, // messageID MessageID 0x67, 0x07, // CHOICE { ..., modifyResponse ModifyResponse, ... // ModifyResponse ::= [APPLICATION 7] LDAPResult 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE { // resultCode ENUMERATED { // success (0), ... // }, 0x04, 0x00, // matchedDN LDAPDN, 0x04, 0x00 // errorMessage LDAPString, // referral [3] Referral OPTIONAL } // } } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyResponse> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyResponse PDU Asn1Decoder.decode( stream, ldapMessageContainer ); // Check the decoded ModifyResponse PDU ModifyResponse modifyResponse = ldapMessageContainer.getMessage(); assertEquals( 1, modifyResponse.getMessageId() ); assertEquals( ResultCodeEnum.SUCCESS, modifyResponse.getLdapResult().getResultCode() ); assertEquals( "", modifyResponse.getLdapResult().getMatchedDn().getName() ); assertEquals( "", modifyResponse.getLdapResult().getDiagnosticMessage() ); // Check encode reverse Asn1Buffer buffer = new Asn1Buffer(); LdapEncoder.encodeMessage( buffer, codec, modifyResponse ); assertArrayEquals( stream.array(), buffer.getBytes().array() ); }
Example #30
Source File: LdapConnectionWrapper.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public ModifyResponse modify( ModifyRequest modRequest ) throws LdapException { return connection.modify( modRequest ); }