Java Code Examples for org.apache.directory.api.ldap.model.message.BindRequest#getControls()

The following examples show how to use org.apache.directory.api.ldap.model.message.BindRequest#getControls() . 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: AuthRequestTest.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( AuthRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" );

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

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

    assertEquals( 1, abandonRequest.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 2
Source File: AuthRequestTest.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( AuthRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
            .openStream(), "UTF-8" );

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

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

    assertEquals( 1, abandonRequest.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 3
Source File: AuthRequestTest.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(
            AuthRequestTest.class.getResource( "request_with_1_control_empty_value.xml" ).openStream(), "UTF-8" );

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

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

    assertEquals( 1, abandonRequest.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 4
Source File: AuthRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 2 (optional) Control elements
 */
@Test
public void testRequestWith2Controls()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AuthRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(), "UTF-8" );

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

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

    assertEquals( 2, abandonRequest.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 5
Source File: AuthRequestTest.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( AuthRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

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

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

    assertEquals( 3, abandonRequest.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 6
Source File: BindRequestTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a BindRequest with an empty credentials with
 * controls
 */
@Test
public void testDecodeBindRequestEmptyCredentialsWithControls() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x2F );
    stream.put( new byte[]
        {
            0x30, 0x2D,             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,     // messageID MessageID
              0x60, 0x0B,           // CHOICE { ..., bindRequest BindRequest, ...
                0x02, 0x01, 0x03,   // version INTEGER (1..127),
                0x04, 0x00,
                ( byte ) 0xA3, 0x04,
                  0x04, 0x00,
                  0x04, 0x00,
              ( byte ) 0xA0, 0x1B,  // A control
                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<BindRequest> container = new LdapMessageContainer<>( codec );

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

    // Check the decoded BindRequest
    BindRequest bindRequest = container.getMessage();

    assertEquals( 1, bindRequest.getMessageId() );
    assertTrue( bindRequest.isVersion3() );
    assertEquals( "", bindRequest.getName() );
    assertFalse( bindRequest.isSimple() );
    assertEquals( "", bindRequest.getSaslMechanism() );
    assertEquals( "", Strings.utf8ToString( bindRequest.getCredentials() ) );

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

    assertEquals( 1, controls.size() );

    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();

    LdapEncoder.encodeMessage( buffer, codec, bindRequest );
    assertArrayEquals( 
        new byte[]
        {
            0x30, 0x2B,             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,     // messageID MessageID
              0x60, 0x09,           // CHOICE { ..., bindRequest BindRequest, ...
                0x02, 0x01, 0x03,   // version INTEGER (1..127),
                0x04, 0x00,
                ( byte ) 0xA3, 0x02,
                  0x04, 0x00,
              ( byte ) 0xA0, 0x1B,  // A control
                0x30, 0x19,
                  0x04, 0x17,
                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
                    '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
        }, buffer.getBytes().array() );
}
 
Example 7
Source File: BindRequestTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a BindRequest with an empty mechanisms with controls
 */
@Test
public void testDecodeBindRequestEmptyMechanismWithControls() throws EncoderException, DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x2D );
    stream.put( new byte[]
        {
            0x30, 0x2B,             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,     // messageID MessageID
              0x60, 0x09,           // CHOICE { ..., bindRequest BindRequest, ...
                0x02, 0x01, 0x03,   // version INTEGER (1..127),
                0x04, 0x00,
                ( byte ) 0xA3, 0x02,
                  0x04, 0x00,
              ( byte ) 0xA0, 0x1B,  // A control
                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<BindRequest> container = new LdapMessageContainer<>( codec );

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

    // Check the decoded BindRequest
    BindRequest bindRequest = container.getMessage();

    assertEquals( 1, bindRequest.getMessageId() );
    assertTrue( bindRequest.isVersion3() );
    assertEquals( "", bindRequest.getName() );
    assertFalse( bindRequest.isSimple() );
    assertEquals( "", bindRequest.getSaslMechanism() );
    assertEquals( "", Strings.utf8ToString( bindRequest.getCredentials() ) );

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

    assertEquals( 1, controls.size() );

    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();

    LdapEncoder.encodeMessage( buffer, codec, bindRequest );
    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}