Search in sources :

Example 61 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.

the class InitAddResponse method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AddResponseDecorator> container) throws DecoderException {
    // Now, we can allocate the AddResponse Object
    AddResponseDecorator addResponse = new AddResponseDecorator(container.getLdapCodecService(), new AddResponseImpl(container.getMessageId()));
    container.setMessage(addResponse);
    // We will check that the request is not null
    TLV tlv = container.getCurrentTLV();
    int expectedLength = tlv.getLength();
    if (expectedLength == 0) {
        String msg = I18n.err(I18n.ERR_04088);
        LOG.error(msg);
        throw new DecoderException(msg);
    }
    LOG.debug("Add Response");
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) AddResponseImpl(org.apache.directory.api.ldap.model.message.AddResponseImpl) AddResponseDecorator(org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 62 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.

the class StoreExtendedResponseName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ExtendedResponseDecorator<?>> container) throws DecoderException {
    // We can allocate the ExtendedResponse Object
    ExtendedResponse extendedResponse;
    // Get the Value and store it in the ExtendedResponse
    TLV tlv = container.getCurrentTLV();
    // OID
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04017);
        LOG.error(msg);
        throw new DecoderException(msg);
    } else {
        String responseName = Oid.fromString(Strings.asciiBytesToString(tlv.getValue().getData())).toString();
        extendedResponse = LdapApiServiceFactory.getSingleton().newExtendedResponse(responseName, container.getMessageId(), null);
        ((ExtendedResponseDecorator<?>) extendedResponse).setLdapResult((LdapResultDecorator) (container.getMessage().getLdapResult()));
        container.setMessage(LdapApiServiceFactory.getSingleton().decorate(extendedResponse));
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("OID read : {}", extendedResponse.getResponseName());
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 63 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.

the class StoreIntermediateResponseName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<IntermediateResponseDecorator<?>> container) throws DecoderException {
    // We can get the IntermediateResponse Object
    IntermediateResponse intermediateResponse = container.getMessage();
    // Get the Value and store it in the IntermediateResponse
    TLV tlv = container.getCurrentTLV();
    // OID.
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04095);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    } else {
        byte[] responseNameBytes = tlv.getValue().getData();
        String oidStr = Strings.utf8ToString(responseNameBytes);
        if (Oid.isOid(oidStr)) {
            Oid.isOid(oidStr);
            intermediateResponse.setResponseName(oidStr);
        } else {
            String msg = "The Intermediate Response name is not a valid OID : " + Strings.utf8ToString(responseNameBytes) + " (" + Strings.dumpBytes(responseNameBytes) + ") is invalid";
            LOG.error("{} : {}", msg, oidStr);
            // Rethrow the exception, we will get a PROTOCOL_ERROR
            throw new DecoderException(msg);
        }
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("OID read : {}", intermediateResponse.getResponseName());
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) IntermediateResponse(org.apache.directory.api.ldap.model.message.IntermediateResponse) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 64 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.

the class StoreSearchResultEntryObjectName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchResultEntryDecorator> container) throws DecoderException {
    SearchResultEntryDecorator searchResultEntry = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    Dn objectName = Dn.EMPTY_DN;
    // Store the value.
    if (tlv.getLength() == 0) {
        searchResultEntry.setObjectName(objectName);
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            objectName = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            // This is for the client side. We will never decode LdapResult on the server
            String msg = "The Dn " + Strings.dumpBytes(dnBytes) + "is invalid : " + ine.getMessage();
            LOG.error("{} : {}", msg, ine.getMessage());
            throw new DecoderException(msg, ine);
        }
        searchResultEntry.setObjectName(objectName);
    }
    if (IS_DEBUG) {
        LOG.debug("Search Result Entry Dn found : {}", searchResultEntry.getObjectName());
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) SearchResultEntryDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator) 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 65 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.

the class StoreReference method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchResultReferenceDecorator> container) throws DecoderException {
    SearchResultReference searchResultReference = container.getMessage();
    // Get the Value and store it in the BindRequest
    TLV tlv = container.getCurrentTLV();
    // Get the referral, or create it if not existing
    Referral referral = searchResultReference.getReferral();
    if (referral == null) {
        referral = new ReferralImpl();
        searchResultReference.setReferral(referral);
    }
    // We have to handle the special case of a 0 length list of referrals
    LdapUrl url = LdapUrl.EMPTY_URL;
    if (tlv.getLength() == 0) {
        referral.addLdapUrl("");
    } else {
        String urlStr = Strings.utf8ToString(tlv.getValue().getData());
        try {
            url = new LdapUrl(urlStr);
            referral.addLdapUrl(urlStr);
        } catch (LdapURLEncodingException luee) {
            LOG.error(I18n.err(I18n.ERR_04021, urlStr, luee.getMessage()));
            throw new DecoderException(I18n.err(I18n.ERR_04016, luee.getMessage()), luee);
        }
    }
    if (IS_DEBUG) {
        LOG.debug("Search reference URL found : {}", url);
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) DecoderException(org.apache.directory.api.asn1.DecoderException) Referral(org.apache.directory.api.ldap.model.message.Referral) ReferralImpl(org.apache.directory.api.ldap.model.message.ReferralImpl) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Aggregations

TLV (org.apache.directory.api.asn1.ber.tlv.TLV)92 DecoderException (org.apache.directory.api.asn1.DecoderException)54 BerValue (org.apache.directory.api.asn1.ber.tlv.BerValue)19 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)17 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)12 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)10 Dn (org.apache.directory.api.ldap.model.name.Dn)10 IntegerDecoderException (org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)9 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)7 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)6 BooleanDecoderException (org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException)5 Filter (org.apache.directory.api.ldap.codec.search.Filter)5 SubstringFilter (org.apache.directory.api.ldap.codec.search.SubstringFilter)5 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)5 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)5 ResultResponse (org.apache.directory.api.ldap.model.message.ResultResponse)5 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)4 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)4 AddRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator)4 ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)4