Search in sources :

Example 11 with CompareRequest

use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.

the class InitCompareRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<CompareRequestDecorator> container) {
    // Now, we can allocate the CompareRequest Object
    CompareRequest internalCompareRequest = new CompareRequestImpl();
    internalCompareRequest.setMessageId(container.getMessageId());
    CompareRequestDecorator compareRequest = new CompareRequestDecorator(container.getLdapCodecService(), internalCompareRequest);
    container.setMessage(compareRequest);
    LOG.debug("Compare Request");
}
Also used : CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) CompareRequestImpl(org.apache.directory.api.ldap.model.message.CompareRequestImpl) CompareRequestDecorator(org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator)

Example 12 with CompareRequest

use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.

the class StoreCompareRequestAssertionValue method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<CompareRequestDecorator> container) {
    // 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 value
    if (tlv.getLength() == 0) {
        compareRequest.setAssertionValue("");
    } else {
        if (container.isBinary(compareRequest.getAttributeId())) {
            compareRequest.setAssertionValue(tlv.getValue().getData());
            if (IS_DEBUG) {
                LOG.debug("Comparing attribute value {}", Strings.dumpBytes(compareRequest.getAssertionValue().getBytes()));
            }
        } else {
            compareRequest.setAssertionValue(Strings.utf8ToString(tlv.getValue().getData()));
            if (LOG.isDebugEnabled()) {
                LOG.debug("Comparing attribute value {}", compareRequest.getAssertionValue());
            }
        }
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 13 with CompareRequest

use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.

the class StoreCompareRequestAttributeDesc method action.

/**
 * {@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();
    // 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());
    }
}
Also used : CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) CompareResponseImpl(org.apache.directory.api.ldap.model.message.CompareResponseImpl) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 14 with CompareRequest

use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.

the class StoreCompareRequestEntryName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<CompareRequestDecorator> container) throws DecoderException {
    CompareRequest compareRequest = container.getMessage();
    // Get the Value and store it in the CompareRequest
    TLV tlv = container.getCurrentTLV();
    Dn entry;
    // Dn
    if (tlv.getLength() == 0) {
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(I18n.err(I18n.ERR_04089));
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            entry = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            CompareResponseImpl response = new CompareResponseImpl(compareRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
        compareRequest.setName(entry);
    }
    if (IS_DEBUG) {
        LOG.debug("Comparing Dn {}", entry);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) CompareResponseImpl(org.apache.directory.api.ldap.model.message.CompareResponseImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 15 with CompareRequest

use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.

the class LdapNetworkConnection method compare.

/**
 * {@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);
}
Also used : CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) CompareRequestImpl(org.apache.directory.api.ldap.model.message.CompareRequestImpl)

Aggregations

CompareRequest (org.apache.directory.api.ldap.model.message.CompareRequest)26 Test (org.junit.Test)15 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)12 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)12 Control (org.apache.directory.api.ldap.model.message.Control)7 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)5 CompareRequestDecorator (org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator)5 CompareRequestImpl (org.apache.directory.api.ldap.model.message.CompareRequestImpl)5 CompareResponse (org.apache.directory.api.ldap.model.message.CompareResponse)5 DecoderException (org.apache.directory.api.asn1.DecoderException)4 ByteBuffer (java.nio.ByteBuffer)3 EncoderException (org.apache.directory.api.asn1.EncoderException)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)3 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)3 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)3 Dn (org.apache.directory.api.ldap.model.name.Dn)3 BatchRequestDsml (org.apache.directory.api.dsmlv2.request.BatchRequestDsml)2 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)2 AbandonRequest (org.apache.directory.api.ldap.model.message.AbandonRequest)2