Package org.apache.directory.shared.ldap.model.message

Examples of org.apache.directory.shared.ldap.model.message.CompareRequest


            de.printStackTrace();
            fail( de.getMessage() );
        }

        // Ceck the decoded CompareRequest PDU
        CompareRequest compareRequest = container.getMessage();

        assertEquals( 1, compareRequest.getMessageId() );
        assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() );
        assertEquals( "test", compareRequest.getAttributeId() );
        assertEquals( "value", compareRequest.getAssertionValue().toString() );

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

        assertEquals( 1, controls.size() );

        @SuppressWarnings("unchecked")
        CodecControl<Control> control = (org.apache.directory.shared.ldap.codec.api.CodecControl<Control> ) controls.get( "2.16.840.1.113730.3.4.2" );
View Full Code Here


     */
    public Element toDsml( Element root )
    {
        Element element = super.toDsml( root );

        CompareRequest request = ( CompareRequest ) 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;
    }
View Full Code Here

    @Test
    public void testCompareAsync() throws Exception
    {
        Dn dn = new Dn( "uid=admin,ou=system" );

        CompareRequest compareRequest = new CompareRequestImpl();
        compareRequest.setName( dn );
        compareRequest.setAttributeId( SchemaConstants.UID_AT );
        compareRequest.setAssertionValue( "admin" );

        connection.compare( compareRequest );

        assertTrue( session.exists( dn ) );
View Full Code Here

    /**
     * {@inheritDoc}
     */
    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 );
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    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 );
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    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 );
View Full Code Here

    public void testOnReferral() throws Exception
    {
        LdapConnection conn = getWiredConnection( getLdapServer() );

        // comparison success
        CompareRequest compareRequest = new CompareRequestImpl();
        compareRequest.setName( new Dn( "uid=akarasulu,ou=users,ou=system" ) );
        compareRequest.setAttributeId( "uid" );
        compareRequest.setAssertionValue( "akarasulu" );
        ManageDsaIT manageDSAIT = new ManageDsaITImpl();
        manageDSAIT.setCritical( false );
        compareRequest.addControl( manageDSAIT );

        CompareResponse compareResponse = conn.compare( compareRequest );
        assertEquals( ResultCodeEnum.COMPARE_TRUE, compareResponse.getLdapResult().getResultCode() );

        // referrals failure
        compareRequest = new CompareRequestImpl();
        compareRequest.setName( new Dn( "uid=akarasuluREF,ou=users,ou=system" ) );
        compareRequest.setAttributeId( "uid" );
        compareRequest.setAssertionValue( "akarasulu" );

        compareResponse = conn.compare( compareRequest );
        assertEquals( ResultCodeEnum.REFERRAL, compareResponse.getLdapResult().getResultCode() );

        assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
View Full Code Here

        LOG.debug( "" );

        LdapConnection conn = getWiredConnection( getLdapServer() );

        // referrals failure
        CompareRequest compareRequest = new CompareRequestImpl();
        compareRequest.setName( new Dn( "ou=Computers,uid=akarasuluref,ou=users,ou=system" ) );
        compareRequest.setAttributeId( "ou" );
        compareRequest.setAssertionValue( "Computers" );

        CompareResponse compareResponse = conn.compare( compareRequest );
        assertEquals( ResultCodeEnum.REFERRAL, compareResponse.getLdapResult().getResultCode() );

        assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
View Full Code Here

        // comparison success
        assertTrue( conn.compare( "uid=akarasuluref,ou=users,ou=system", "uid", "akarasuluref" ) );

        // comparison failure
        CompareRequest compareRequest = new CompareRequestImpl();
        compareRequest.setName( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
        compareRequest.setAttributeId( "uid" );
        compareRequest.setAssertionValue( "elecharny" );
        ManageDsaIT manageDSAIT = new ManageDsaITImpl();
        manageDSAIT.setCritical( true );
        compareRequest.addControl( manageDSAIT );

        CompareResponse compareResponse = conn.compare( compareRequest );
        assertEquals( ResultCodeEnum.COMPARE_FALSE, compareResponse.getLdapResult().getResultCode() );

        conn.close();
View Full Code Here

     * {@inheritDoc}
     */
    public void action( LdapMessageContainer<CompareRequestDecorator> 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_04093 );
            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 ( IS_DEBUG )
        {
            LOG.debug( "Comparing attribute description {}", compareRequest.getAttributeId() );
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.model.message.CompareRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.