use of org.apache.directory.api.ldap.model.message.BindRequest in project directory-ldap-api by apache.
the class LdapDecoderTest method testDecode2Messages.
/**
* Test the decoding of two messages in a PDU
*/
@Test
public void testDecode2Messages() throws Exception {
LdapMessageContainer<MessageDecorator<? extends Message>> container = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
IoSession dummySession = new DummySession();
dummySession.setAttribute(LdapDecoder.MESSAGE_CONTAINER_ATTR, container);
ByteBuffer stream = ByteBuffer.allocate(0x6A);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x33, 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
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r', 'd', 0x30, // LDAPMessage ::=SEQUENCE {
0x33, 0x02, 0x01, // messageID MessageID
0x02, 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
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r', 'd' });
stream.flip();
List<Message> result = new ArrayList<Message>();
// Decode a BindRequest PDU
try {
decode(stream, container, result);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check the decoded PDU
BindRequest bindRequest = (BindRequest) (result.get(0));
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()));
// The second message
bindRequest = (BindRequest) (result.get(1));
assertEquals(2, bindRequest.getMessageId());
assertTrue(bindRequest.isVersion3());
assertEquals("uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString());
assertTrue(bindRequest.isSimple());
assertEquals("password", Strings.utf8ToString(bindRequest.getCredentials()));
}
use of org.apache.directory.api.ldap.model.message.BindRequest in project directory-ldap-api by apache.
the class LdapDecoderTest method testDecodeSplittedPDU.
/**
* Test the decoding of a splitted PDU
*/
@Test
public void testDecodeSplittedPDU() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(16);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x33, 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', '=' });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode a BindRequest PDU first block of data
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.VALUE_STATE_PENDING, container.getState());
// Second block of data
stream = ByteBuffer.allocate(37);
stream.put(new byte[] { 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', // authentication
'd', // authentication
'c', // authentication
'=', // authentication
'c', // authentication
'o', // authentication
'm', // authentication
(byte) 0x80, // authentication
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r', 'd' });
stream.flip();
// Decode a BindRequest PDU second block of data
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(container.getState(), TLVStateEnum.PDU_DECODED);
// Check the decoded PDU
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()));
}
use of org.apache.directory.api.ldap.model.message.BindRequest in project directory-ldap-api by apache.
the class BatchRequestTest method testResponseWith1AuthRequest.
/**
* Test parsing of a Request with 1 AuthRequest
*/
@Test
public void testResponseWith1AuthRequest() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(BatchRequestTest.class.getResource("request_with_1_AuthRequest.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BatchRequestDsml batchRequest = parser.getBatchRequest();
assertEquals(1, batchRequest.getRequests().size());
if (batchRequest.getCurrentRequest() instanceof BindRequest) {
assertTrue(true);
} else {
fail();
}
}
use of org.apache.directory.api.ldap.model.message.BindRequest in project directory-ldap-api by apache.
the class AuthRequestTest method testRequestWith1ControlBase64Value.
/**
* Test parsing of a request with a (optional) Control element with Base64 value
*/
@Test
public void testRequestWith1ControlBase64Value() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(AuthRequestTest.class.getResource("request_with_1_control_base64_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BindRequest abandonRequest = (BindRequest) parser.getBatchRequest().getCurrentRequest();
Map<String, Control> controls = abandonRequest.getControls();
assertEquals(1, abandonRequest.getControls().size());
Control control = controls.get("1.2.840.113556.1.4.643");
assertNotNull(control);
assertTrue(control.isCritical());
assertEquals("1.2.840.113556.1.4.643", control.getOid());
assertEquals("DSMLv2.0 rocks!!", Strings.utf8ToString(((DsmlControl<?>) control).getValue()));
}
use of org.apache.directory.api.ldap.model.message.BindRequest in project directory-ldap-api by apache.
the class AuthRequestTest method testRequestWith2Controls.
/**
* Test parsing of a request with 2 (optional) Control elements
*/
@Test
public void testRequestWith2Controls() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(AuthRequestTest.class.getResource("request_with_2_controls.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BindRequest abandonRequest = (BindRequest) parser.getBatchRequest().getCurrentRequest();
Map<String, Control> controls = abandonRequest.getControls();
assertEquals(2, abandonRequest.getControls().size());
Control control = controls.get("1.2.840.113556.1.4.789");
assertNotNull(control);
assertFalse(control.isCritical());
assertEquals("1.2.840.113556.1.4.789", control.getOid());
assertEquals("Some other text", Strings.utf8ToString(((DsmlControl<?>) control).getValue()));
}
Aggregations