use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class BindResultTestCase method testReadBindResultFromInvalidElementType.
/**
* Tests the {@code readBindResultFrom} method with a sequence containing an
* invalid element type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testReadBindResultFromInvalidElementType() throws Exception {
ASN1Buffer b = new ASN1Buffer();
ASN1BufferSequence msgSequence = b.beginSequence();
b.addInteger(1);
ASN1BufferSequence opSequence = b.beginSequence(LDAPMessage.PROTOCOL_OP_TYPE_BIND_RESPONSE);
b.addEnumerated(0);
b.addOctetString();
b.addOctetString();
b.addOctetString((byte) 0x00);
opSequence.end();
msgSequence.end();
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
LDAPMessage.readLDAPResponseFrom(reader, true);
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class ModifyDNRequest method writeTo.
/**
* {@inheritDoc}
*/
@Override()
public void writeTo(@NotNull final ASN1Buffer writer) {
final ASN1BufferSequence requestSequence = writer.beginSequence(LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_DN_REQUEST);
writer.addOctetString(dn);
writer.addOctetString(newRDN);
writer.addBoolean(deleteOldRDN);
if (newSuperiorDN != null) {
writer.addOctetString(NEW_SUPERIOR_TYPE, newSuperiorDN);
}
requestSequence.end();
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class SearchRequest method writeTo.
/**
* {@inheritDoc}
*/
@Override()
public void writeTo(@NotNull final ASN1Buffer writer) {
final ASN1BufferSequence requestSequence = writer.beginSequence(LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_REQUEST);
writer.addOctetString(baseDN);
writer.addEnumerated(scope.intValue());
writer.addEnumerated(derefPolicy.intValue());
writer.addInteger(sizeLimit);
writer.addInteger(timeLimit);
writer.addBoolean(typesOnly);
filter.writeTo(writer);
final ASN1BufferSequence attrSequence = writer.beginSequence();
for (final String s : attributes) {
writer.addOctetString(s);
}
attrSequence.end();
requestSequence.end();
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class SimpleBindRequest method writeTo.
/**
* {@inheritDoc}
*/
@Override()
public void writeTo(@NotNull final ASN1Buffer buffer) {
final ASN1BufferSequence requestSequence = buffer.beginSequence(LDAPMessage.PROTOCOL_OP_TYPE_BIND_REQUEST);
buffer.addElement(VERSION_ELEMENT);
buffer.addElement(bindDN);
if (passwordProvider == null) {
buffer.addElement(password);
} else {
final byte[] pwBytes;
try {
pwBytes = passwordProvider.getPasswordBytes();
} catch (final LDAPException le) {
Debug.debugException(le);
throw new LDAPRuntimeException(le);
}
final ASN1OctetString pw = new ASN1OctetString(CRED_TYPE_SIMPLE, pwBytes);
buffer.addElement(pw);
buffer.setZeroBufferOnClear();
Arrays.fill(pwBytes, (byte) 0x00);
}
requestSequence.end();
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class SearchRequestProtocolOpTestCase method testSearchRequestProtocolOp.
/**
* Provides test coverage for the search request protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSearchRequestProtocolOp() throws Exception {
LinkedList<String> attrs = new LinkedList<String>();
attrs.add("*");
attrs.add("+");
SearchRequestProtocolOp op = new SearchRequestProtocolOp("dc=example,dc=com", SearchScope.SUB, DereferencePolicy.NEVER, 1, 2, false, Filter.createEqualityFilter("uid", "test.user"), attrs);
ASN1Buffer buffer = new ASN1Buffer();
op.writeTo(buffer);
byte[] opBytes = buffer.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
op = new SearchRequestProtocolOp(reader);
op = SearchRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new SearchRequestProtocolOp(op.toSearchRequest());
assertEquals(new DN(op.getBaseDN()), new DN("dc=example,dc=com"));
assertEquals(op.getScope(), SearchScope.SUB);
assertEquals(op.getDerefPolicy(), DereferencePolicy.NEVER);
assertEquals(op.getSizeLimit(), 1);
assertEquals(op.getTimeLimit(), 2);
assertFalse(op.typesOnly());
assertNotNull(op.getFilter());
assertEquals(op.getFilter(), Filter.create("(uid=test.user)"));
assertNotNull(op.getAttributes());
assertEquals(op.getAttributes().size(), 2);
assertEquals(op.getProtocolOpType(), (byte) 0x63);
assertNotNull(op.toString());
}
Aggregations