final EntryCursor userCursor = connection.search(configuration.getUserBaseDN(), String.format(configuration.getUserFilter(), user), SearchScope.ONELEVEL, configuration.getUserNameAttribute(), configuration.getUserEmailAttribute()); final EntryCursor cursor = connection.search(configuration.getGroupBaseDN(), String.format(configuration.getGroupFilter(), user), configuration.getGroupSearchScope(), configuration.getGroupNameAttribute());
/** * {@inheritDoc} */ @Override public EntryCursor search( String baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException { return connection.search( baseDn, filter, scope, attributes ); }
/** * {@inheritDoc} */ @Override public SearchCursor search( SearchRequest searchRequest ) throws LdapException { return connection.search( searchRequest ); }
/** * {@inheritDoc} */ @Override public SearchCursor search( SearchRequest searchRequest ) throws LdapException { return connection.search( searchRequest ); }
/** * {@inheritDoc} */ @Override public EntryCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException { return connection.search( baseDn, filter, scope, attributes ); }
/** * {@inheritDoc} */ @Override public EntryCursor search( String baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException { return connection.search( baseDn, filter, scope, attributes ); }
/** * {@inheritDoc} */ @Override public EntryCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException { return connection.search( baseDn, filter, scope, attributes ); }
/** * {@inheritDoc} */ @Override public EntryCursor search( Dn baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException { return connection.search( baseDn, filter, scope, attributes ); }
/** * {@inheritDoc} */ @Override public EntryCursor search( String baseDn, String filter, SearchScope scope, String... attributes ) throws LdapException { return connection.search( baseDn, filter, scope, attributes ); }
/** * {@inheritDoc} */ @Override public SearchCursor search( SearchRequest searchRequest ) throws LdapException { return connection.search( searchRequest ); }
@JsonIgnore public Entry getEntry(final LdapConnection connection, final String filter, final String... attributes) throws LdapException, CursorException, IOException { connection.bind(); try (final EntryCursor cursor = connection.search(baseDn, filter, SearchScope.SUBTREE, attributes)) { if (!cursor.next()) return null; return cursor.get(); } }
void findEntry(LdapConnection connection, Entry entry, StringBuilder sb) throws LdapException, CursorException { sb.append(LdifUtils.convertToLdif(entry)); sb.append("\n"); EntryCursor cursor = connection.search(entry.getDn(), "(ObjectClass=*)", SearchScope.ONELEVEL, "*", "+"); while (cursor.next()) { findEntry(connection, cursor.get(), sb); } }
/** * Get child list * * @param entryDN The distinguished name of an Entry in the LDAP * @param connection An initialized LDAP-Context * @return All child's of an Entry * @throws IOException * @throws CursorException * @throws LdapException */ private List<String> getChildList(String entryDN, LdapConnection connection) throws CursorException, IOException, LdapException { List<String> childs = new ArrayList<String>(); EntryCursor cursor = connection.search("ou=system", "(objectclass=*)", SearchScope.ONELEVEL); while (cursor.next()) { Entry entry = cursor.get(); childs.add(entry.get("distinguishedName").getString()); } //SearchResultDone done = cursor.getSearchResultDone(); //ResultCodeEnum resultCode = done.getLdapResult().getResultCode(); cursor.close(); // ResultCodeEnum.SUCCESS == resultCode return childs; }
/** * {@inheritDoc} */ @Override public <T> List<T> search( SearchRequest searchRequest, EntryMapper<T> entryMapper ) { List<T> entries = new ArrayList<>(); LdapConnection connection = null; try { connection = connectionPool.getConnection(); for ( Entry entry : new EntryCursorImpl( connection.search( searchRequest ) ) ) { entries.add( entryMapper.map( entry ) ); } } catch ( LdapException e ) { throw new LdapRuntimeException( e ); } finally { returnLdapConnection( connection ); } return entries; }
/** * searches for an entry having the given DN * * @param dn the DN of the entry to be fetched * @param attributes the attributes to be returned along with entry * @return the Entry with the given DN or null if no entry exists with that DN * @throws LdapException in case of any problems while searching for the DN */ public SearchResponse lookup( String dn, String... attributes ) throws LdapException { SearchResponse resp = null; try { Cursor<SearchResponse> cursor = search( dn, "(objectClass=*)", SearchScope.OBJECT, attributes ); if( cursor.next() ) { resp = cursor.get(); } cursor.close(); } catch( Exception e ) { throw new LdapException( e ); } return resp; }
public List<Entry> search(final LdapConnection connection, final String filter, final int start, final int rows) throws LdapException, CursorException, IOException { connection.bind(); final SearchRequest request = new SearchRequestImpl(); request.setBase(new Dn(baseDn)); request.setFilter(filter); request.setScope(SearchScope.SUBTREE); request.setSizeLimit(start + rows); try (final SearchCursor cursor = connection.search(request)) { while (start > 0 && cursor.next()) ; final List<Entry> entries = new ArrayList<>(); while (rows > 0 && cursor.next()) entries.add(cursor.getEntry()); return entries; } }
/** * Deletes the entire subtree of root but not root itself. Throws NoSuchNodeException if root does not exist. Throws * MissingParentException if some node above root does not exist. * */ public void deleteSubtreeExcludingRoot(Dn root) throws NoSuchNodeException, MissingParentException { existsCheck(root); try { EntryCursor entryCursor = connection.search(root, "(objectclass=*)", SearchScope.ONELEVEL); while (entryCursor.next()) { deleteSubtreeIncludingRoot(entryCursor.get().getDn()); } } catch (Exception e) { throw new LdapDaoException(e); } }
public int count(final LdapConnection connection, final String filter, final int max) throws LdapException, CursorException, IOException { connection.bind(); final SearchRequest request = new SearchRequestImpl(); request.setBase(new Dn(baseDn)); request.setFilter(filter); request.setScope(SearchScope.SUBTREE); request.setSizeLimit(max); try (final SearchCursor cursor = connection.search(request)) { int count = 0; while (cursor.next()) count++; return count; } }
/** * 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 ); }
/** * 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 ); }