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);
}
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());
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations