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

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

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

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

    assertEquals( 1, searchRequest.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: SearchRequestTest.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( SearchRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
            .openStream(), "UTF-8" );

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

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

    assertEquals( 1, searchRequest.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: SearchRequestTest.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( SearchRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
            .openStream(), "UTF-8" );

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

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

    assertEquals( 1, searchRequest.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: SearchRequestTest.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( SearchRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(), "UTF-8" );

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

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

    assertEquals( 2, searchRequest.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: SearchRequestTest.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( SearchRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

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

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

    assertEquals( 3, searchRequest.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: SearchRequestHandler.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Handles a simple lookup, or a RootDSE lookup.
 *
 * @param session the LdapSession for which this search is conducted
 * @param req the search request on the RootDSE
 * @throws Exception if failures are encountered while searching
 */
private void handleLookup( LdapSession session, SearchRequest req ) throws Exception
{
    try
    {
        Map<String, Control> controlMap = req.getControls();
        Control[] controls = null;

        if ( controlMap != null )
        {
            Collection<Control> controlValues = controlMap.values();

            controls = new Control[controlValues.size()];
            int pos = 0;

            for ( Control control : controlMap.values() )
            {
                controls[pos++] = control;
            }
        }

        Entry entry = session.getCoreSession().lookup(
            req.getBase(),
            controls,
            req.getAttributes().toArray( new String[]
                {} ) );

        session.getIoSession().write( generateResponse( session, req, entry ) );

        // write the SearchResultDone message
        session.getIoSession().write( req.getResultResponse() );
    }
    finally
    {
    }
}
 
Example 7
Source File: SearchRequestHandler.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Handles a simple lookup, or a RootDSE lookup.
 *
 * @param session the LdapSession for which this search is conducted
 * @param req the search request on the RootDSE
 * @throws Exception if failures are encountered while searching
 */
private void handleLookup( LdapSession session, SearchRequest req ) throws Exception
{
    try
    {
        Map<String, Control> controlMap = req.getControls();
        Control[] controls = null;

        if ( controlMap != null )
        {
            Collection<Control> controlValues = controlMap.values();

            controls = new Control[controlValues.size()];
            int pos = 0;

            for ( Control control : controlMap.values() )
            {
                controls[pos++] = control;
            }
        }

        Entry entry = session.getCoreSession().lookup(
            req.getBase(),
            controls,
            req.getAttributes().toArray( new String[]
                {} ) );

        session.getIoSession().write( generateResponse( session, req, entry ) );

        // write the SearchResultDone message
        session.getIoSession().write( req.getResultResponse() );
    }
    finally
    {
    }
}