use of org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator in project directory-ldap-api by apache.
the class BindRequestPerfTest method testDecodeBindRequestSimpleNoControlsPerf.
/**
* Test the decoding of a BindRequest with Simple authentication and no
* controls
*/
@Test
@Ignore
public void testDecodeBindRequestSimpleNoControlsPerf() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x52);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x50, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x2E, // BindRequest ::= APPLICATION[0] SEQUENCE {
0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, // name LDAPDN,
0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', (byte) 0x80, // authentication AuthenticationChoice
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r', 'd', (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 LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode the BindRequest PDU
try {
int nbLoops = 1000000;
long t0 = System.currentTimeMillis();
for (int i = 0; i < nbLoops; i++) {
ldapDecoder.decode(stream, container);
container.clean();
stream.flip();
}
long t1 = System.currentTimeMillis();
System.out.println("testDecodeBindRequestSimpleNoControlsPerf, " + nbLoops + " loops, Delta = " + (t1 - t0));
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
assertEquals(1, bindRequest.getMessageId());
assertTrue(bindRequest.isVersion3());
assertEquals("uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString());
assertTrue(bindRequest.isSimple());
assertEquals("password", Strings.utf8ToString(bindRequest.getCredentials()));
// Check the Control
Map<String, Control> controls = bindRequest.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(bindRequest);
// Check the length
assertEquals(0x52, 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.codec.decorators.BindRequestDecorator in project directory-ldap-api by apache.
the class BindRequestTest method testDecodeBindRequestSimpleEmptyName.
/**
* Test the decoding of a BindRequest with Simple authentication, empty name
* (an anonymous bind) and no controls
*/
@Test
public void testDecodeBindRequestSimpleEmptyName() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x16);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x14, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x0F, // BindRequest ::= APPLICATION[0] SEQUENCE {
0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, // name LDAPDN,
0x00, (byte) 0x80, // authentication AuthenticationChoice
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r', 'd' });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode the BindRequest PDU
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
assertEquals(1, bindRequest.getMessageId());
assertTrue(bindRequest.isVersion3());
assertEquals("", bindRequest.getName());
assertTrue(bindRequest.isSimple());
assertEquals("password", Strings.utf8ToString(bindRequest.getCredentials()));
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(bindRequest);
// Check the length
assertEquals(0x16, 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.codec.decorators.BindRequestDecorator in project directory-ldap-api by apache.
the class BindRequestTest method testDecodeBindRequestSaslNoCredsNoControls.
/**
* Test the decoding of a BindRequest with Sasl authentication, no
* credentials and no controls
*/
@Test
public void testDecodeBindRequestSaslNoCredsNoControls() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x3A);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x38, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x33, // BindRequest ::= APPLICATION[0] SEQUENCE {
0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, // name LDAPDN,
0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', (byte) 0xA3, // authentication AuthenticationChoice
0x0D, // ...
0x04, 0x0B, 'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4' });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode the BindRequest PDU
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
assertEquals(1, bindRequest.getMessageId());
assertTrue(bindRequest.isVersion3());
assertEquals("uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString());
assertFalse(bindRequest.isSimple());
assertEquals("KERBEROS_V4", bindRequest.getSaslMechanism());
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(bindRequest);
// Check the length
assertEquals(0x3A, 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.codec.decorators.BindRequestDecorator in project directory-ldap-api by apache.
the class BindRequestTest method testDecodeBindRequestEmptyMechanismWithControls.
/**
* Test the decoding of a BindRequest with an empty mechanisms with controls
*/
@Test
public void testDecodeBindRequestEmptyMechanismWithControls() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x2D);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x2B, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x09, 0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, 0x00, (byte) 0xA3, 0x02, 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 LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode the BindRequest PDU
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
assertEquals(1, bindRequest.getMessageId());
assertTrue(bindRequest.isVersion3());
assertEquals("", bindRequest.getName());
assertFalse(bindRequest.isSimple());
assertEquals("", bindRequest.getSaslMechanism());
assertEquals("", Strings.utf8ToString(bindRequest.getCredentials()));
// Check the Control
Map<String, Control> controls = bindRequest.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(bindRequest);
// Check the length
assertEquals(0x2D, 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.codec.decorators.BindRequestDecorator in project directory-ldap-api by apache.
the class BindRequestTest method testDecodeBindRequestEmptyName.
/**
* Test the decoding of a BindRequest with an empty name
*/
@Test
public void testDecodeBindRequestEmptyName() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x0C);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x0A, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x05, 0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, 0x00 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode a BindRequest message
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
Aggregations