Java Code Examples for org.apache.directory.server.core.api.filtering.EntryFilteringCursor#beforeFirst()
The following examples show how to use
org.apache.directory.server.core.api.filtering.EntryFilteringCursor#beforeFirst() .
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: LDAPIAMPoller.java From aws-iam-ldap-bridge with Apache License 2.0 | 6 votes |
private void clearDN(String dnStr) throws LdapException, ParseException, IOException, CursorException { Dn dn = directory.getDnFactory().create(dnStr); dn.apply(directory.getSchemaManager()); ExprNode filter = FilterParser.parse(directory.getSchemaManager(), "(ObjectClass=*)"); NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( directory.getSchemaManager() ); FilterNormalizingVisitor visitor = new FilterNormalizingVisitor( ncn, directory.getSchemaManager() ); filter.accept(visitor); SearchOperationContext context = new SearchOperationContext(directory.getAdminSession(), dn, SearchScope.SUBTREE, filter, SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES); EntryFilteringCursor cursor = directory.getPartitionNexus().search(context); cursor.beforeFirst(); Collection<Dn> dns = new ArrayList<Dn>(); while (cursor.next()) { Entry ent = cursor.get(); if (ent.getDn().equals(dn)) continue; dns.add(ent.getDn()); } cursor.close(); LOG.debug("Deleting " + dns.size() + " items from under " + dnStr); for (Dn deleteDn: dns) { directory.getAdminSession().delete(deleteDn); } }
Example 2
Source File: LDAPIAMPoller.java From aws-iam-ldap-bridge with Apache License 2.0 | 6 votes |
private Collection<Entry> getAllEntries(String rootDN, String className) { try { Dn dn = directory.getDnFactory().create(rootDN); dn.apply(directory.getSchemaManager()); ExprNode filter = FilterParser.parse(directory.getSchemaManager(), String.format("(ObjectClass=%s)", className)); NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( directory.getSchemaManager() ); FilterNormalizingVisitor visitor = new FilterNormalizingVisitor( ncn, directory.getSchemaManager() ); filter.accept(visitor); SearchOperationContext context = new SearchOperationContext(directory.getAdminSession(), dn, SearchScope.SUBTREE, filter, SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES); EntryFilteringCursor cursor = directory.getPartitionNexus().search(context); cursor.beforeFirst(); Collection<Entry> entries = new ArrayList<Entry>(); while (cursor.next()) { Entry ent = cursor.get(); if (ent.getDn().equals(dn)) continue; entries.add(ent); } cursor.close(); return entries; } catch (Throwable e) { return Collections.emptyList(); } }
Example 3
Source File: SearchRequestHandler.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * Conducts a simple search across the result set returning each entry * back except for the search response done. This is calculated but not * returned so the persistent search mechanism can leverage this method * along with standard search.<br> * <br> * @param session the LDAP session object for this request * @param req the search request * @return the result done * @throws Exception if there are failures while processing the request */ private SearchResultDone doSimpleSearch( LdapSession session, SearchRequest req ) throws Exception { LdapResult ldapResult = req.getResultResponse().getLdapResult(); // Check if we are using the Paged Search Control Object control = req.getControls().get( PagedResults.OID ); if ( control != null ) { // Let's deal with the pagedControl return doPagedSearch( session, req, ( PagedResultsDecorator ) control ); } // A normal search // Check that we have a cursor or not. // No cursor : do a search. EntryFilteringCursor cursor = session.getCoreSession().search( req ); // register the request in the session session.registerSearchRequest( req, cursor ); // Position the cursor at the beginning cursor.beforeFirst(); /* * Iterate through all search results building and sending back responses * for each search result returned. */ try { // Get the size limits // Don't bother setting size limits for administrators that don't ask for it long serverLimit = getServerSizeLimit( session, req ); long requestLimit = req.getSizeLimit() == 0L ? Long.MAX_VALUE : req.getSizeLimit(); req.addAbandonListener( new SearchAbandonListener( ldapServer, cursor ) ); setTimeLimitsOnCursor( req, session, cursor ); if ( IS_DEBUG ) { LOG.debug( "using <{},{}> for size limit", requestLimit, serverLimit ); } long sizeLimit = min( requestLimit, serverLimit ); writeResults( session, req, ldapResult, cursor, sizeLimit ); } finally { if ( ( cursor != null ) && !cursor.isClosed() ) { try { cursor.close(); } catch ( Exception e ) { LOG.error( I18n.err( I18n.ERR_168 ), e ); } } } return req.getResultResponse(); }