Search in sources :

Example 11 with ResponseCarryingException

use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException 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 12 with ResponseCarryingException

use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException 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)

Example 13 with ResponseCarryingException

use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException 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)

Example 14 with ResponseCarryingException

use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException 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 15 with ResponseCarryingException

use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException 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)

Aggregations

ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)28 DecoderException (org.apache.directory.api.asn1.DecoderException)20 Message (org.apache.directory.api.ldap.model.message.Message)16 ByteBuffer (java.nio.ByteBuffer)14 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)14 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)14 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)14 Test (org.junit.Test)14 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)12 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)8 Dn (org.apache.directory.api.ldap.model.name.Dn)8 ModifyDnResponseImpl (org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl)6 AddResponseImpl (org.apache.directory.api.ldap.model.message.AddResponseImpl)5 ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)4 CompareResponseImpl (org.apache.directory.api.ldap.model.message.CompareResponseImpl)4 ModifyResponseImpl (org.apache.directory.api.ldap.model.message.ModifyResponseImpl)4 Asn1Container (org.apache.directory.api.asn1.ber.Asn1Container)3 ModifyDnRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyDnRequestDecorator)3 BindResponseImpl (org.apache.directory.api.ldap.model.message.BindResponseImpl)3 ModifyDnRequest (org.apache.directory.api.ldap.model.message.ModifyDnRequest)3