Search in sources :

Example 56 with TLV

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

the class StoreControlCriticality method action.

/**
 * {@inheritDoc}
 */
public void action(ControlsContainer container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    // Get the current control
    Control control = container.getCurrentControl();
    // Store the criticality
    // We get the value. If it's a 0, it's a FALSE. If it's
    // a FF, it's a TRUE. Any other value should be an error,
    // but we could relax this constraint. So if we have
    // something
    // which is not 0, it will be interpreted as TRUE, but we
    // will generate a warning.
    BerValue value = tlv.getValue();
    try {
        control.setCritical(BooleanDecoder.parse(value));
    } catch (BooleanDecoderException bde) {
        LOG.error(I18n.err(I18n.ERR_04100_BAD_CONTROL_CRITICALITY, Strings.dumpBytes(value.getData()), bde.getMessage()));
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(bde.getMessage(), bde);
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("Control criticality : {}", control.isCritical());
    }
}
Also used : BooleanDecoderException(org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) Control(org.apache.directory.api.ldap.model.message.Control) BooleanDecoderException(org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 57 with TLV

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

the class StoreControlValue method action.

/**
 * {@inheritDoc}
 */
@Override
public void action(ControlsContainer container) {
    TLV tlv = container.getCurrentTLV();
    CodecControl<?> control = container.getCurrentControl();
    // Get the current control
    BerValue value = tlv.getValue();
    // Store the value - have to handle the special case of a 0 length value
    if (tlv.getLength() == 0) {
        control.setValue(Strings.EMPTY_BYTES);
    } else {
        control.setValue(value.getData());
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("Control value : {}", Strings.dumpBytes(control.getValue()));
    }
}
Also used : BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 58 with TLV

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

the class SearchRequestDecorator method unstackFilters.

/**
 * This method is used to clear the filter's stack for terminated elements. An element
 * is considered as terminated either if :
 *  - it's a final element (ie an element which cannot contains a Filter)
 *  - its current length equals its expected length.
 *
 * @param container The container being decoded
 */
@SuppressWarnings("unchecked")
public void unstackFilters(Asn1Container container) {
    LdapMessageContainer<MessageDecorator<Message>> ldapMessageContainer = (LdapMessageContainer<MessageDecorator<Message>>) container;
    TLV tlv = ldapMessageContainer.getCurrentTLV();
    TLV localParent = tlv.getParent();
    Filter localFilter = terminalFilter;
    // The parent has been completed, so fold it
    while ((localParent != null) && (localParent.getExpectedLength() == 0)) {
        int parentTlvId = localFilter.getParent() != null ? localFilter.getParent().getTlvId() : localFilter.getParentTlvId();
        if (localParent.getId() != parentTlvId) {
            localParent = localParent.getParent();
        } else {
            Filter filterParent = localFilter.getParent();
            // pushed on the stack, so we need to get its parent's parent
            if (localFilter instanceof PresentFilter) {
                if (filterParent == null) {
                    // We don't have parent, get out
                    break;
                }
                filterParent = filterParent.getParent();
            } else {
                filterParent = filterParent.getParent();
            }
            if (filterParent != null) {
                // The parent is a filter ; it will become the new currentFilter
                // and we will loop again.
                localFilter = currentFilter;
                currentFilter = filterParent;
                localParent = localParent.getParent();
            } else {
                // We can stop the recursion, we have reached the searchResult Object
                break;
            }
        }
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) MessageDecorator(org.apache.directory.api.ldap.codec.api.MessageDecorator) Message(org.apache.directory.api.ldap.model.message.Message) PresentFilter(org.apache.directory.api.ldap.codec.search.PresentFilter) AttributeValueAssertionFilter(org.apache.directory.api.ldap.codec.search.AttributeValueAssertionFilter) AndFilter(org.apache.directory.api.ldap.codec.search.AndFilter) ConnectorFilter(org.apache.directory.api.ldap.codec.search.ConnectorFilter) SubstringFilter(org.apache.directory.api.ldap.codec.search.SubstringFilter) NotFilter(org.apache.directory.api.ldap.codec.search.NotFilter) OrFilter(org.apache.directory.api.ldap.codec.search.OrFilter) PresentFilter(org.apache.directory.api.ldap.codec.search.PresentFilter) ExtensibleMatchFilter(org.apache.directory.api.ldap.codec.search.ExtensibleMatchFilter) Filter(org.apache.directory.api.ldap.codec.search.Filter) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 59 with TLV

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

the class StoreSubstringFilterType method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequestDecorator searchRequestDecorator = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Store the value.
    SubstringFilter substringFilter = (SubstringFilter) searchRequestDecorator.getTerminalFilter();
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04106);
        LOG.error(msg);
        throw new DecoderException(msg);
    } else {
        String type = Strings.utf8ToString(tlv.getValue().getData());
        substringFilter.setType(type);
        // We now have to get back to the nearest filter which
        // is not terminal.
        searchRequestDecorator.setTerminalFilter(substringFilter);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) SubstringFilter(org.apache.directory.api.ldap.codec.search.SubstringFilter) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 60 with TLV

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

the class InitUnbindRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<UnbindRequestDecorator> container) throws DecoderException {
    // Create the UnbindRequest LdapMessage instance and store it in the container
    UnbindRequest unbindRequestInternal = new UnbindRequestImpl();
    unbindRequestInternal.setMessageId(container.getMessageId());
    UnbindRequestDecorator unbindRequest = new UnbindRequestDecorator(container.getLdapCodecService(), unbindRequestInternal);
    container.setMessage(unbindRequest);
    TLV tlv = container.getCurrentTLV();
    int expectedLength = tlv.getLength();
    // The Length should be null
    if (expectedLength != 0) {
        LOG.error(I18n.err(I18n.ERR_04071, Integer.valueOf(expectedLength)));
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(I18n.err(I18n.ERR_04072));
    }
    // We can quit now
    container.setGrammarEndAllowed(true);
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) UnbindRequestImpl(org.apache.directory.api.ldap.model.message.UnbindRequestImpl) UnbindRequestDecorator(org.apache.directory.api.ldap.codec.decorators.UnbindRequestDecorator) UnbindRequest(org.apache.directory.api.ldap.model.message.UnbindRequest) 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