Search in sources :

Example 1 with ModifyResponseImpl

use of org.apache.directory.api.ldap.model.message.ModifyResponseImpl in project directory-ldap-api by apache.

the class ModifyRequestTest method testDecodeModifyRequestBadDN.

/**
 * Test the decoding of a ModifyRequest
 */
@Test
public void testDecodeModifyRequestBadDN() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x54);
    stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
    0x52, 0x02, 0x01, // messageID MessageID
    0x01, 0x66, // CHOICE { ..., modifyRequest ModifyRequest, ...
    0x4d, // object LDAPDN,
    0x04, 0x20, 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x29, // modification SEQUENCE OF SEQUENCE {
    0x30, 0x11, 0x0A, 0x01, // operation ENUMERATED {
    0x02, // modification AttributeTypeAndValues } }
    0x30, // AttributeTypeAndValues ::= SEQUENCE {
    0x0c, 0x04, 0x01, // type AttributeDescription,
    'l', 0x31, // vals SET OF AttributeValue }
    0x07, 0x04, 0x05, 'P', 'a', 'r', 'i', 's', 0x30, // modification SEQUENCE OF *SEQUENCE* {
    0x14, 0x0A, 0x01, // operation ENUMERATED {
    0x00, // modification AttributeTypeAndValues } }
    0x30, // AttributeTypeAndValues ::= SEQUENCE {
    0x0f, // type AttributeDescription,
    0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, // vals SET OF AttributeValue }
    0x06, 0x04, 0x04, 't', 'e', 's', 't' });
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<ModifyRequestDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyRequestDecorator>(codec);
    // Decode a ModifyRequest PDU
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        assertTrue(de instanceof ResponseCarryingException);
        Message response = ((ResponseCarryingException) de).getResponse();
        assertTrue(response instanceof ModifyResponseImpl);
        assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((ModifyResponseImpl) response).getLdapResult().getResultCode());
        return;
    }
    fail("We should not reach this point");
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) Message(org.apache.directory.api.ldap.model.message.Message) ModifyResponseImpl(org.apache.directory.api.ldap.model.message.ModifyResponseImpl) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 2 with ModifyResponseImpl

use of org.apache.directory.api.ldap.model.message.ModifyResponseImpl 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 3 with ModifyResponseImpl

use of org.apache.directory.api.ldap.model.message.ModifyResponseImpl in project directory-ldap-api by apache.

the class InitModifyResponse method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyResponseDecorator> container) {
    // Now, we can allocate the ModifyResponse Object
    ModifyResponseDecorator modifyResponse = new ModifyResponseDecorator(container.getLdapCodecService(), new ModifyResponseImpl(container.getMessageId()));
    container.setMessage(modifyResponse);
    LOG.debug("Modify response");
}
Also used : ModifyResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyResponseDecorator) ModifyResponseImpl(org.apache.directory.api.ldap.model.message.ModifyResponseImpl)

Example 4 with ModifyResponseImpl

use of org.apache.directory.api.ldap.model.message.ModifyResponseImpl 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 5 with ModifyResponseImpl

use of org.apache.directory.api.ldap.model.message.ModifyResponseImpl in project directory-ldap-api by apache.

the class ModifyRequestTest method testDecodeModifyRequestAddOperationModificationEmptyType.

/**
 * Test the decoding of a ModifyRequest with an add operation, and a
 * modification with an empty type
 */
@Test
public void testDecodeModifyRequestAddOperationModificationEmptyType() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x34);
    stream.put(new byte[] { 0x30, // LdapMessage
    0x32, 0x02, 0x01, // Message ID : 49
    0x31, 0x66, // ModifyRequest
    0x2D, 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x09, 0x30, 0x07, 0x0A, 0x01, 0x00, 0x30, 0x02, 0x04, 0x00 });
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<ModifyRequestDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyRequestDecorator>(codec);
    // Decode a ModifyRequest PDU
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
        fail("We should never reach this point !!!");
    } catch (DecoderException de) {
        assertTrue(de instanceof ResponseCarryingException);
        Message response = ((ResponseCarryingException) de).getResponse();
        assertTrue(response instanceof ModifyResponseImpl);
        assertEquals(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ((ModifyResponseImpl) response).getLdapResult().getResultCode());
        return;
    }
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) Message(org.apache.directory.api.ldap.model.message.Message) ModifyResponseImpl(org.apache.directory.api.ldap.model.message.ModifyResponseImpl) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

ModifyResponseImpl (org.apache.directory.api.ldap.model.message.ModifyResponseImpl)5 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)4 ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)4 ByteBuffer (java.nio.ByteBuffer)2 DecoderException (org.apache.directory.api.asn1.DecoderException)2 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)2 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)2 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)2 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)2 Message (org.apache.directory.api.ldap.model.message.Message)2 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)2 Test (org.junit.Test)2 ModifyResponseDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyResponseDecorator)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1