Search in sources :

Example 26 with ModifyRequest

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

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

the class BatchRequestTest method testResponseWith1ModifyRequest.

/**
 * Test parsing of a Request with 1 ModifyRequest
 */
@Test
public void testResponseWith1ModifyRequest() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(BatchRequestTest.class.getResource("request_with_1_ModifyRequest.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    BatchRequestDsml batchRequest = parser.getBatchRequest();
    assertEquals(1, batchRequest.getRequests().size());
    if (batchRequest.getCurrentRequest() instanceof ModifyRequest) {
        assertTrue(true);
    } else {
        fail();
    }
}
Also used : BatchRequestDsml(org.apache.directory.api.dsmlv2.request.BatchRequestDsml) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 28 with ModifyRequest

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

the class ModifyRequestTest method testRequestWithOperationAdd.

/**
 * Test parsing of a request with operation attribute to Add value
 * @throws NamingException
 */
@Test
public void testRequestWithOperationAdd() throws LdapException {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(ModifyRequestTest.class.getResource("request_with_operation_add.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
    Collection<Modification> modifications = modifyRequest.getModifications();
    assertEquals(1, modifications.size());
    Modification modification = modifications.iterator().next();
    assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 29 with ModifyRequest

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

the class ModifyRequestTest method testRequestWith1Modification.

/**
 * Test parsing of a request with a Modification element
 * @throws NamingException
 */
@Test
public void testRequestWith1Modification() throws LdapException {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(ModifyRequestTest.class.getResource("request_with_1_modification.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
    Collection<Modification> modifications = modifyRequest.getModifications();
    assertEquals(1, modifications.size());
    Modification modification = modifications.iterator().next();
    assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
    Attribute attribute = modification.getAttribute();
    assertEquals("directreport", attribute.getId());
    assertEquals("CN=John Smith, DC=microsoft, DC=com", attribute.get().getValue());
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 30 with ModifyRequest

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

the class ModifyRequestTest method testRequestWithModificationWithoutValue.

/**
 * Test parsing of a request with a Modification element without Value element
 * @throws NamingException
 */
@Test
public void testRequestWithModificationWithoutValue() throws LdapException {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(ModifyRequestTest.class.getResource("request_with_modification_without_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
    Collection<Modification> modifications = modifyRequest.getModifications();
    assertEquals(1, modifications.size());
    Modification modification = modifications.iterator().next();
    assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
    Attribute attribute = modification.getAttribute();
    assertEquals("directreport", attribute.getId());
    assertEquals(0, attribute.size());
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Aggregations

ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)40 Modification (org.apache.directory.api.ldap.model.entry.Modification)25 Test (org.junit.Test)24 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)22 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)17 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)17 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)14 ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)11 ModifyRequestImpl (org.apache.directory.api.ldap.model.message.ModifyRequestImpl)11 ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)10 Dn (org.apache.directory.api.ldap.model.name.Dn)10 ByteBuffer (java.nio.ByteBuffer)7 DecoderException (org.apache.directory.api.asn1.DecoderException)7 EncoderException (org.apache.directory.api.asn1.EncoderException)7 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)7 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)7 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)7 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)7 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)7 Control (org.apache.directory.api.ldap.model.message.Control)7