org.apache.directory.api.ldap.model.message.CompareRequest Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.message.CompareRequest. 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: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * This method uses the compare ldap func to assert audit record into the directory server's configured audit
 * logger.
 *
 * This is for one reason - to force the ldap server to maintain an audit trail on checkAccess api.
 *
 * Use proxy authz control (RFC4370) to assert the caller's id onto the record.
 *
 * @param connection is LdapConnection object used for all communication with host.
 * @param dn         contains address of distinguished name to begin ldap search
 * @param userDn     dn for user node
 * @param attribute  attribute used for compare
 * @return true if compare operation succeeds
 * @throws LdapException                thrown in the event of error in ldap client or server code.
 * @throws UnsupportedEncodingException in the event the server cannot perform the operation.
 */
protected boolean compareNode( LdapConnection connection, String dn, String userDn,
    Attribute attribute ) throws LdapException, UnsupportedEncodingException
{
    COUNTERS.incrementCompare();

    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( new Dn( dn ) );
    compareRequest.setAttributeId( attribute.getId() );
    compareRequest.setAssertionValue( attribute.getString() );

    // Assert the end user's dn onto the reqest using proxy authZ control so openldap can log who the user was (for authZ audit trail)
    ProxiedAuthz proxiedAuthzControl = new ProxiedAuthzImpl();
    proxiedAuthzControl.setAuthzId( "dn: " + userDn );
    compareRequest.addControl( proxiedAuthzControl );
    CompareResponse response = connection.compare( compareRequest );
    return response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS;
}
 
Example #2
Source File: CompareRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with the (optional) requestID attribute
 */
@Test
public void testRequestWithRequestId()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( CompareRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
            .openStream(), "UTF-8" );

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

    CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();

    assertEquals( 456, compareRequest.getMessageId() );
}
 
Example #3
Source File: CompareRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a request with the dn attribute
 */
@Test
public void testRequestWithDn()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( CompareRequestTest.class.getResource( "request_with_dn_attribute.xml" ).openStream(),
            "UTF-8" );

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

    CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();

    assertTrue( compareRequest.getName().equals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM" ) );
}
 
Example #4
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( Dn dn, String attributeName, Value value ) throws LdapException
{
    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( dn );
    compareRequest.setAttributeId( attributeName );

    if ( value.isHumanReadable() )
    {
        compareRequest.setAssertionValue( value.getString() );
    }
    else
    {
        compareRequest.setAssertionValue( value.getBytes() );
    }

    CompareResponse compareResponse = compare( compareRequest );

    return processResponse( compareResponse );
}
 
Example #5
Source File: CompareRequestFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Encode the CompareRequest message to a PDU.
 * <br>
 * <pre>
 * CompareRequest :
 *   0x6E LL
 *     0x04 LL entry
 *     0x30 LL attributeValueAssertion
 *       0x04 LL attributeDesc
 *       0x04 LL assertionValue
 * </pre>
 *
 * @param codec The LdapApiService instance
 * @param buffer The buffer where to put the PDU
 * @param message the CompareRequest to encode
 */
@Override
public void encodeReverse( LdapApiService codec, Asn1Buffer buffer, Message message )
{
    int pos = buffer.getPos();
    CompareRequest compareMessage = ( CompareRequest ) message;

    // The assertionValue
    BerValue.encodeOctetString( buffer, compareMessage.getAssertionValue().getBytes() );

    // The attributeDesc
    BerValue.encodeOctetString( buffer, compareMessage.getAttributeId() );

    // The attributeValueAssertion sequence Tag
    BerValue.encodeSequence( buffer, pos );

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

    // The CompareRequest Tag
    BerValue.encodeSequence( buffer, LdapCodecConstants.COMPARE_REQUEST_TAG, pos );
}
 
