Search in sources :

Example 86 with TLV

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

the class StoreMessageId method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    // The current TLV should be a integer
    // We get it and store it in MessageId
    TLV tlv = container.getCurrentTLV();
    // The Length should not be null
    if (tlv.getLength() == 0) {
        LOG.error(I18n.err(I18n.ERR_04068));
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(I18n.err(I18n.ERR_04069));
    }
    BerValue value = tlv.getValue();
    try {
        int messageId = IntegerDecoder.parse(value, 0, Integer.MAX_VALUE);
        container.setMessageId(messageId);
        if (IS_DEBUG) {
            LOG.debug("Ldap Message Id has been decoded : " + messageId);
        }
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_04070, Strings.dumpBytes(value.getData()), ide.getLocalizedMessage()));
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(ide.getMessage(), ide);
    }
}
Also used : IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 87 with TLV

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

the class AddReferral method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    Message response = container.getMessage();
    LdapResult ldapResult = ((ResultResponse) response).getLdapResult();
    Referral referral = ldapResult.getReferral();
    if (tlv.getLength() == 0) {
        referral.addLdapUrl("");
    } else {
        if (ldapResult.getResultCode() == ResultCodeEnum.REFERRAL) {
            try {
                String url = Strings.utf8ToString(tlv.getValue().getData());
                referral.addLdapUrl(new LdapUrl(url).toString());
            } catch (LdapURLEncodingException luee) {
                String badUrl = Strings.utf8ToString(tlv.getValue().getData());
                LOG.error(I18n.err(I18n.ERR_04015, badUrl, luee.getMessage()));
                throw new DecoderException(I18n.err(I18n.ERR_04016, luee.getMessage()), luee);
            }
        } else {
            LOG.warn("The Referral error message is not allowed when havind an error code no equals to REFERRAL");
            referral.addLdapUrl(LdapUrl.EMPTY_URL.toString());
        }
    }
    if (IS_DEBUG) {
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        for (String url : ldapResult.getReferral().getLdapUrls()) {
            if (isFirst) {
                isFirst = false;
            } else {
                sb.append(", ");
            }
            sb.append(url);
        }
        LOG.debug("The referral error message is set to " + sb.toString());
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : ResultResponse(org.apache.directory.api.ldap.model.message.ResultResponse) 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) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) Message(org.apache.directory.api.ldap.model.message.Message) Referral(org.apache.directory.api.ldap.model.message.Referral) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 88 with TLV

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

the class StoreTypeMatchingRule method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequestDecorator searchRequest = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04022);
        LOG.error(msg);
        throw new DecoderException(msg);
    } else {
        // Store the value.
        ExtensibleMatchFilter extensibleMatchFilter = (ExtensibleMatchFilter) searchRequest.getTerminalFilter();
        String type = Strings.utf8ToString(tlv.getValue().getData());
        extensibleMatchFilter.setType(type);
        if (IS_DEBUG) {
            LOG.debug("Stored a type matching rule : {}", type);
        }
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) ExtensibleMatchFilter(org.apache.directory.api.ldap.codec.search.ExtensibleMatchFilter) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 89 with TLV

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

the class ApiAsn1BerOsgiTest method useBundleClasses.

@Override
protected void useBundleClasses() throws Exception {
    new CheckNotNullLength<Asn1Container>();
    new Asn1Decoder().getMaxLengthLength();
    new BerValue().init(5);
    new TLV(1).getValue();
}
Also used : CheckNotNullLength(org.apache.directory.api.asn1.actions.CheckNotNullLength) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 90 with TLV

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

the class StoreAssertionValue method action.

/**
 * {@inheritDoc}
 */
@Override
public void action(VirtualListViewRequestContainer vlvContainer) {
    TLV tlv = vlvContainer.getCurrentTLV();
    if (tlv.getLength() != 0) {
        byte[] assertionValue = tlv.getValue().getData();
        vlvContainer.getDecorator().setAssertionValue(assertionValue);
    } else {
        vlvContainer.getDecorator().setAssertionValue(Strings.EMPTY_BYTES);
    }
    // The last element is optional, we can quit here
    vlvContainer.setGrammarEndAllowed(true);
}
Also used : 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