Java Code Examples for org.apache.directory.api.ldap.model.message.SearchRequest#setSizeLimit()

The following examples show how to use org.apache.directory.api.ldap.model.message.SearchRequest#setSizeLimit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public <T> T searchFirst( SearchRequest searchRequest,
    EntryMapper<T> entryMapper )
{
    // in case the caller did not set size limit, we cache original value,
    // set to 1, then set back to original value before returning...
    long originalSizeLimit = searchRequest.getSizeLimit();
    try
    {
        searchRequest.setSizeLimit( 1 );
        List<T> entries = search( searchRequest, entryMapper );
        return entries.isEmpty() ? null : entries.get( 0 );
    }
    finally
    {
        searchRequest.setSizeLimit( originalSizeLimit );
    }
}
 
Example 2
Source File: LDAPConnectionService.java    From guacamole-client with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a SearchRequest object using the given Base DN and filter
 * and retrieving other properties from the LDAP configuration service.
 * 
 * @param baseDn
 *     The LDAP Base DN at which to search the search.
 * 
 * @param filter
 *     A string representation of a LDAP filter to use for the search.
 * 
 * @return
 *     The properly-configured SearchRequest object.
 * 
 * @throws GuacamoleException
 *     If an error occurs retrieving any of the configuration values.
 */
public SearchRequest getSearchRequest(Dn baseDn, ExprNode filter)
        throws GuacamoleException {
    
    SearchRequest searchRequest = new SearchRequestImpl();
    searchRequest.setBase(baseDn);
    searchRequest.setDerefAliases(confService.getDereferenceAliases());
    searchRequest.setScope(SearchScope.SUBTREE);
    searchRequest.setFilter(filter);
    searchRequest.setSizeLimit(confService.getMaxResults());
    searchRequest.setTimeLimit(confService.getOperationTimeout());
    searchRequest.setTypesOnly(false);
    
    if (confService.getFollowReferrals())
        searchRequest.followReferrals();
    
    return searchRequest;
}
 
Example 3
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * Perform normal ldap search specifying default batch size and max entries to return.
 *
 * @param connection is LdapConnection object used for all communication with host.
 * @param baseDn     contains address of distinguished name to begin ldap search
 * @param scope      indicates depth of search starting at basedn.  0 (base dn),
 *                   1 (one level down) or 2 (infinite) are valid values.
 * @param filter     contains the search criteria
 * @param attrs      is the requested list of attritubutes to return from directory search.
 * @param attrsOnly  if true pull back attribute names only.
 * @param maxEntries specifies the maximum number of entries to return in this search query.
 * @return result set containing ldap entries returned from directory.
 * @throws LdapException thrown in the event of error in ldap client or server code.
 */
protected SearchCursor search( LdapConnection connection, String baseDn, SearchScope scope, String filter,
    String[] attrs, boolean attrsOnly, int maxEntries ) throws LdapException
{
    COUNTERS.incrementSearch();

    SearchRequest searchRequest = new SearchRequestImpl();

    searchRequest.setBase( new Dn( baseDn ) );
    searchRequest.setFilter( filter );
    searchRequest.setScope( scope );
    searchRequest.setSizeLimit( maxEntries );
    searchRequest.setTypesOnly( attrsOnly );
    searchRequest.addAttributes( attrs );

    return connection.search( searchRequest );
}
 
Example 4
Source File: LDAPConnectionService.java    From guacamole-client with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a SearchRequest object using the given Base DN and filter
 * and retrieving other properties from the LDAP configuration service.
 * 
 * @param baseDn
 *     The LDAP Base DN at which to search the search.
 * 
 * @param filter
 *     A string representation of a LDAP filter to use for the search.
 * 
 * @return
 *     The properly-configured SearchRequest object.
 * 
 * @throws GuacamoleException
 *     If an error occurs retrieving any of the configuration values.
 */
public SearchRequest getSearchRequest(Dn baseDn, ExprNode filter)
        throws GuacamoleException {
    
    SearchRequest searchRequest = new SearchRequestImpl();
    searchRequest.setBase(baseDn);
    searchRequest.setDerefAliases(confService.getDereferenceAliases());
    searchRequest.setScope(SearchScope.SUBTREE);
    searchRequest.setFilter(filter);
    searchRequest.setSizeLimit(confService.getMaxResults());
    searchRequest.setTimeLimit(confService.getOperationTimeout());
    searchRequest.setTypesOnly(false);
    
    if (confService.getFollowReferrals())
        searchRequest.followReferrals();
    
    return searchRequest;
}
 
Example 5
Source File: StoreSearchRequestSizeLimit.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<SearchRequest> container ) throws DecoderException
{
    SearchRequest searchRequest = container.getMessage();

    TLV tlv = container.getCurrentTLV();

    // The current TLV should be a integer
    // We get it and store it in sizeLimit
    BerValue value = tlv.getValue();

    try
    {
        long sizeLimit = LongDecoder.parse( value, 0, Integer.MAX_VALUE );
        searchRequest.setSizeLimit( sizeLimit );
    }
    catch ( LongDecoderException lde )
    {
        String msg = I18n.err( I18n.ERR_05151_BAD_SIZE_LIMIT, value.toString() );
        LOG.error( msg );
        throw new DecoderException( msg, lde );
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05163_SIZE_LIMIT_SET_TO, searchRequest.getSizeLimit() ) );
    }
}