Java Code Examples for org.apache.directory.api.ldap.model.message.AddRequest#getEntry()

The following examples show how to use org.apache.directory.api.ldap.model.message.AddRequest#getEntry() . 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: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with an Attr elements with value
 */
@Test
public void testRequestWith1AttrWithoutValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_without_value.xml" ).openStream(),
            "UTF-8" );

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

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertFalse( valueIterator.hasNext() );
}
 
Example 2
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with an Attr elements with empty value
 */
@Test
public void testRequestWith1AttrEmptyValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_empty_value.xml" ).openStream(),
            "UTF-8" );

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

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertFalse( valueIterator.hasNext() );
}
 
Example 3
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with an Attr elements with value
 */
@Test
public void testRequestWith1AttrWithValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_value.xml" ).openStream(),
            "UTF-8" );

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

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "top", value.getString() );
}
 
Example 4
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with an Attr elements with value
 */
@Test
public void testRequestWith1AttrWithBase64Value()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_base64_value.xml" )
            .openStream(), "UTF-8" );

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

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertFalse( value.isHumanReadable() );
    assertEquals( "DSMLv2.0 rocks!!", value.getString() );
}
 
Example 5
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 2 Attr elements with value
 */
@Test
public void testRequestWith2AttrWithValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_2_attr_with_value.xml" ).openStream(),
            "UTF-8" );

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

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "top", value.getString() );
    assertTrue( valueIterator.hasNext() );
    value = valueIterator.next();
    assertEquals( "person", value.getString() );
    assertFalse( valueIterator.hasNext() );
}
 
Example 6
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 1 Attr element with 2 Values
 */
@Test
public void testRequestWith1AttrWith2Values()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_2_values.xml" ).openStream(),
            "UTF-8" );

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

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "top", value.getString() );
    assertTrue( valueIterator.hasNext() );
    value = valueIterator.next();
    assertEquals( "person", value.getString() );
    assertFalse( valueIterator.hasNext() );
}
 
Example 7
Source File: AddRequestFactory.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Encode the AddRequest message to a PDU.
 * <br>
 * AddRequest :
 * <pre>
 * 0x68 LL
 *   0x04 LL entry
 *   0x30 LL attributesList
 *     0x30 LL attribute
 *       0x04 LL attributeDescription
 *       0x31 LL attributeValues
 *         0x04 LL attributeValue
 *         ...
 *         0x04 LL attributeValue
 *     ...
 *     0x30 LL attribute
 *       0x04 LL attributeDescription
 *       0x31 LL attributeValue
 *         0x04 LL attributeValue
 *         ...
 *         0x04 LL attributeValue
 * </pre>
 *
 * @param codec The LdapApiService instance
 * @param buffer The buffer where to put the PDU
 * @param message the AbandonRequest to encode
 */
@Override
public void encodeReverse( LdapApiService codec, Asn1Buffer buffer, Message message )
{
    int start = buffer.getPos();
    AddRequest addRequest = ( AddRequest ) message;

    // The partial attribute list
    Entry entry = addRequest.getEntry();

    if ( entry.size() != 0 )
    {
        // Encode the attributes
        encodeAttributeReverse( buffer, entry.iterator() );
    }

    // The attributes sequence
    BerValue.encodeSequence( buffer, start );

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

    // The AddRequest Tag
    BerValue.encodeSequence( buffer, LdapCodecConstants.ADD_REQUEST_TAG, start );
}
 
Example 8
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a AddRequest with a empty attributeList
 */
