org.apache.directory.api.ldap.model.cursor.SearchCursor Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.cursor.SearchCursor. 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: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public SearchCursor search( SearchRequest searchRequest ) throws LdapException
{
    if ( searchRequest == null )
    {
        String msg = I18n.err( I18n.ERR_04130_CANNOT_PROCESS_NULL_SEARCH_REQ );
        
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( msg );
        }
        
        throw new IllegalArgumentException( msg );
    }

    SearchFuture searchFuture = searchAsync( searchRequest );

    long searchTimeout = getTimeout( timeout, searchRequest.getTimeLimit() );

    return new SearchCursorImpl( searchFuture, searchTimeout, TimeUnit.MILLISECONDS );
}
 
Example #2
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 #3
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * This method will search the directory and return at most one record.  If more than one record is found
 * an ldap exception will be thrown.
 *
 * @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.
 * @return entry   containing target ldap node.
 * @throws LdapException   thrown in the event of error in ldap client or server code.
 * @throws CursorException If we weren't able to fetch an element from the search result
 */
protected Entry searchNode( LdapConnection connection, String baseDn, SearchScope scope, String filter,
    String[] attrs, boolean attrsOnly ) throws LdapException, CursorException
{
    SearchRequest searchRequest = new SearchRequestImpl();

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

    SearchCursor result = connection.search( searchRequest );

    Entry entry = result.getEntry();

    if ( result.next() )
    {
        throw new LdapException( "searchNode failed to return unique record for LDAP search of base DN [" +
            baseDn + "] filter [" + filter + "]" );
    }

    return entry;
}
 
Example #4
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * This search method uses OpenLDAP Proxy Authorization Control to assert arbitrary user identity onto connection.
 *
 * @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 userDn     string value represents the identity of user on who's behalf the request was initiated.  The
 *                   value will be stored in openldap auditsearch record AuthZID's attribute.
 * @return entry   containing target ldap node.
 * @throws LdapException   thrown in the event of error in ldap client or server code.
 * @throws CursorException If we weren't able to fetch an element from the search result
 */
protected Entry searchNode( LdapConnection connection, String baseDn, SearchScope scope, String filter,
    String[] attrs, boolean attrsOnly, String userDn ) throws LdapException, CursorException
{
    COUNTERS.incrementSearch();

    SearchRequest searchRequest = new SearchRequestImpl();

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

    SearchCursor result = connection.search( searchRequest );

    Entry entry = result.getEntry();

    if ( result.next() )
    {
        throw new LdapException( "searchNode failed to return unique record for LDAP search of base DN [" +
            baseDn + "] filter [" + filter + "]" );
    }

    return entry;
}
 
Example #5
Source File: EntryCursorImpl.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new search cursor, embedding a SearchCursor.
 *
 * @param searchCursor the embedded SearchResponse cursor
 */
public EntryCursorImpl( SearchCursor searchCursor )
{
    if ( LOG_CURSOR.isDebugEnabled() )
    {
        LOG_CURSOR.debug( I18n.msg( I18n.MSG_04161_CREATING_ENTRY_CURSOR, this ) );
    }

    this.searchCursor = searchCursor;
    messageId = -1;
}
 
Example #6
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Perform normal ldap search accepting default batch size.
 *
 * @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.
 * @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 ) throws LdapException
{
    COUNTERS.incrementSearch();

    SearchRequest searchRequest = new SearchRequestImpl();
    searchRequest.setBase( new Dn( baseDn ) );
    searchRequest.setScope( scope );
    searchRequest.setFilter( filter );
    searchRequest.setTypesOnly( attrsOnly );
    searchRequest.addAttributes( attrs );

    return connection.search( searchRequest );
}
 
Example #7
Source File: LdapConnectionWrapper.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public SearchCursor search( SearchRequest searchRequest ) throws LdapException
{
    return connection.search( searchRequest );
}
 
Example #8
Source File: LdapConnection.java    From directory-ldap-api with Apache License 2.0 2 votes vote down vote up
/**
 * Performs search using a search request object.
 *
 * @param searchRequest The search request object containing all the needed information
 * @return a search cursor on the result.
 * @throws LdapException if some error occurred
 */
SearchCursor search( SearchRequest searchRequest ) throws LdapException;