use of org.apache.directory.api.ldap.model.message.Control in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method extendedOperation.
public ExtendedResponse extendedOperation(final ExtendedRequest request) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
final org.apache.directory.api.ldap.model.message.ExtendedRequest apacheRequest = new org.apache.directory.api.ldap.model.message.ExtendedRequest() {
public String getRequestName() {
return request.getID();
}
public org.apache.directory.api.ldap.model.message.ExtendedRequest setRequestName(final String oid) {
return this;
}
public org.apache.directory.api.ldap.model.message.ExtendedRequest setMessageId(final int messageId) {
return this;
}
public org.apache.directory.api.ldap.model.message.ExtendedRequest addControl(final Control control) {
return null;
}
public org.apache.directory.api.ldap.model.message.ExtendedRequest addAllControls(final Control[] controls) {
return null;
}
public org.apache.directory.api.ldap.model.message.ExtendedRequest removeControl(final Control control) {
return null;
}
public MessageTypeEnum getResponseType() {
return null;
}
public ResultResponse getResultResponse() {
return null;
}
public boolean hasResponse() {
return false;
}
public MessageTypeEnum getType() {
return null;
}
public Map<String, Control> getControls() {
return null;
}
public Control getControl(final String oid) {
return null;
}
public boolean hasControl(final String oid) {
return false;
}
public int getMessageId() {
return 0;
}
public Object get(final Object key) {
return null;
}
public Object put(final Object key, final Object value) {
return null;
}
};
try {
final org.apache.directory.api.ldap.model.message.ExtendedResponse apacheResponse = connection.extended(apacheRequest);
final ExtendedResponse extendedResponse = new ExtendedResponse() {
public String getID() {
return apacheResponse.getResponseName();
}
public byte[] getEncodedValue() {
return null;
}
};
return extendedResponse;
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
use of org.apache.directory.api.ldap.model.message.Control in project directory-ldap-api by apache.
the class SearchResultEntryTest method testDecodeSearchResultEntryEmptyAttributeValueWithControls.
/**
* Test the decoding of a SearchResultEntry with an empty attribute value
* with controls
*/
@Test
public void testDecodeSearchResultEntryEmptyAttributeValueWithControls() throws NamingException {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x56);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x54, 0x02, 0x01, // messageID MessageID
0x01, 0x64, // CHOICE { ..., searchResEntry SearchResultEntry,
0x32, // objectName LDAPDN,
0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm', // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
0x30, 0x13, 0x30, 0x11, // type AttributeDescription,
0x04, 0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // vals SET OF AttributeValue }
0x31, 0x02, // AttributeValue ::= OCTET STRING
0x04, 0x00, (byte) 0xA0, // A control
0x1B, 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultEntryDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
assertEquals(1, searchResultEntry.getMessageId());
assertEquals("ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString());
Entry entry = searchResultEntry.getEntry();
assertEquals(1, entry.size());
for (int i = 0; i < entry.size(); i++) {
Attribute attribute = entry.get("objectclass");
assertEquals(Strings.toLowerCaseAscii("objectClass"), Strings.toLowerCaseAscii(attribute.getUpId()));
assertTrue(attribute.contains(""));
}
// Check the Control
Map<String, Control> controls = searchResultEntry.getControls();
assertEquals(1, controls.size());
@SuppressWarnings("unchecked") CodecControl<Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<Control>) controls.get("2.16.840.1.113730.3.4.2");
assertEquals("2.16.840.1.113730.3.4.2", control.getOid());
assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(searchResultEntry);
// Check the length
assertEquals(0x56, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.ldap.model.message.Control in project directory-ldap-api by apache.
the class SearchResultReferenceTest method testDecodeSearchResultReferenceSuccessWithControls.
/**
* Test the decoding of a SearchResultReference with controls
*/
@Test
public void testDecodeSearchResultReferenceSuccessWithControls() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x3F5);
String[] ldapUrls = new String[] { "ldap:///", "ldap://directory.apache.org:80/", "ldap://d-a.org:80/", "ldap://1.2.3.4/", "ldap://1.2.3.4:80/", "ldap://1.1.1.100000.a/", "ldap://directory.apache.org:389/dc=example,dc=org/", "ldap://directory.apache.org:389/dc=example", "ldap://directory.apache.org:389/dc=example%202,dc=org", "ldap://directory.apache.org:389/dc=example,dc=org?ou", "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc", "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou", "ldap:///o=University%20of%20Michigan,c=US", "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US", "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress", "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)", "ldap://ldap.itd.umich.edu/c=GB?objectClass?one", "ldap://ldap.question.com/o=Question%3f,c=US?mail", "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", "ldap:///??sub??bindname=cn=Manager%2co=Foo", "ldap:///??sub??!bindname=cn=Manager%2co=Foo" };
stream.put(new byte[] { // LDAPMessage
0x30, // LDAPMessage
(byte) 0x82, // LDAPMessage
0x03, // LDAPMessage
(byte) 0xF1, // ::=SEQUENCE {
0x02, 0x01, // messageID MessageID
0x01, 0x73, (byte) 0x82, 0x03, // CHOICE { ...,
(byte) 0xcd // searchResEntry
// SearchResultEntry,
// ...
// SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL
});
for (int i = 0; i < ldapUrls.length; i++) {
stream.put((byte) 0x04);
stream.put((byte) Strings.getBytesUtf8(ldapUrls[i]).length);
byte[] bytes = Strings.getBytesUtf8(ldapUrls[i]);
for (int j = 0; j < bytes.length; j++) {
stream.put(bytes[j]);
}
}
byte[] controlBytes = new byte[] { (byte) 0xA0, // A control
0x1B, 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 };
for (int i = 0; i < controlBytes.length; i++) {
stream.put(controlBytes[i]);
}
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchResultReferenceDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultReferenceDecorator>(codec);
try {
ldapMessageContainer.clean();
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
stream.flip();
SearchResultReference searchResultReference = ldapMessageContainer.getMessage();
assertEquals(1, searchResultReference.getMessageId());
Set<String> ldapUrlsSet = new HashSet<String>();
for (int i = 0; i < ldapUrls.length; i++) {
ldapUrlsSet.add(ldapUrls[i]);
}
Referral referral = searchResultReference.getReferral();
assertNotNull(referral);
for (String ldapUrl : referral.getLdapUrls()) {
if (ldapUrlsSet.contains(ldapUrl)) {
ldapUrlsSet.remove(ldapUrl);
} else {
fail(ldapUrl.toString() + " is not present");
}
}
assertTrue(ldapUrlsSet.size() == 0);
// Check the Control
Map<String, Control> controls = searchResultReference.getControls();
assertEquals(1, controls.size());
@SuppressWarnings("unchecked") CodecControl<Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<Control>) controls.get("2.16.840.1.113730.3.4.2");
assertEquals("2.16.840.1.113730.3.4.2", control.getOid());
assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(searchResultReference);
// Check the length
assertEquals(0x3F5, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.ldap.model.message.Control in project directory-ldap-api by apache.
the class UpdateControls method toString.
/**
* @see Object#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("UpdateControl :");
sb.append("\n messageId : ").append(messageId);
if (controls.isEmpty()) {
sb.append("\n No controls");
} else {
sb.append("\n Controls: [");
boolean isFirst = true;
for (Control control : controls) {
if (isFirst) {
isFirst = false;
} else {
sb.append(", ");
}
sb.append(control.getOid());
}
sb.append(']');
}
return sb.toString();
}
use of org.apache.directory.api.ldap.model.message.Control in project directory-ldap-api by apache.
the class UpdateControls method hashCode.
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
int hash = 37;
hash = hash * 17 + messageId;
for (Control control : controls) {
hash = hash * 17 + control.hashCode();
}
return hash;
}
Aggregations