Search in sources :

Example 21 with TLV

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

the class StoreExtendedRequestValue method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ExtendedRequestDecorator<?>> container) throws DecoderException {
    // We can allocate the ExtendedRequest Object
    ExtendedRequestDecorator<?> extendedRequest = container.getMessage();
    // Get the Value and store it in the ExtendedRequest
    TLV tlv = container.getCurrentTLV();
    // value
    if (tlv.getLength() == 0) {
        extendedRequest.setRequestValue(Strings.EMPTY_BYTES);
    } else {
        extendedRequest.setRequestValue(tlv.getValue().getData());
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("Extended value : {}", extendedRequest.getRequestValue());
    }
}
Also used : TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 22 with TLV

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

the class AddModifyRequestAttribute method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
    ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
    ModifyRequest modifyRequest = modifyRequestDecorator.getDecorated();
    TLV tlv = container.getCurrentTLV();
    // Store the value. It can't be null
    String type;
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04083);
        LOG.error(msg);
        ModifyResponseImpl response = new ModifyResponseImpl(modifyRequest.getMessageId());
        throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, modifyRequest.getName(), null);
    } else {
        type = Strings.utf8ToString(tlv.getValue().getData());
        modifyRequestDecorator.addAttributeTypeAndValues(type);
    }
    if (IS_DEBUG) {
        LOG.debug("Modifying type : {}", type);
    }
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) ModifyResponseImpl(org.apache.directory.api.ldap.model.message.ModifyResponseImpl) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 23 with TLV

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

the class StoreModifyRequestAttributeValue method action.

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

Example 24 with TLV

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

the class CheckLengthNotNull method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    int expectedLength = tlv.getLength();
    // The Length should be null
    if (expectedLength == 0) {
        String msg = I18n.err(I18n.ERR_04096_NULL_CONTROL_LENGTH);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 25 with TLV

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

the class AddControl method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    // We have to handle the special case of a 0 length OID
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04097_NULL_CONTROL_OID);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
    byte[] value = tlv.getValue().getData();
    String oidValue = Strings.asciiBytesToString(value);
    // The OID is encoded as a String, not an Object Id
    if (!Oid.isOid(oidValue)) {
        String msg = I18n.err(I18n.ERR_04098_INVALID_CONTROL_OID, oidValue);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
    Message message = container.getMessage();
    Control control = container.getLdapCodecService().newControl(oidValue);
    message.addControl(control);
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("Control OID : {}", oidValue);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) Control(org.apache.directory.api.ldap.model.message.Control) Message(org.apache.directory.api.ldap.model.message.Message) 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