Search in sources :

Example 1 with SearchResultDoneImpl

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

the class StoreSearchRequestBaseObject method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequestDecorator searchRequestDecorator = container.getMessage();
    SearchRequest searchRequest = searchRequestDecorator.getDecorated();
    TLV tlv = container.getCurrentTLV();
    // We have to check that this is a correct Dn
    Dn baseObject;
    // root.
    if (tlv.getLength() != 0) {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            baseObject = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid root Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            SearchResultDoneImpl response = new SearchResultDoneImpl(searchRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
    } else {
        baseObject = Dn.EMPTY_DN;
    }
    searchRequest.setBase(baseObject);
    LOG.debug("Searching with root Dn : {}", baseObject);
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) SearchResultDoneImpl(org.apache.directory.api.ldap.model.message.SearchResultDoneImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 2 with SearchResultDoneImpl

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

the class InitSearchResultDone method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchResultDoneDecorator> container) {
    // Now, we can allocate the SearchResultDone Object
    SearchResultDoneDecorator searchResultDone = new SearchResultDoneDecorator(container.getLdapCodecService(), new SearchResultDoneImpl(container.getMessageId()));
    container.setMessage(searchResultDone);
    LOG.debug("Search Result Done found");
}
Also used : SearchResultDoneImpl(org.apache.directory.api.ldap.model.message.SearchResultDoneImpl) SearchResultDoneDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator)

Example 3 with SearchResultDoneImpl

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

the class SearchRequestTest method testDecodeSearchRequestGlobalBadObjectBase.

/**
 * Test the decoding of a SearchRequest with a bad objectBase
 */
@Test
public void testDecodeSearchRequestGlobalBadObjectBase() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x90);
    stream.put(new byte[] { 0x30, (byte) 0x81, // LDAPMessage ::=SEQUENCE {
    (byte) 0x8D, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, (byte) 0x81, // CHOICE { ...,
    (byte) 0x87, // SearchRequest ::= APPLICATION[3] SEQUENCE {
    0x04, // baseObject 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', 0x0A, 0x01, // scope ENUMERATED {
    0x01, // wholeSubtree (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // derefAlways (3) },
    0x02, 0x02, 0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
    (byte) 0xE8, 0x02, 0x02, 0x03, // timeLimit INTEGER (0 .. maxInt), (1000)
    (byte) 0xE8, 0x01, 0x01, // typesOnly  BOOLEAN, (TRUE)
    (byte) 0xFF, // filter Filter,
    (byte) 0xA0, // Filter ::= CHOICE {
    0x3C, // and [0] SET OF Filter,
    (byte) 0xA1, // or [1] SET of Filter,
    0x24, (byte) 0xA3, // equalityMatch [3]
    0x12, // attributeDesc AttributeDescription (LDAPString),
    0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
    0x04, 0x03, 't', 'o', 'p', (byte) 0xA3, // equalityMatch [3] Assertion,
    0x0E, // Assertion ::= SEQUENCE {
    0x04, 0x02, 'o', // attributeDesc AttributeDescription (LDAPString),
    'u', // assertionValue AssertionValue (OCTET STRING) }
    0x04, 0x08, 'c', 'o', 'n', 't', 'a', 'c', 't', 's', (byte) 0xA2, // not [2] Filter,
    0x14, (byte) 0xA3, // equalityMatch [3] Assertion,
    0x12, // attributeDesc AttributeDescription (LDAPString),
    0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
    0x04, 0x03, 't', 't', 't', // attributes AttributeDescriptionList }
    0x30, // AttributeDescriptionList ::= SEQUENCE OF
    0x15, // AttributeDescription
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::= LDAPString
    '0', 0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::= LDAPString
    '1', 0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::= LDAPString
    '2' });
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        assertTrue(de instanceof ResponseCarryingException);
        Message response = ((ResponseCarryingException) de).getResponse();
        assertTrue(response instanceof SearchResultDoneImpl);
        assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((SearchResultDoneImpl) 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) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) SearchResultDoneImpl(org.apache.directory.api.ldap.model.message.SearchResultDoneImpl) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

SearchResultDoneImpl (org.apache.directory.api.ldap.model.message.SearchResultDoneImpl)3 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)2 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)2 ByteBuffer (java.nio.ByteBuffer)1 DecoderException (org.apache.directory.api.asn1.DecoderException)1 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)1 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)1 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)1 SearchResultDoneDecorator (org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator)1 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 Message (org.apache.directory.api.ldap.model.message.Message)1 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1 Test (org.junit.Test)1