Search in sources :

Example 6 with TLV

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

the class InitAbandonRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AbandonRequestDecorator> container) throws DecoderException {
    // Create the AbandonRequest LdapMessage instance and store it in the container
    AbandonRequest internalAbandonRequest = new AbandonRequestImpl();
    internalAbandonRequest.setMessageId(container.getMessageId());
    AbandonRequestDecorator abandonRequest = new AbandonRequestDecorator(container.getLdapCodecService(), internalAbandonRequest);
    container.setMessage(abandonRequest);
    // The current TLV should be a integer
    // We get it and store it in MessageId
    TLV tlv = container.getCurrentTLV();
    BerValue value = tlv.getValue();
    if ((value == null) || (value.getData() == null)) {
        String msg = I18n.err(I18n.ERR_04075);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
    try {
        int abandonnedMessageId = IntegerDecoder.parse(value, 0, Integer.MAX_VALUE);
        abandonRequest.setAbandoned(abandonnedMessageId);
        if (IS_DEBUG) {
            LOG.debug("AbandonMessage Id has been decoded : {}", Integer.valueOf(abandonnedMessageId));
        }
        container.setGrammarEndAllowed(true);
        return;
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_04076, 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) AbandonRequest(org.apache.directory.api.ldap.model.message.AbandonRequest) AbandonRequestImpl(org.apache.directory.api.ldap.model.message.AbandonRequestImpl) AbandonRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 7 with TLV

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

the class AddAddRequestAttributeType method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AddRequestDecorator> container) throws DecoderException {
    AddRequestDecorator addRequest = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Store the type. It can't be null.
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04086);
        LOG.error(msg);
        AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
        throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, addRequest.getEntry().getDn(), null);
    }
    String type = Strings.utf8ToString(tlv.getValue().getData());
    try {
        addRequest.addAttributeType(type);
    } catch (LdapException ne) {
        String msg = I18n.err(I18n.ERR_04087);
        LOG.error(msg);
        AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
        throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, addRequest.getEntry().getDn(), ne);
    }
    if (IS_DEBUG) {
        LOG.debug("Adding type {}", type);
    }
}
Also used : ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) AddResponseImpl(org.apache.directory.api.ldap.model.message.AddResponseImpl) 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 8 with TLV

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

the class InitAddRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AddRequestDecorator> container) throws DecoderException {
    // Now, we can allocate the AddRequest Object
    int messageId = container.getMessageId();
    AddRequest internalAddRequest = new AddRequestImpl();
    internalAddRequest.setMessageId(messageId);
    AddRequestDecorator addRequest = new AddRequestDecorator(container.getLdapCodecService(), internalAddRequest);
    container.setMessage(addRequest);
    // We will check that the request is not null
    TLV tlv = container.getCurrentTLV();
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04084);
        LOG.error(msg);
        // Will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
}
Also used : AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) DecoderException(org.apache.directory.api.asn1.DecoderException) AddRequestImpl(org.apache.directory.api.ldap.model.message.AddRequestImpl) AddRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 9 with TLV

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

the class StoreAddRequestEntryName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AddRequestDecorator> container) throws DecoderException {
    AddRequestDecorator addRequest = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Store the entry. It can't be null
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04085);
        LOG.error(msg);
        AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
        // Not 100% sure though ...
        throw new ResponseCarryingException(msg, response, ResultCodeEnum.NAMING_VIOLATION, Dn.EMPTY_DN, null);
    } else {
        Dn entryDn = null;
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            entryDn = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
        addRequest.setEntryDn(entryDn);
    }
    LOG.debug("Adding an entry with Dn : {}", addRequest.getEntry());
}
Also used : ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) AddResponseImpl(org.apache.directory.api.ldap.model.message.AddResponseImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) AddRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 10 with TLV

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

the class InitBindRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
    // Create the BindRequest LdapMessage instance and store it in the container
    BindRequest internalBindRequest = new BindRequestImpl();
    internalBindRequest.setMessageId(container.getMessageId());
    BindRequestDecorator bindRequest = new BindRequestDecorator(container.getLdapCodecService(), internalBindRequest);
    container.setMessage(bindRequest);
    // We will check that the request is not null
    TLV tlv = container.getCurrentTLV();
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04077);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) BindRequestDecorator(org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl) 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