Search in sources :

Example 66 with TLV

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

the class StoreExtendedRequestName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ExtendedRequestDecorator<?>> container) throws DecoderException {
    ExtendedRequest req;
    // Get the Value and store it in the ExtendedRequest
    TLV tlv = container.getCurrentTLV();
    // OID
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04095);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    } else {
        byte[] requestNameBytes = tlv.getValue().getData();
        try {
            String requestName = Strings.utf8ToString(requestNameBytes);
            if (!Oid.isOid(requestName)) {
                String msg = "The Request name is not a valid OID : " + Strings.utf8ToString(requestNameBytes) + " (" + Strings.dumpBytes(requestNameBytes) + ") is invalid";
                LOG.error(msg);
                // throw an exception, we will get a PROTOCOL_ERROR
                throw new DecoderException(msg);
            }
            req = LdapApiServiceFactory.getSingleton().newExtendedRequest(requestName, null);
            req.setMessageId(container.getMessageId());
            container.setMessage(LdapApiServiceFactory.getSingleton().decorate(req));
        } catch (DecoderException de) {
            String msg = "The Request name is not a valid OID : " + Strings.utf8ToString(requestNameBytes) + " (" + Strings.dumpBytes(requestNameBytes) + ") is invalid";
            LOG.error("{} : {}", msg, de.getMessage());
            // Rethrow the exception, we will get a PROTOCOL_ERROR
            throw de;
        }
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("OID read : {}", req.getRequestName());
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 67 with TLV

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

the class InitAttributeVals method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyRequestDecorator> container) {
    TLV tlv = container.getCurrentTLV();
    // If the length is null, we store an empty value
    if (tlv.getLength() == 0) {
        LOG.debug("No vals for this attribute");
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    LOG.debug("Some vals are to be decoded");
}
Also used : TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 68 with TLV

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

the class StoreModifyRequestObjectName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
    ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
    ModifyRequest modifyRequest = modifyRequestDecorator.getDecorated();
    TLV tlv = container.getCurrentTLV();
    Dn object = Dn.EMPTY_DN;
    // Store the value.
    if (tlv.getLength() == 0) {
        (modifyRequestDecorator.getDecorated()).setName(object);
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            object = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            ModifyResponseImpl response = new ModifyResponseImpl(modifyRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
        modifyRequest.setName(object);
    }
    if (IS_DEBUG) {
        LOG.debug("Modification of Dn {}", modifyRequest.getName());
    }
}
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) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 69 with TLV

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

the class StoreOperationType method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
    ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Decode the operation type
    int operation = 0;
    try {
        operation = IntegerDecoder.parse(tlv.getValue(), 0, 2);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04082, Strings.dumpBytes(tlv.getValue().getData()));
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg, ide);
    }
    // Store the current operation.
    modifyRequestDecorator.setCurrentOperation(operation);
    if (IS_DEBUG) {
        switch(operation) {
            case LdapCodecConstants.OPERATION_ADD:
                LOG.debug("Modification operation : ADD");
                break;
            case LdapCodecConstants.OPERATION_DELETE:
                LOG.debug("Modification operation : DELETE");
                break;
            case LdapCodecConstants.OPERATION_REPLACE:
                LOG.debug("Modification operation : REPLACE");
                break;
            default:
                LOG.debug("Modification operation : UNKNOWN");
        }
    }
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 70 with TLV

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

the class StoreName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
    BindRequest bindRequestMessage = container.getMessage();
    // Get the Value and store it in the BindRequest
    TLV tlv = container.getCurrentTLV();
    // We have to handle the special case of a 0 length name
    if (tlv.getLength() == 0) {
        bindRequestMessage.setName("");
    } else {
        byte[] nameBytes = tlv.getValue().getData();
        String nameStr = Strings.utf8ToString(nameBytes);
        bindRequestMessage.setName(nameStr);
    }
    if (IS_DEBUG) {
        LOG.debug(" The Bind name is {}", bindRequestMessage.getName());
    }
}
Also used : BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) 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