Search in sources :

Example 6 with BerValue

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

the class StoreVersion method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
    BindRequest bindRequestMessage = container.getMessage();
    // The current TLV should be a integer between 1 and 127
    // We get it and store it in Version
    TLV tlv = container.getCurrentTLV();
    BerValue value = tlv.getValue();
    try {
        int version = IntegerDecoder.parse(value, 1, 127);
        if (IS_DEBUG) {
            LOG.debug("Ldap version ", Integer.valueOf(version));
        }
        bindRequestMessage.setVersion3(version == 3);
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_04078, Strings.dumpBytes(value.getData()), ide.getMessage()));
        // 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) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 7 with BerValue

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

the class StoreControlValue method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    MessageDecorator<?> message = container.getMessage();
    CodecControl<? extends Control> control = message.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());
        control.decode(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 8 with BerValue

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

the class StoreSearchRequestSizeLimit method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequest searchRequest = container.getMessage().getDecorated();
    TLV tlv = container.getCurrentTLV();
    // The current TLV should be a integer
    // We get it and store it in sizeLimit
    BerValue value = tlv.getValue();
    long sizeLimit = 0;
    try {
        sizeLimit = LongDecoder.parse(value, 0, Integer.MAX_VALUE);
    } catch (LongDecoderException lde) {
        String msg = I18n.err(I18n.ERR_04103, value.toString());
        LOG.error(msg);
        throw new DecoderException(msg, lde);
    }
    searchRequest.setSizeLimit(sizeLimit);
    if (IS_DEBUG) {
        LOG.debug("The sizeLimit value is set to {} objects", Long.valueOf(sizeLimit));
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) LongDecoderException(org.apache.directory.api.asn1.ber.tlv.LongDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) LongDecoderException(org.apache.directory.api.asn1.ber.tlv.LongDecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 9 with BerValue

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

the class StoreSearchRequestTimeLimit method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequest searchRequest = container.getMessage().getDecorated();
    TLV tlv = container.getCurrentTLV();
    // The current TLV should be a integer
    // We get it and store it in timeLimit
    BerValue value = tlv.getValue();
    int timeLimit = 0;
    try {
        timeLimit = IntegerDecoder.parse(value, 0, Integer.MAX_VALUE);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04104, value.toString());
        LOG.error(msg);
        throw new DecoderException(msg, ide);
    }
    searchRequest.setTimeLimit(timeLimit);
    if (IS_DEBUG) {
        LOG.debug("The timeLimit value is set to {} seconds", Integer.valueOf(timeLimit));
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) 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 10 with BerValue

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

the class StoreSearchRequestTypesOnly method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequest searchRequest = container.getMessage().getDecorated();
    TLV tlv = container.getCurrentTLV();
    // 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 {
        searchRequest.setTypesOnly(BooleanDecoder.parse(value));
    } catch (BooleanDecoderException bde) {
        LOG.error(I18n.err(I18n.ERR_04105, Strings.dumpBytes(value.getData()), bde.getMessage()));
        throw new DecoderException(bde.getMessage(), bde);
    }
    if (IS_DEBUG) {
        LOG.debug("The search will return {}", searchRequest.getTypesOnly() ? "only attributs type" : "attributes types and values");
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) BooleanDecoderException(org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) 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)

Aggregations

BerValue (org.apache.directory.api.asn1.ber.tlv.BerValue)22 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)19 DecoderException (org.apache.directory.api.asn1.DecoderException)18 IntegerDecoderException (org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)11 BooleanDecoderException (org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException)5 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)5 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 ByteBuffer (java.nio.ByteBuffer)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 StoredProcedureContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureContainer)2 StoredProcedureDecoder (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureDecoder)2 StoredProcedureRequestDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureRequestDecorator)2 Control (org.apache.directory.api.ldap.model.message.Control)2 Test (org.junit.Test)2 NamingException (javax.naming.NamingException)1 CheckNotNullLength (org.apache.directory.api.asn1.actions.CheckNotNullLength)1 LongDecoderException (org.apache.directory.api.asn1.ber.tlv.LongDecoderException)1 ExtendedOperationFactory (org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory)1 AbandonRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator)1 ExtendedRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator)1