Search in sources :

Example 41 with SearchRequestDecorator

use of org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator in project directory-ldap-api by apache.

the class SearchRequestMatchingRuleAssertionTest method testDecodeSearchRequestEmptyExtensibleMatch.

/**
 * Test the decoding of a SearchRequest with an empty extensible match
 */
@Test
public void testDecodeSearchRequestEmptyExtensibleMatch() {
    byte[] asn1BER = new byte[] { 0x30, 0x3B, 0x02, 0x01, // messageID
    0x04, 0x63, // baseObject LDAPDN,
    0x36, 0x04, 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, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x01, 0x01, (byte) 0xFF, (byte) 0xA9, 0x00, 0x30, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
    0x02, 0x04, 0x00 };
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
    stream.put(asn1BER);
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    // Decode a SearchRequest message
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        assertTrue(true);
        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) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) 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)

Example 42 with SearchRequestDecorator

use of org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator in project directory-ldap-api by apache.

the class ApiLdapCodecCoreOsgiTest method useBundleClasses.

@Override
protected void useBundleClasses() throws Exception {
    LdapStatesEnum.END_STATE.isEndState();
    new InitBindRequest();
    new InitBindResponse();
    new InitAddRequest();
    new InitAddResponse();
    new InitSearchRequest();
    new InitSearchResultDone();
    new AndFilter();
    new SubstringFilter();
    SearchRequest decoratedMessage = new SearchRequestImpl();
    new SearchRequestDecorator(ldapApiService, decoratedMessage);
}
Also used : AndFilter(org.apache.directory.api.ldap.codec.search.AndFilter) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) InitSearchRequest(org.apache.directory.api.ldap.codec.actions.request.search.InitSearchRequest) InitBindResponse(org.apache.directory.api.ldap.codec.actions.response.bind.InitBindResponse) InitBindRequest(org.apache.directory.api.ldap.codec.actions.request.bind.InitBindRequest) InitSearchRequest(org.apache.directory.api.ldap.codec.actions.request.search.InitSearchRequest) SubstringFilter(org.apache.directory.api.ldap.codec.search.SubstringFilter) InitAddRequest(org.apache.directory.api.ldap.codec.actions.request.add.InitAddRequest) SearchRequestImpl(org.apache.directory.api.ldap.model.message.SearchRequestImpl) InitAddResponse(org.apache.directory.api.ldap.codec.actions.response.add.InitAddResponse) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) InitSearchResultDone(org.apache.directory.api.ldap.codec.actions.response.search.done.InitSearchResultDone)

Example 43 with SearchRequestDecorator

use of org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator in project directory-ldap-api by apache.

the class InitSearchRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) {
    // Now, we can allocate the SearchRequest Object
    TLV tlv = container.getCurrentTLV();
    SearchRequest internalSearchRequest = new SearchRequestImpl();
    internalSearchRequest.setMessageId(container.getMessageId());
    SearchRequestDecorator searchRequest = new SearchRequestDecorator(container.getLdapCodecService(), internalSearchRequest);
    searchRequest.setTlvId(tlv.getId());
    container.setMessage(searchRequest);
    LOG.debug("Search Request");
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SearchRequestImpl(org.apache.directory.api.ldap.model.message.SearchRequestImpl) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 44 with SearchRequestDecorator

use of org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator 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 45 with SearchRequestDecorator

use of org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator in project directory-ldap-api by apache.

the class InitAndFilter method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04006);
        LOG.error(msg);
        throw new DecoderException(msg);
    }
    SearchRequestDecorator searchRequestDecorator = container.getMessage();
    // We can allocate the SearchRequest
    Filter andFilter = new AndFilter(container.getTlvId());
    // Set the filter
    searchRequestDecorator.addCurrentFilter(andFilter);
    if (IS_DEBUG) {
        LOG.debug("Initialize AND filter");
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) AndFilter(org.apache.directory.api.ldap.codec.search.AndFilter) Filter(org.apache.directory.api.ldap.codec.search.Filter) AndFilter(org.apache.directory.api.ldap.codec.search.AndFilter) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Aggregations

SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)110 DecoderException (org.apache.directory.api.asn1.DecoderException)97 ByteBuffer (java.nio.ByteBuffer)85 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)85 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)85 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)85 Test (org.junit.Test)85 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)48 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)37 EncoderException (org.apache.directory.api.asn1.EncoderException)33 AndNode (org.apache.directory.api.ldap.model.filter.AndNode)19 EqualityNode (org.apache.directory.api.ldap.model.filter.EqualityNode)18 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)17 SubstringNode (org.apache.directory.api.ldap.model.filter.SubstringNode)12 OrNode (org.apache.directory.api.ldap.model.filter.OrNode)10 Filter (org.apache.directory.api.ldap.codec.search.Filter)9 PresenceNode (org.apache.directory.api.ldap.model.filter.PresenceNode)9 SubstringFilter (org.apache.directory.api.ldap.codec.search.SubstringFilter)6 GreaterEqNode (org.apache.directory.api.ldap.model.filter.GreaterEqNode)6 NotNode (org.apache.directory.api.ldap.model.filter.NotNode)6