@Test
public void testDecodeAddRequestEmptyAttributeValue() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x34 );

    stream.put( new byte[]
        {
            0x30, 0x32,                     // LDAPMessage ::= SEQUENCE {
              0x02, 0x01, 0x01,             // messageID MessageID
              0x68, 0x2D,                   // CHOICE { ..., addRequest AddRequest, ...
                                            // AddRequest ::= [APPLICATION 8] SEQUENCE {
                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',
                                            // attributes AttributeList }
                0x30, 0x09,                 // AttributeList ::= SEQUENCE OF SEQUENCE {
                  0x30, 0x07,               // attribute 1
                    0x04, 0x01,
                      'l',                  // type AttributeDescription,
                    0x31, 0x02,
                      0x04, 0x00
        } );

    stream.flip();

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

    // Decode a AddRequest message
    Asn1Decoder.decode( stream, container );

    AddRequest addRequest = container.getMessage();

    // Check the decoded message
    assertEquals( 1, addRequest.getMessageId() );
    assertEquals( "cn=testModify,ou=users,ou=system", addRequest.getEntryDn().toString() );

    Entry entry = addRequest.getEntry();

    assertEquals( 1, entry.size() );

    Attribute attribute = entry.get( "l" );

    assertEquals( "l", Strings.toLowerCaseAscii( attribute.getId() ) );

    for ( Value value : attribute )
    {
        assertEquals( "", value.getString() );
    }

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

    AddRequest request = new AddRequestImpl();
    request.setEntry( addRequest.getEntry() );
    request.setMessageId( addRequest.getMessageId() );

    LdapEncoder.encodeMessage( buffer, codec, request );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example 9
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a AddRequest with a empty attributeList and a
 * control
 */
@Test
public void testDecodeAddRequestEmptyAttributeValueWithControl() throws  DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x51 );

    stream.put( new byte[]
        {
            0x30, 0x4F, // LDAPMessage ::= SEQUENCE {
              0x02, 0x01, 0x01, // messageID MessageID
              0x68, 0x2D, // CHOICE { ..., addRequest AddRequest, ...
                // AddRequest ::= [APPLICATION 8] SEQUENCE {
                // entry LDAPDN,
                0x04, 0x20,
                  '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',
                // attributes AttributeList }
                0x30, 0x09, // AttributeList ::= SEQUENCE OF SEQUENCE {
                  0x30, 0x07, // attribute 1
                    0x04, 0x01,
                      'l', // type AttributeDescription,
                  0x31, 0x02,
                    0x04, 0x00,
                ( byte ) 0xA0, 0x1B, // A control (ManageDsaIT)
                  0x30, 0x19,
                    0x04, 0x17,
                      '2', '.', '1', '6', '.', '8', '4', '0', '.', '1',  '.', '1', '1', '3', '7', '3', '0',
                      '.', '3', '.', '4', '.', '2'
        } );

    stream.flip();

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

    // Decode a AddRequest message
    Asn1Decoder.decode( stream, container );

    AddRequest addRequest = container.getMessage();

    // Check the decoded message
    assertEquals( 1, addRequest.getMessageId() );
    assertEquals( "cn=testModify,ou=users,ou=system", addRequest.getEntryDn().toString() );

    Entry entry = addRequest.getEntry();

    assertEquals( 1, entry.size() );

    Attribute attribute = entry.get( "l" );

    assertEquals( "l", Strings.toLowerCaseAscii( attribute.getId() ) );

    for ( Value value : attribute )
    {
        assertEquals( "", value.getString() );
    }

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

    assertEquals( 1, controls.size() );

    assertTrue( addRequest.hasControl( "2.16.840.1.113730.3.4.2" ) );

    Control control = controls.get( "2.16.840.1.113730.3.4.2" );
    assertTrue( control instanceof ManageDsaIT );
    assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );

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

    AddRequest request = new AddRequestImpl();
    request.setEntry( addRequest.getEntry() );
    request.setMessageId( addRequest.getMessageId() );
    request.addControl( new ManageDsaITImpl() );

    LdapEncoder.encodeMessage( buffer, codec, request );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
    
    // Check encode reverse
    Asn1Buffer asn1Buffer = new Asn1Buffer();

    AddRequest request2 = new AddRequestImpl();
    request2.setEntry( addRequest.getEntry() );
    request2.setMessageId( addRequest.getMessageId() );
    request2.addControl( new ManageDsaITImpl() );

    LdapEncoder.encodeMessage( asn1Buffer, codec, request2 );

    assertArrayEquals( stream.array(), asn1Buffer.getBytes().array() );
}