org.apache.directory.api.ldap.model.message.ModifyRequest Java Examples
The following examples show how to use
org.apache.directory.api.ldap.model.message.ModifyRequest.
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 |
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 #2
Source File: InitAttributeVals.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void action( LdapMessageContainer<ModifyRequest> container ) { TLV tlv = container.getCurrentTLV(); // If the length is null, we store an empty value if ( LOG.isDebugEnabled() && ( tlv.getLength() == 0 ) ) { LOG.debug( I18n.msg( I18n.MSG_05129_NO_VALS_FOR_ATTRIBUTE ) ); } // We can have an END transition container.setGrammarEndAllowed( true ); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_05130_SOME_VALS_NEED_DECODING ) ); } }
Example #3
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 #4
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 #5
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 #6
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test the decoding of a ModifyRequest with an empty body */ @Test public void testDecodeModifyRequestEmptyBody() throws DecoderException { ByteBuffer stream = ByteBuffer.allocate( 0x07 ); stream.put( new byte[] { 0x30, 0x05, // LdapMessage 0x02, 0x01, 0x31, // messageID MessageID 0x66, 0x00 // ModifyRequest } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyRequest PDU assertThrows( DecoderException.class, ( ) -> { Asn1Decoder.decode( stream, ldapMessageContainer ); } ); }
Example #7
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test the decoding of a ModifyRequest with an empty object */ @Test public void testDecodeModifyRequestEmptyObject() throws DecoderException { ByteBuffer stream = ByteBuffer.allocate( 0x09 ); stream.put( new byte[] { 0x30, 0x07, // LdapMessage 0x02, 0x01, 0x31, // messageID MessageID 0x66, 0x02, // ModifyRequest 0x04, 0x00 } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyRequest PDU assertThrows( DecoderException.class, ( ) -> { Asn1Decoder.decode( stream, ldapMessageContainer ); } ); }
Example #8
Source File: DefaultCoreSession.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void modify( ModifyRequest modifyRequest, LogChange log ) throws LdapException { ModifyOperationContext modifyContext = new ModifyOperationContext( this, modifyRequest ); modifyContext.setLogChange( log ); OperationManager operationManager = directoryService.getOperationManager(); try { operationManager.modify( modifyContext ); } catch ( LdapException e ) { modifyRequest.getResultResponse().addAllControls( modifyContext.getResponseControls() ); throw e; } modifyRequest.getResultResponse().addAllControls( modifyContext.getResponseControls() ); }
Example #9
Source File: DefaultCoreSession.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void modify( ModifyRequest modifyRequest, LogChange log ) throws LdapException { ModifyOperationContext modifyContext = new ModifyOperationContext( this, modifyRequest ); modifyContext.setLogChange( log ); OperationManager operationManager = directoryService.getOperationManager(); try { operationManager.modify( modifyContext ); } catch ( LdapException e ) { modifyRequest.getResultResponse().addAllControls( modifyContext.getResponseControls() ); throw e; } modifyRequest.getResultResponse().addAllControls( modifyContext.getResponseControls() ); }
Example #10
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test parsing of a request with the (optional) requestID attribute */ @Test public void testRequestWithRequestId() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); assertEquals( 456, modifyRequest.getMessageId() ); }
Example #11
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with operation attribute to Delete value * @throws NamingException */ @Test public void testRequestWithOperationDelete() throws LdapException { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_operation_delete.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Collection<Modification> modifications = modifyRequest.getModifications(); assertEquals( 1, modifications.size() ); Modification modification = modifications.iterator().next(); assertEquals( ModificationOperation.REMOVE_ATTRIBUTE, modification.getOperation() ); }
Example #12
Source File: ModifyRequestDsml.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public ModifyRequest add( Attribute attr ) { getDecorated().add( attr ); return this; }
Example #13
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with operation attribute to Add value * @throws NamingException */ @Test public void testRequestWithOperationAdd() throws LdapException { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_operation_add.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Collection<Modification> modifications = modifyRequest.getModifications(); assertEquals( 1, modifications.size() ); Modification modification = modifications.iterator().next(); assertEquals( ModificationOperation.ADD_ATTRIBUTE, modification.getOperation() ); }
Example #14
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test the decoding of a ModifyRequest with an add operation, and an empty * modification */ @Test public void testDecodeModifyRequestAddOperationEmptyModification() throws DecoderException { ByteBuffer stream = ByteBuffer.allocate( 0x32 ); stream.put( new byte[] { 0x30, 0x30, // LdapMessage 0x02, 0x01, 0x31, // messageID MessageID 0x66, 0x2B, // ModifyRequest 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', 0x30, 0x07, 0x30, 0x05, 0x0A, 0x01, 0x00, 0x30, 0x00 } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyRequest PDU assertThrows( DecoderException.class, ( ) -> { Asn1Decoder.decode( stream, ldapMessageContainer ); } ); }
Example #15
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 #16
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with a Modification element and Increment operation * @throws NamingException */ @Test public void testRequestWith1ModificationIncrement() throws LdapException { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_1_modification_increment.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Collection<Modification> modifications = modifyRequest.getModifications(); assertEquals( 1, modifications.size() ); Modification modification = modifications.iterator().next(); assertEquals( ModificationOperation.INCREMENT_ATTRIBUTE, modification.getOperation() ); Attribute attribute = modification.getAttribute(); assertEquals( "uidnumber", attribute.getId() ); assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get().getString() ); }
Example #17
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with a Modification element * @throws NamingException */ @Test public void testRequestWith1Modification() throws LdapException { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_1_modification.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Collection<Modification> modifications = modifyRequest.getModifications(); assertEquals( 1, modifications.size() ); Modification modification = modifications.iterator().next(); assertEquals( ModificationOperation.ADD_ATTRIBUTE, modification.getOperation() ); Attribute attribute = modification.getAttribute(); assertEquals( "directreport", attribute.getId() ); assertEquals( "CN=John Smith, DC=microsoft, DC=com", attribute.get().getString() ); }
Example #18
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with 3 (optional) Control elements without value */ @Test public void testRequestWith3ControlsWithoutValue() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_3_controls_without_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = modifyRequest.getControls(); assertEquals( 3, modifyRequest.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 #19
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with 2 (optional) Control elements */ @Test public void testRequestWith2Controls() { Dsmlv2Parser parser = null; try { parser = newParser(); parser .setInput( ModifyRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = modifyRequest.getControls(); assertEquals( 2, modifyRequest.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 #20
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with operation attribute to Replace value * @throws NamingException */ @Test public void testRequestWithOperationReplace() throws LdapException { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_operation_replace.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Collection<Modification> modifications = modifyRequest.getModifications(); assertEquals( 1, modifications.size() ); Modification modification = modifications.iterator().next(); assertEquals( ModificationOperation.REPLACE_ATTRIBUTE, modification.getOperation() ); }
Example #21
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with a Modification element without Value element * @throws NamingException */ @Test public void testRequestWithModificationWithoutValue() throws LdapException { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_modification_without_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Collection<Modification> modifications = modifyRequest.getModifications(); assertEquals( 1, modifications.size() ); Modification modification = modifications.iterator().next(); assertEquals( ModificationOperation.ADD_ATTRIBUTE, modification.getOperation() ); Attribute attribute = modification.getAttribute(); assertEquals( "directreport", attribute.getId() ); assertEquals( 0, attribute.size() ); }
Example #22
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test the decoding of a ModifyRequest with an add operation, and nothing * more */ @Test public void testDecodeModifyRequestAddOperationEnd() throws DecoderException { ByteBuffer stream = ByteBuffer.allocate( 0x30 ); stream.put( new byte[] { 0x30, 0x2E, // LdapMessage 0x02, 0x01, 0x31, // messageID MessageID 0x66, 0x29, // ModifyRequest 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', 0x30, 0x05, 0x30, 0x03, 0x0A, 0x01, 0x00 } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyRequest PDU assertThrows( DecoderException.class, ( ) -> { Asn1Decoder.decode( stream, ldapMessageContainer ); } ); }
Example #23
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test the decoding of a ModifyRequest with an wrong operation */ @Test public void testDecodeModifyRequestWrongOperation() throws DecoderException { ByteBuffer stream = ByteBuffer.allocate( 0x30 ); stream.put( new byte[] { 0x30, 0x2E, // LdapMessage 0x02, 0x01, 0x31, // messageID MessageID 0x66, 0x29, // ModifyRequest 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', 0x30, 0x05, 0x30, 0x03, 0x0A, 0x01, 0x04 } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyRequest PDU assertThrows( DecoderException.class, ( ) -> { Asn1Decoder.decode( stream, ldapMessageContainer ); } ); }
Example #24
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test the decoding of a ModifyRequest with an wrong empty operation */ @Test public void testDecodeModifyRequestWrongOperationEmpty() throws DecoderException { ByteBuffer stream = ByteBuffer.allocate( 0x2F ); stream.put( new byte[] { 0x30, 0x2D, // LdapMessage 0x02, 0x01, 0x31, // messageID MessageID 0x66, 0x28, // ModifyRequest 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', 0x30, 0x04, 0x30, 0x02, 0x0A, 0x00 } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyRequest PDU assertThrows( DecoderException.class, ( ) -> { Asn1Decoder.decode( stream, ldapMessageContainer ); } ); }
Example #25
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test the decoding of a ModifyRequest with an empty operation */ @Test public void testDecodeModifyRequestEmptyOperation() throws DecoderException { ByteBuffer stream = ByteBuffer.allocate( 0x2D ); stream.put( new byte[] { 0x30, 0x2B, // LdapMessage 0x02, 0x01, 0x31, // messageID MessageID 0x66, 0x26, // ModifyRequest 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', 0x30, 0x02, 0x30, 0x00 } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyRequest PDU assertThrows( DecoderException.class, ( ) -> { Asn1Decoder.decode( stream, ldapMessageContainer ); } ); }
Example #26
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 #27
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test the decoding of a ModifyRequest with an empty modification */ @Test public void testDecodeModifyRequestEmptyModification() throws DecoderException { ByteBuffer stream = ByteBuffer.allocate( 0x2B ); stream.put( new byte[] { 0x30, 0x29, // LdapMessage 0x02, 0x01, 0x31, // messageID MessageID 0x66, 0x24, // ModifyRequest 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', 0x30, 0x00 } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyRequest PDU assertThrows( DecoderException.class, ( ) -> { Asn1Decoder.decode( stream, ldapMessageContainer ); } ); }
Example #28
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test the decoding of a ModifyRequest with an object and nothing else */ @Test public void testDecodeModifyRequestObjectAlone() throws DecoderException { ByteBuffer stream = ByteBuffer.allocate( 0x29 ); stream.put( new byte[] { 0x30, 0x27, // LdapMessage 0x02, 0x01, 0x31, // messageID MessageID 0x66, 0x22, // ModifyRequest 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', } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyRequest PDU assertThrows( DecoderException.class, ( ) -> { Asn1Decoder.decode( stream, ldapMessageContainer ); } ); }
Example #29
Source File: LdapConnectionTemplate.java From directory-ldap-api with Apache License 2.0 | 5 votes |
private void modifyPassword( final LdapConnection connection, final Dn userDn, final char[] newPassword ) throws PasswordException { passwordPolicyResponder.process( new PasswordPolicyOperation() { @Override public ResultResponse process() throws PasswordException, LdapException { // Can't use Password Modify: // https://issues.apache.org/jira/browse/DIRSERVER-1935 // So revert to regular Modify MemoryClearingBuffer newPasswordBuffer = MemoryClearingBuffer.newInstance( newPassword ); try { ModifyRequest modifyRequest = new ModifyRequestImpl() .setName( userDn ) .replace( "userPassword", newPasswordBuffer.getComputedBytes() ) .addControl( passwordPolicyRequestControl ); return connection.modify( modifyRequest ); } finally { newPasswordBuffer.clear(); } } } ); }
Example #30
Source File: AddModifyRequestAttribute.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void action( LdapMessageContainer<ModifyRequest> container ) throws DecoderException { ModifyRequest modifyRequest = container.getMessage(); TLV tlv = container.getCurrentTLV(); // Store the value. It can't be null String type; if ( tlv.getLength() == 0 ) { String msg = I18n.err( I18n.ERR_05123_TYPE_CANT_BE_NULL ); LOG.error( msg ); ModifyResponseImpl response = new ModifyResponseImpl( modifyRequest.getMessageId() ); throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, modifyRequest.getName(), null ); } else { type = Strings.utf8ToString( tlv.getValue().getData() ); Attribute currentAttribute = new DefaultAttribute( type ); container.setCurrentAttribute( currentAttribute ); container.getCurrentModification().setAttribute( currentAttribute ); } // We can have an END transition if the operation was INCREMENT if ( container.getCurrentModification().getOperation() == ModificationOperation.INCREMENT_ATTRIBUTE ) { container.setGrammarEndAllowed( true ); } if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_05128_MODIFYING_TYPE, type ) ); } }