Example #6
Source File: Dsmlv2Grammar.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( Dsmlv2Container container ) throws XmlPullParserException
{
    CompareRequest compareRequest = ( CompareRequest ) container.getBatchRequest().getCurrentRequest();

    XmlPullParser xpp = container.getParser();

    // Checking and adding the request's attributes
    String attributeId;

    // name
    attributeId = xpp.getAttributeValue( "", NAME );

    if ( attributeId != null )
    {
        compareRequest.setAttributeId( attributeId );
    }
    else
    {
        throw new XmlPullParserException( I18n.err( I18n.ERR_03002_NAME_ATTRIBUTE_REQUIRED ), xpp, null );
    }
}
 
Example #7
Source File: CompareRequestTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of an empty CompareRequest
 */
@Test
public void testDecodeCompareRequestEmptyRequest() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x07 );

    stream.put( new byte[]
        {
            0x30, 0x05,             // LDAPMessage ::= SEQUENCE {
              0x02, 0x01, 0x01,     // messageID MessageID
                                    // CHOICE { ..., compareRequest CompareRequest, ...
              0x6E, 0x00            // CompareRequest ::= [APPLICATION 14] SEQUENCE {
    } );

    stream.flip();

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

    // Decode the CompareRequest PDU
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #8
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean compare( CompareRequest compareRequest ) throws LdapException
{
    CompareOperationContext compareContext = new CompareOperationContext( this, compareRequest );
    OperationManager operationManager = directoryService.getOperationManager();
    boolean result = false;
    try
    {
        result = operationManager.compare( compareContext );
    }
    catch ( LdapException e )
    {
        compareRequest.getResultResponse().addAllControls( compareContext.getResponseControls() );
        throw e;
    }

    compareRequest.getResultResponse().addAllControls( compareContext.getResponseControls() );
    return result;
}
 
Example #9
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean compare( CompareRequest compareRequest ) throws LdapException
{
    CompareOperationContext compareContext = new CompareOperationContext( this, compareRequest );
    OperationManager operationManager = directoryService.getOperationManager();
    boolean result = false;
    try
    {
        result = operationManager.compare( compareContext );
    }
    catch ( LdapException e )
    {
        compareRequest.getResultResponse().addAllControls( compareContext.getResponseControls() );
        throw e;
    }

    compareRequest.getResultResponse().addAllControls( compareContext.getResponseControls() );
    return result;
}
 
Example #10
Source File: CompareRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test the decoding of an empty entry CompareRequest
 */
@Test
public void testDecodeCompareRequestEmptyEntry() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x18 );

    stream.put( new byte[]
        {
            0x30, 0x16,                 // LDAPMessage ::= SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
                                        // CHOICE { ..., compareRequest CompareRequest, ...
              0x6E, 0x11,               // CompareRequest ::= [APPLICATION 14] SEQUENCE {
                0x04, 0x00,             // entry LDAPDN,
                                        // ava AttributeValueAssertion }
                0x30, 0x0D,             // AttributeValueAssertion ::= SEQUENCE {
                  0x04, 0x04,           // attributeDesc AttributeDescription,
                    't', 'e', 's', 't',
                  0x04, 0x05,           // assertionValue AssertionValue }
                    'v', 'a', 'l', 'u', 'e'
        } );

    stream.flip();

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

    // Decode the CompareRequest PDU
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #11
Source File: CompareRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test the decoding of an empty ava
 */
@Test
public void testDecodeCompareRequestEmptyAVA() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x2B );

    stream.put( new byte[]
        {
            0x30, 0x29,                 // LDAPMessage ::= SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
                                        // CHOICE { ..., compareRequest CompareRequest, ...
              0x6E, 0x24,               // CompareRequest ::= [APPLICATION 14] 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',
                                        // ava AttributeValueAssertion }
                0x30, 0x00              // AttributeValueAssertion ::= SEQUENCE {
    } );

    stream.flip();

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

    // Decode the CompareRequest PDU
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #12
Source File: StoreCompareRequestAttributeDesc.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<CompareRequest> container ) throws DecoderException
{
    // Get the CompareRequest Object
    CompareRequest compareRequest = container.getMessage();

    // Get the Value and store it in the CompareRequest
    TLV tlv = container.getCurrentTLV();

    // We have to handle the special case of a 0 length matched
    // Dn
    if ( tlv.getLength() == 0 )
    {
        String msg = I18n.err( I18n.ERR_05118_NULL_ATTRIBUTE_DESC );
        LOG.error( msg );
        CompareResponseImpl response = new CompareResponseImpl( compareRequest.getMessageId() );

        throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
            compareRequest.getName(), null );
    }

    String type = Strings.utf8ToString( tlv.getValue().getData() );
    compareRequest.setAttributeId( type );

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05122_COMPARING_ATTRIBUTE_DESCRIPTION, compareRequest.getAttributeId() ) );
    }
}
 
