Search in sources :

Example 11 with BindResponseImpl

use of org.apache.directory.api.ldap.model.message.BindResponseImpl in project directory-ldap-api by apache.

the class BindRequestTest method testDecodeBindRequestBadDN.

/**
 * Test the decoding of a BindRequest with Simple authentication and
 * controls
 */
@Test
public void testDecodeBindRequestBadDN() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x35);
    stream.put(new byte[] { 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 AuthenticationChoice
    0x08, // ...
    'p', 'a', 's', 's', 'w', 'o', 'r', 'd' });
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<MessageDecorator<? extends Message>> container = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
    // Decode the BindRequest PDU
    try {
        ldapDecoder.decode(stream, container);
        BindRequest bindRequest = ((BindRequestDecorator) container.getMessage());
        assertNull(bindRequest.getDn());
        assertEquals("uid:akarasulu,dc=example,dc=com", bindRequest.getName());
    } catch (DecoderException de) {
        assertTrue(de instanceof ResponseCarryingException);
        Message response = ((ResponseCarryingException) de).getResponse();
        assertTrue(response instanceof BindResponseImpl);
        assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((BindResponseImpl) response).getLdapResult().getResultCode());
        return;
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) MessageDecorator(org.apache.directory.api.ldap.codec.api.MessageDecorator) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) Message(org.apache.directory.api.ldap.model.message.Message) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) BindResponseImpl(org.apache.directory.api.ldap.model.message.BindResponseImpl) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 12 with BindResponseImpl

use of org.apache.directory.api.ldap.model.message.BindResponseImpl in project directory-ldap-api by apache.

the class BindRequestTest method testDecodeBindRequestEmptySasl.

/**
 * Test the decoding of a BindRequest with an empty sasl
 */
@Test
public void testDecodeBindRequestEmptySasl() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x0E);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x0C, 0x02, 0x01, // messageID MessageID
    0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
    0x07, 0x02, 0x01, // version INTEGER (1..127),
    0x03, 0x04, 0x00, (byte) 0xA3, 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(de instanceof ResponseCarryingException);
        Message response = ((ResponseCarryingException) de).getResponse();
        assertTrue(response instanceof BindResponseImpl);
        assertEquals(ResultCodeEnum.INVALID_CREDENTIALS, ((BindResponseImpl) response).getLdapResult().getResultCode());
        return;
    }
    fail("We should not reach this point");
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) Message(org.apache.directory.api.ldap.model.message.Message) BindRequestDecorator(org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) BindResponseImpl(org.apache.directory.api.ldap.model.message.BindResponseImpl) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

BindResponseImpl (org.apache.directory.api.ldap.model.message.BindResponseImpl)12 Test (org.junit.Test)10 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)3 ByteBuffer (java.nio.ByteBuffer)2 DecoderException (org.apache.directory.api.asn1.DecoderException)2 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)2 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)2 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)2 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)2 LdapResultImpl (org.apache.directory.api.ldap.model.message.LdapResultImpl)2 Message (org.apache.directory.api.ldap.model.message.Message)2 Referral (org.apache.directory.api.ldap.model.message.Referral)2 ReferralImpl (org.apache.directory.api.ldap.model.message.ReferralImpl)2 Dn (org.apache.directory.api.ldap.model.name.Dn)2 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)1 MessageDecorator (org.apache.directory.api.ldap.codec.api.MessageDecorator)1 BindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator)1 BindResponseDecorator (org.apache.directory.api.ldap.codec.decorators.BindResponseDecorator)1