Search in sources :

Example 16 with TLV

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

the class StoreSearchRequestDerefAlias 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 derefAliases
    BerValue value = tlv.getValue();
    int derefAliases = 0;
    try {
        derefAliases = IntegerDecoder.parse(value, LdapCodecConstants.NEVER_DEREF_ALIASES, LdapCodecConstants.DEREF_ALWAYS);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04102, value.toString());
        LOG.error(msg);
        throw new DecoderException(msg, ide);
    }
    searchRequest.setDerefAliases(AliasDerefMode.getDerefMode(derefAliases));
    if (IS_DEBUG) {
        switch(derefAliases) {
            case LdapCodecConstants.NEVER_DEREF_ALIASES:
                LOG.debug("Handling object strategy : NEVER_DEREF_ALIASES");
                break;
            case LdapCodecConstants.DEREF_IN_SEARCHING:
                LOG.debug("Handling object strategy : DEREF_IN_SEARCHING");
                break;
            case LdapCodecConstants.DEREF_FINDING_BASE_OBJ:
                LOG.debug("Handling object strategy : DEREF_FINDING_BASE_OBJ");
                break;
            case LdapCodecConstants.DEREF_ALWAYS:
                LOG.debug("Handling object strategy : DEREF_ALWAYS");
                break;
            default:
                LOG.debug("Handling object strategy : UNKNOWN");
        }
    }
}
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 TLV

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

the class StoreSaslMechanism method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<BindRequestDecorator> container) {
    BindRequest bindRequestMessage = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // mechanism
    if (tlv.getLength() == 0) {
        bindRequestMessage.setSaslMechanism("");
    } else {
        bindRequestMessage.setSaslMechanism(Strings.utf8ToString(tlv.getValue().getData()));
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("The mechanism is : {}", bindRequestMessage.getSaslMechanism());
    }
}
Also used : BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 18 with TLV

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

the class StoreSimpleAuth method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
    BindRequest bindRequestMessage = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Allocate the Authentication Object
    bindRequestMessage.setSimple(true);
    // We have to handle the special case of a 0 length simple
    if (tlv.getLength() == 0) {
        bindRequestMessage.setCredentials(Strings.EMPTY_BYTES);
    } else {
        bindRequestMessage.setCredentials(tlv.getValue().getData());
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("The simple authentication is : {}", Strings.dumpBytes(bindRequestMessage.getCredentials()));
    }
}
Also used : BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 19 with TLV

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

the class StoreVersion method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
    BindRequest bindRequestMessage = container.getMessage();
    // The current TLV should be a integer between 1 and 127
    // We get it and store it in Version
    TLV tlv = container.getCurrentTLV();
    BerValue value = tlv.getValue();
    try {
        int version = IntegerDecoder.parse(value, 1, 127);
        if (IS_DEBUG) {
            LOG.debug("Ldap version ", Integer.valueOf(version));
        }
        bindRequestMessage.setVersion3(version == 3);
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_04078, 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) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 20 with TLV

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

the class InitDelRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<DeleteRequestDecorator> container) throws DecoderException {
    // Create the DeleteRequest LdapMessage instance and store it in the container
    DeleteRequest internaldelRequest = new DeleteRequestImpl();
    internaldelRequest.setMessageId(container.getMessageId());
    DeleteRequestDecorator delRequest = new DeleteRequestDecorator(container.getLdapCodecService(), internaldelRequest);
    container.setMessage(delRequest);
    // And store the Dn into it
    // Get the Value and store it in the DelRequest
    TLV tlv = container.getCurrentTLV();
    // We have to handle the special case of a 0 length matched
    // Dn
    Dn entry;
    if (tlv.getLength() == 0) {
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(I18n.err(I18n.ERR_04073));
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            entry = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = I18n.err(I18n.ERR_04074, dnStr, Strings.dumpBytes(dnBytes), ine.getLocalizedMessage());
            LOG.error(msg);
            DeleteResponseImpl response = new DeleteResponseImpl(delRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
        delRequest.setName(entry);
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("Deleting Dn {}", entry);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) DeleteResponseImpl(org.apache.directory.api.ldap.model.message.DeleteResponseImpl) DeleteRequestDecorator(org.apache.directory.api.ldap.codec.decorators.DeleteRequestDecorator) DeleteRequestImpl(org.apache.directory.api.ldap.model.message.DeleteRequestImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

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