Example #13
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Inject the MessageReceived and MessageSent handler into the IoHandler
 * 
 * @param compareRequestHandler The CompareRequest message received handler
 * @param compareResponseHandler The CompareResponse message sent handler
 */
public void setCompareHandlers( LdapRequestHandler<CompareRequest> compareRequestHandler,
    LdapResponseHandler<CompareResponse> compareResponseHandler )
{
    handler.removeReceivedMessageHandler( CompareRequest.class );
    this.compareRequestHandler = compareRequestHandler;
    this.compareRequestHandler.setLdapServer( this );
    this.handler.addReceivedMessageHandler( CompareRequest.class, this.compareRequestHandler );

    handler.removeReceivedMessageHandler( CompareResponse.class );
    this.compareResponseHandler = compareResponseHandler;
    this.compareResponseHandler.setLdapServer( this );
    this.handler.addSentMessageHandler( CompareResponse.class, this.compareResponseHandler );
}
 
Example #14
Source File: InitCompareRequest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<CompareRequest> container )
{
    // Now, we can allocate the CompareRequest Object
    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setMessageId( container.getMessageId() );
    container.setMessage( compareRequest );

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05120_COMPARE_REQUEST ) );
    }
}
 
Example #15
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Inject the MessageReceived and MessageSent handler into the IoHandler
 * 
 * @param compareRequestHandler The CompareRequest message received handler
 * @param compareResponseHandler The CompareResponse message sent handler
 */
public void setCompareHandlers( LdapRequestHandler<CompareRequest> compareRequestHandler,
    LdapResponseHandler<CompareResponse> compareResponseHandler )
{
    handler.removeReceivedMessageHandler( CompareRequest.class );
    this.compareRequestHandler = compareRequestHandler;
    this.compareRequestHandler.setLdapServer( this );
    this.handler.addReceivedMessageHandler( CompareRequest.class, this.compareRequestHandler );

    handler.removeReceivedMessageHandler( CompareResponse.class );
    this.compareResponseHandler = compareResponseHandler;
    this.compareResponseHandler.setLdapServer( this );
    this.handler.addSentMessageHandler( CompareResponse.class, this.compareResponseHandler );
}
 
Example #16
Source File: CompareRequestDsml.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Element toDsml( Element root )
{
    Element element = super.toDsml( root );

    CompareRequest request = getDecorated();

    // Dn
    if ( request.getName() != null )
    {
        element.addAttribute( "dn", request.getName().getName() );
    }

    // Assertion
    Element assertionElement = element.addElement( "assertion" );
    if ( request.getAttributeId() != null )
    {
        assertionElement.addAttribute( "name", request.getAttributeId() );
    }
    if ( request.getAssertionValue() != null )
    {
        assertionElement.addElement( "value" ).setText( request.getAssertionValue().getString() );
    }

    return element;
}
 
Example #17
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( Dn dn, String attributeName, byte[] value ) throws LdapException
{
    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( dn );
    compareRequest.setAttributeId( attributeName );
    compareRequest.setAssertionValue( value );

    CompareResponse compareResponse = compare( compareRequest );

    return processResponse( compareResponse );
}
 
Example #18
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( Dn dn, String attributeName, String value ) throws LdapException
{
    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( dn );
    compareRequest.setAttributeId( attributeName );
    compareRequest.setAssertionValue( value );

    CompareResponse compareResponse = compare( compareRequest );

    return processResponse( compareResponse );
}
 
