Search in sources :

Example 71 with TLV

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

the class StoreSaslCredentials 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();
    // credentials
    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 credentials are : {}", 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 72 with TLV

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

the class StoreCompareRequestAssertionValue method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<CompareRequestDecorator> container) {
    // Get the CompareRequest Object
    CompareRequest compareRequest = container.getMessage();
    // Get the Value and store it in the CompareRequest
    TLV tlv = container.getCurrentTLV();
    // We have to handle the special case of a 0 length value
    if (tlv.getLength() == 0) {
        compareRequest.setAssertionValue("");
    } else {
        if (container.isBinary(compareRequest.getAttributeId())) {
            compareRequest.setAssertionValue(tlv.getValue().getData());
            if (IS_DEBUG) {
                LOG.debug("Comparing attribute value {}", Strings.dumpBytes(compareRequest.getAssertionValue().getBytes()));
            }
        } else {
            compareRequest.setAssertionValue(Strings.utf8ToString(tlv.getValue().getData()));
            if (LOG.isDebugEnabled()) {
                LOG.debug("Comparing attribute value {}", compareRequest.getAssertionValue());
            }
        }
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 73 with TLV

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

the class StoreCompareRequestAttributeDesc method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<CompareRequestDecorator> container) throws DecoderException {
    // Get the CompareRequest Object
    CompareRequest compareRequest = container.getMessage();
    // Get the Value and store it in the CompareRequest
    TLV tlv = container.getCurrentTLV();
    // Dn
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04093);
        LOG.error(msg);
        CompareResponseImpl response = new CompareResponseImpl(compareRequest.getMessageId());
        throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, compareRequest.getName(), null);
    }
    String type = Strings.utf8ToString(tlv.getValue().getData());
    compareRequest.setAttributeId(type);
    if (IS_DEBUG) {
        LOG.debug("Comparing attribute description {}", compareRequest.getAttributeId());
    }
}
Also used : CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) CompareResponseImpl(org.apache.directory.api.ldap.model.message.CompareResponseImpl) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 74 with TLV

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

the class StoreCompareRequestEntryName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<CompareRequestDecorator> container) throws DecoderException {
    CompareRequest compareRequest = container.getMessage();
    // Get the Value and store it in the CompareRequest
    TLV tlv = container.getCurrentTLV();
    Dn entry;
    // Dn
    if (tlv.getLength() == 0) {
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(I18n.err(I18n.ERR_04089));
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            entry = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            CompareResponseImpl response = new CompareResponseImpl(compareRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
        compareRequest.setName(entry);
    }
    if (IS_DEBUG) {
        LOG.debug("Comparing Dn {}", entry);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) CompareResponseImpl(org.apache.directory.api.ldap.model.message.CompareResponseImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 75 with TLV

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

the class StoreModifyDnRequestNewSuperior method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyDnRequestDecorator> container) throws DecoderException {
    ModifyDnRequest modifyDnRequest = container.getMessage();
    // Get the Value and store it in the modifyDNRequest
    TLV tlv = container.getCurrentTLV();
    // We have to handle the special case of a 0 length matched
    // Dn
    Dn newSuperior = Dn.EMPTY_DN;
    if (tlv.getLength() == 0) {
        if (modifyDnRequest.getDeleteOldRdn()) {
            // This will generate a PROTOCOL_ERROR
            throw new DecoderException(I18n.err(I18n.ERR_04092));
        } else {
            LOG.warn("The new superior is null, so we will change the entry");
        }
        modifyDnRequest.setNewSuperior(newSuperior);
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            newSuperior = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid new superior Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            ModifyDnResponseImpl response = new ModifyDnResponseImpl(modifyDnRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, modifyDnRequest.getName(), ine);
        }
        modifyDnRequest.setNewSuperior(newSuperior);
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("New superior Dn {}", newSuperior);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyDnResponseImpl(org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) 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