Search in sources :

Example 1 with OpaqueControl

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

the class LdifControlSerializationTest method setup.

@BeforeClass
public static void setup() {
    controlCriticalWithData = new OpaqueControl("1.2.3.4.1");
    controlCriticalWithData.setCritical(true);
    ((OpaqueControl) controlCriticalWithData).setEncodedValue(data);
    controlCriticalNoData = new OpaqueControl("1.2.3.4.2");
    controlCriticalNoData.setCritical(true);
    controlCriticalEmptyData = new OpaqueControl("1.2.3.4.3");
    controlCriticalEmptyData.setCritical(true);
    ((OpaqueControl) controlCriticalEmptyData).setEncodedValue(Strings.EMPTY_BYTES);
    controlNoCriticalWithData = new OpaqueControl("1.2.3.4.4");
    controlNoCriticalWithData.setCritical(false);
    ((OpaqueControl) controlNoCriticalWithData).setEncodedValue(data);
    controlNoCriticalNoData = new OpaqueControl("1.2.3.4.5");
    controlNoCriticalNoData.setCritical(false);
    controlNoCriticalEmptyData = new OpaqueControl("1.2.3.4.6");
    controlNoCriticalEmptyData.setCritical(false);
}
Also used : OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl) BeforeClass(org.junit.BeforeClass)

Example 2 with OpaqueControl

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

the class OpaqueControlTest method testEmptyValue.

@Test
public void testEmptyValue() {
    OpaqueControl control = new OpaqueControl("1.1");
    assertFalse(control.hasEncodedValue());
    control.setEncodedValue(Strings.EMPTY_BYTES);
    assertTrue(control.hasEncodedValue());
}
Also used : OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl) Test(org.junit.Test)

Example 3 with OpaqueControl

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

the class LdapNetworkConnection method deleteTree.

/**
 * deletes the entry with the given Dn, and all its children
 *
 * @param dn the target entry's Dn as a String
 * @throws LdapException If the Dn is not valid or if the deletion failed
 */
public void deleteTree(String dn) throws LdapException {
    try {
        String treeDeleteOid = "1.2.840.113556.1.4.805";
        Dn newDn = new Dn(dn);
        if (isControlSupported(treeDeleteOid)) {
            DeleteRequest deleteRequest = new DeleteRequestImpl();
            deleteRequest.setName(newDn);
            deleteRequest.addControl(new OpaqueControl(treeDeleteOid));
            DeleteResponse deleteResponse = delete(deleteRequest);
            processResponse(deleteResponse);
        } else {
            String msg = "The subtreeDelete control (1.2.840.113556.1.4.805) is not supported by the server\n" + " The deletion has been aborted";
            LOG.error(msg);
            throw new LdapException(msg);
        }
    } catch (LdapInvalidDnException e) {
        LOG.error(e.getMessage(), e);
        throw new LdapException(e.getMessage(), e);
    }
}
Also used : DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) DeleteRequestImpl(org.apache.directory.api.ldap.model.message.DeleteRequestImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 4 with OpaqueControl

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

the class LdapNetworkConnection method deleteTree.

/**
 * deletes the entry with the given Dn, and all its children
 *
 * @param dn the target entry's Dn
 * @throws LdapException If the Dn is not valid or if the deletion failed
 */
public void deleteTree(Dn dn) throws LdapException {
    String treeDeleteOid = "1.2.840.113556.1.4.805";
    if (isControlSupported(treeDeleteOid)) {
        DeleteRequest deleteRequest = new DeleteRequestImpl();
        deleteRequest.setName(dn);
        deleteRequest.addControl(new OpaqueControl(treeDeleteOid));
        DeleteResponse deleteResponse = delete(deleteRequest);
        processResponse(deleteResponse);
    } else {
        String msg = "The subtreeDelete control (1.2.840.113556.1.4.805) is not supported by the server\n" + " The deletion has been aborted";
        LOG.error(msg);
        throw new LdapException(msg);
    }
}
Also used : DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) DeleteRequestImpl(org.apache.directory.api.ldap.model.message.DeleteRequestImpl) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 5 with OpaqueControl

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

the class Dsmlv2ResponseGrammar method createAndAddControl.

/**
 * Creates a Control parsing the current node and adds it to the given parent
 * @param container the DSMLv2Container
 * @param parent the parent
 * @throws XmlPullParserException
 */
private void createAndAddControl(Dsmlv2Container container, AbstractDsmlMessageDecorator<? extends Message> parent) throws XmlPullParserException {
    CodecControl<? extends Control> control;
    XmlPullParser xpp = container.getParser();
    // Checking and adding the Control's attributes
    String attributeValue;
    // TYPE
    attributeValue = xpp.getAttributeValue("", "type");
    if (attributeValue != null) {
        if (!Oid.isOid(attributeValue)) {
            throw new XmlPullParserException(I18n.err(I18n.ERR_03006), xpp, null);
        }
        control = container.getLdapCodecService().newControl(new OpaqueControl(attributeValue));
        parent.addControl(control);
    } else {
        throw new XmlPullParserException(I18n.err(I18n.ERR_03005), xpp, null);
    }
    // CRITICALITY
    attributeValue = xpp.getAttributeValue("", "criticality");
    if (attributeValue != null) {
        if ("true".equals(attributeValue)) {
            control.setCritical(true);
        } else if ("false".equals(attributeValue)) {
            control.setCritical(false);
        } else {
            throw new XmlPullParserException(I18n.err(I18n.ERR_03007), xpp, null);
        }
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl)

Aggregations

OpaqueControl (org.apache.directory.api.ldap.model.message.controls.OpaqueControl)7 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 DeleteRequest (org.apache.directory.api.ldap.model.message.DeleteRequest)2 DeleteRequestImpl (org.apache.directory.api.ldap.model.message.DeleteRequestImpl)2 DeleteResponse (org.apache.directory.api.ldap.model.message.DeleteResponse)2 Dn (org.apache.directory.api.ldap.model.name.Dn)2 Test (org.junit.Test)2 EncoderException (org.apache.directory.api.asn1.EncoderException)1 BasicControlDecorator (org.apache.directory.api.ldap.codec.BasicControlDecorator)1 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)1 ControlFactory (org.apache.directory.api.ldap.codec.api.ControlFactory)1 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)1 BindRequestImpl (org.apache.directory.api.ldap.model.message.BindRequestImpl)1 Control (org.apache.directory.api.ldap.model.message.Control)1 BeforeClass (org.junit.BeforeClass)1 Ignore (org.junit.Ignore)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1