Example #19
Source File: CompareRequestTest.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 testRequestWith1AssertionEmptyValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( CompareRequestTest.class.getResource( "request_with_1_assertion_empty_value.xml" )
            .openStream(), "UTF-8" );

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

    CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();

    assertTrue( compareRequest.getName().equals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM" ) );

    assertEquals( "sn", compareRequest.getAttributeId() );

    assertNull( compareRequest.getAssertionValue() );
}
 
Example #20
Source File: CompareRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with a complete assertion with base64 value
 */
@Test
public void testRequestWith1CompleteAssertionBase64Value()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( CompareRequestTest.class
            .getResource( "request_with_1_complete_assertion_base64_value.xml" ).openStream(), "UTF-8" );

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

    CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();

    assertTrue( compareRequest.getName().equals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM" ) );

    assertEquals( "sn", compareRequest.getAttributeId() );

    assertEquals( "DSMLv2.0 rocks!!", compareRequest.getAssertionValue().getString() );
}
 
Example #21
Source File: CompareRequestTest.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 testRequestWith1CompleteAssertion()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( CompareRequestTest.class.getResource( "request_with_1_complete_assertion.xml" )
            .openStream(), "UTF-8" );

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

    CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();

    assertTrue( compareRequest.getName().equals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM" ) );

    assertEquals( "sn", compareRequest.getAttributeId() );

    assertEquals( "Johnson", compareRequest.getAssertionValue().getString() );
}
 
Example #22
Source File: CompareRequestDsml.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public CompareRequest setAssertionValue( byte[] value )
{
    getDecorated().setAssertionValue( value );

    return this;
}
 
Example #23
Source File: CompareRequestDsml.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public CompareRequest setMessageId( int messageId )
{
    super.setMessageId( messageId );

    return this;
}
 
Example #24
Source File: CompareRequestTest.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( CompareRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

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

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

    assertEquals( 3, compareRequest.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 #25
Source File: Dsmlv2Grammar.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( Dsmlv2Container container ) throws XmlPullParserException
{
    CompareRequest compareRequest = ( CompareRequest ) container.getBatchRequest().getCurrentRequest();

    XmlPullParser xpp = container.getParser();

    try
    {
        // We have to catch the type Attribute Value before going to the next Text node
        String typeValue = ParserUtils.getXsiTypeAttributeValue( xpp );

        // Getting the value
        String nextText = xpp.nextText();

        if ( !Strings.isEmpty( nextText ) )
        {
            if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
            {
                compareRequest.setAssertionValue( Base64.decode( nextText.trim().toCharArray() ) );
            }
            else
            {
                compareRequest.setAssertionValue( nextText.trim() );
            }
        }
    }
    catch ( IOException ioe )
    {
        throw new XmlPullParserException( I18n.err( I18n.ERR_03008_UNEXPECTED_ERROR, ioe.getMessage() ), xpp, ioe );
    }
}
 
Example #26
Source File: CompareRequestDsml.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public CompareRequest setAttributeId( String attrId )
{
    getDecorated().setAttributeId( attrId );

    return this;
}
 
Example #27
Source File: BatchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a Request with 1 CompareRequest
 */
@Test
public void testResponseWith1CompareRequest()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( BatchRequestTest.class.getResource( "request_with_1_CompareRequest.xml" ).openStream(),
            "UTF-8" );

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

    BatchRequestDsml batchRequest = parser.getBatchRequest();

    assertEquals( 1, batchRequest.getRequests().size() );

    if ( batchRequest.getCurrentRequest() instanceof CompareRequest )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #28
Source File: BatchRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a Request with 2 CompareRequest
 */
@Test
public void testResponseWith2CompareRequest()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( BatchRequestTest.class.getResource( "request_with_2_CompareRequest.xml" ).openStream(),
            "UTF-8" );

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

    BatchRequestDsml batchRequest = parser.getBatchRequest();

    assertEquals( 2, batchRequest.getRequests().size() );

    if ( batchRequest.getCurrentRequest() instanceof CompareRequest )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #29
Source File: CompareRequestTest.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( CompareRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" );

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

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

    assertEquals( 1, compareRequest.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 #30
Source File: CompareRequestTest.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( CompareRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" );

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

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

    assertEquals( 1, compareRequest.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() ) );
}