Search in sources :

Example 11 with TLV

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

the class StoreModifyDnRequestDeleteOldRdn method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyDnRequestDecorator> container) throws DecoderException {
    ModifyDnRequest modifyDnRequest = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // We get the value. If it's a 0, it's a FALSE. If it's
    // a FF, it's a TRUE. Any other value should be an error,
    // but we could relax this constraint. So if we have
    // something
    // which is not 0, it will be interpreted as TRUE, but we
    // will generate a warning.
    BerValue value = tlv.getValue();
    try {
        modifyDnRequest.setDeleteOldRdn(BooleanDecoder.parse(value));
    } catch (BooleanDecoderException bde) {
        LOG.error(I18n.err(I18n.ERR_04091, Strings.dumpBytes(value.getData()), bde.getMessage()));
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(bde.getMessage(), bde);
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        if (modifyDnRequest.getDeleteOldRdn()) {
            LOG.debug(" Old Rdn attributes will be deleted");
        } else {
            LOG.debug(" Old Rdn attributes will be retained");
        }
    }
}
Also used : BooleanDecoderException(org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BooleanDecoderException(org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 12 with TLV

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

the class StoreModifyDnRequestEntryName 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 entry;
    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());
            ModifyDnResponseImpl response = new ModifyDnResponseImpl(modifyDnRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
        modifyDnRequest.setName(entry);
    }
    if (IS_DEBUG) {
        LOG.debug("Modifying Dn {}", entry);
    }
}
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)

Example 13 with TLV

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

the class StoreModifyDnRequestNewRdn 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
    // newDN
    Rdn newRdn;
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04090);
        LOG.error(msg);
        ModifyDnResponseImpl response = new ModifyDnResponseImpl(modifyDnRequest.getMessageId());
        throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, modifyDnRequest.getName(), null);
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            Dn dn = new Dn(dnStr);
            newRdn = dn.getRdn(dn.size() - 1);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid new Rdn 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.setNewRdn(newRdn);
    }
    if (IS_DEBUG) {
        LOG.debug("Modifying with new Rdn {}", newRdn);
    }
}
Also used : ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) ModifyDnResponseImpl(org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) Rdn(org.apache.directory.api.ldap.model.name.Rdn) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 14 with TLV

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

the class InitSearchRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) {
    // Now, we can allocate the SearchRequest Object
    TLV tlv = container.getCurrentTLV();
    SearchRequest internalSearchRequest = new SearchRequestImpl();
    internalSearchRequest.setMessageId(container.getMessageId());
    SearchRequestDecorator searchRequest = new SearchRequestDecorator(container.getLdapCodecService(), internalSearchRequest);
    searchRequest.setTlvId(tlv.getId());
    container.setMessage(searchRequest);
    LOG.debug("Search Request");
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SearchRequestImpl(org.apache.directory.api.ldap.model.message.SearchRequestImpl) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 15 with TLV

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

the class StoreSearchRequestBaseObject method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequestDecorator searchRequestDecorator = container.getMessage();
    SearchRequest searchRequest = searchRequestDecorator.getDecorated();
    TLV tlv = container.getCurrentTLV();
    // We have to check that this is a correct Dn
    Dn baseObject;
    // root.
    if (tlv.getLength() != 0) {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            baseObject = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid root Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            SearchResultDoneImpl response = new SearchResultDoneImpl(searchRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
    } else {
        baseObject = Dn.EMPTY_DN;
    }
    searchRequest.setBase(baseObject);
    LOG.debug("Searching with root Dn : {}", baseObject);
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) SearchResultDoneImpl(org.apache.directory.api.ldap.model.message.SearchResultDoneImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) 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