Search in sources :

Example 76 with TLV

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

the class StoreSearchRequestAttributeDesc method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequestDecorator searchRequestDecorator = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    String attributeDescription = null;
    if (tlv.getLength() != 0) {
        attributeDescription = Strings.utf8ToString(tlv.getValue().getData());
        // If the attributeDescription is empty, we won't add it
        if (!Strings.isEmpty(attributeDescription.trim())) {
            searchRequestDecorator.getDecorated().addAttributes(attributeDescription);
        }
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("Decoded Attribute Description : {}", attributeDescription);
    }
}
Also used : SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 77 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV 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 78 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV 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 79 with TLV

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

the class AddAttributeValue method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AddRequestDecorator> container) {
    AddRequestDecorator addRequest = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Store the value. It can't be null
    Object value = null;
    try {
        if (tlv.getLength() == 0) {
            addRequest.addAttributeValue("");
        } else {
            if (container.isBinary(addRequest.getCurrentAttributeType())) {
                value = tlv.getValue().getData();
                if (IS_DEBUG) {
                    LOG.debug("Adding value {}", Strings.dumpBytes((byte[]) value));
                }
                addRequest.addAttributeValue((byte[]) value);
            } else {
                value = Strings.utf8ToString(tlv.getValue().getData());
                if (IS_DEBUG) {
                    LOG.debug("Adding value {}" + value);
                }
                addRequest.addAttributeValue((String) value);
            }
        }
    } catch (LdapException le) {
    // Just swallow the exception, it can't occur here
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : AddRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 80 with TLV

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

the class InitSaslBind method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
    BindRequest bindRequestMessage = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // We will check that the sasl is not null
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04079);
        LOG.error(msg);
        BindResponseImpl response = new BindResponseImpl(bindRequestMessage.getMessageId());
        throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_CREDENTIALS, bindRequestMessage.getDn(), null);
    }
    bindRequestMessage.setSimple(false);
    if (IS_DEBUG) {
        LOG.debug("The SaslCredential has been created");
    }
}
Also used : ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) BindResponseImpl(org.apache.directory.api.ldap.model.message.BindResponseImpl) 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