Search in sources :

Example 16 with BerValue

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

the class StoreSearchRequestScope method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequest searchRequest = container.getMessage().getDecorated();
    TLV tlv = container.getCurrentTLV();
    // We have to check that this is a correct scope
    BerValue value = tlv.getValue();
    int scope = 0;
    try {
        scope = IntegerDecoder.parse(value, LdapCodecConstants.SCOPE_BASE_OBJECT, LdapCodecConstants.SCOPE_WHOLE_SUBTREE);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04101, value.toString());
        LOG.error(msg);
        throw new DecoderException(msg, ide);
    }
    searchRequest.setScope(SearchScope.getSearchScope(scope));
    if (IS_DEBUG) {
        switch(scope) {
            case LdapCodecConstants.SCOPE_BASE_OBJECT:
                LOG.debug("Searching within BASE_OBJECT scope ");
                break;
            case LdapCodecConstants.SCOPE_SINGLE_LEVEL:
                LOG.debug("Searching within SINGLE_LEVEL scope ");
                break;
            case LdapCodecConstants.SCOPE_WHOLE_SUBTREE:
                LOG.debug("Searching within WHOLE_SUBTREE scope ");
                break;
            default:
                LOG.debug("Searching within UNKNOWN scope ");
        }
    }
}
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 17 with BerValue

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

the class StoreResultCode 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();
    BerValue value = tlv.getValue();
    ResultCodeEnum resultCode = ResultCodeEnum.SUCCESS;
    try {
        resultCode = ResultCodeEnum.getResultCode(IntegerDecoder.parse(value, 0, ResultCodeEnum.E_SYNC_REFRESH_REQUIRED.getResultCode()));
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_04018, Strings.dumpBytes(value.getData()), ide.getMessage()));
        throw new DecoderException(ide.getMessage(), ide);
    }
    if (IS_DEBUG) {
        LOG.debug("The result code is set to " + resultCode);
    }
    ResultResponse response = (ResultResponse) container.getMessage();
    LdapResult ldapResult = response.getLdapResult();
    ldapResult.setResultCode(resultCode);
}
Also used : ResultResponse(org.apache.directory.api.ldap.model.message.ResultResponse) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) 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) ResultCodeEnum(org.apache.directory.api.ldap.model.message.ResultCodeEnum)

Example 18 with BerValue

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

the class StoreMatchingRuleDnAttributes method action.

public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequestDecorator searchRequest = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Store the value.
    ExtensibleMatchFilter extensibleMatchFilter = (ExtensibleMatchFilter) searchRequest.getTerminalFilter();
    // 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 {
        extensibleMatchFilter.setDnAttributes(BooleanDecoder.parse(value));
    } catch (BooleanDecoderException bde) {
        LOG.error(I18n.err(I18n.ERR_04110, Strings.dumpBytes(value.getData()), bde.getMessage()));
        throw new DecoderException(bde.getMessage(), bde);
    }
    if (IS_DEBUG) {
        LOG.debug("Dn Attributes : {}", Boolean.valueOf(extensibleMatchFilter.isDnAttributes()));
    }
    // unstack the filters if needed
    searchRequest.unstackFilters(container);
}
Also used : 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) 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 19 with BerValue

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

the class StoreControlCriticality method action.

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

use of org.apache.directory.api.asn1.ber.tlv.BerValue 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)

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