Refine search
/** * Allows for custom processing of the search results. * @param processor {@link RecordProcessor} implementation * @throws NamingException */ public void handle(RecordProcessor processor) throws NamingException { try { for (NamingEnumeration<SearchResult> searchResult : searchResults) { while (searchResult.hasMore()) { if (!processor.process(searchResult.next())) { return; } } } } finally { for (NamingEnumeration<SearchResult> searchResult : searchResults) { try { searchResult.close(); } catch (NamingException ex) { LOG.warn("Failed to close LDAP search result", ex); } } } }
@Override public boolean engineContainsAlias(String alias) { DirContext context = obtainDirContext(); if (context == null) { log.trace("Unable to obtain DirContext"); return false; } try { NamingEnumeration<SearchResult> results = context.search(searchPath, filterAlias, new String[]{alias}, createSearchControl(new String[]{aliasAttribute})); boolean found = results.hasMore(); results.close(); return found; } catch (NamingException e) { throw log.ldapKeyStoreFailedToTestAliasExistence(alias, e); } finally { returnDirContext(context); } }
ldapContext = buildLdapContext(); ldapResult = ldapContext.search(context, filterExpr, filterArgs, createSearchControls()); while (ldapResult.hasMore()) { searchResults.add(ldapResult.next()); if (ldapResult != null) { try { ldapResult.close(); } catch (NamingException ex) { log.error("Failed to close LDAP results enumeration", ex);
while (answer.hasMoreElements()) { Attributes attributes = ((SearchResult) answer.next()).getAttributes(); String groupName = (String) attributes.get(manager.getGroupNameField()).get(); String description = ""; if (memberField != null) { NamingEnumeration ne = memberField.getAll(); while (ne.hasMore()) { ne.next(); elements = elements + 1; answer.close();
/** * Checks to see if an entry being renamed has a descendant that is an * administrative point. * * @param name the name of the entry which is used as the search base * @return true if name is an administrative point or one of its descendants * are, false otherwise * @throws NamingException if there are errors while searching the directory */ private boolean hasAdministrativeDescendant( LdapDN name ) throws NamingException { ExprNode filter = new PresenceNode( "administrativeRole" ); SearchControls controls = new SearchControls(); controls.setSearchScope( SearchControls.SUBTREE_SCOPE ); NamingEnumeration aps = nexus.search( name, factoryCfg.getEnvironment(), filter, controls ); if ( aps.hasMore() ) { aps.close(); return true; } return false; }
private boolean filterByGroup(AutoclosingLdapContext context, String sanitizedUsername) throws NamingException { final Set<String> restrictedToGroups = configuration.getRestrictToGroups(); if (restrictedToGroups.isEmpty()) { return true; } final StringBuilder groupFilter = new StringBuilder(); for (String group : restrictedToGroups) { final String sanitizedGroup = sanitizeEntity(group); groupFilter.append(String.format("(%s=%s)", configuration.getGroupNameAttribute(), sanitizedGroup)); } final String filter = String.format("(&(%s=%s)(|%s))", configuration.getGroupMembershipAttribute(), userNameBaseOnGroupClass(sanitizedUsername), groupFilter.toString()); final NamingEnumeration<SearchResult> result = context.search(configuration.getGroupFilter(), filter, new SearchControls()); try { return result.hasMore(); } finally { result.close(); } }
// get the default initial Directory Context InitialDirContext idc = new InitialDirContext(); // get the DNS records for inetAddress Attributes attributes = idc.getAttributes("dns:/" + inetAddress.getHostName()); // get an enumeration of the attributes and print them out NamingEnumeration attributeEnumeration = attributes.getAll(); System.out.println("-- DNS INFORMATION --"); while (attributeEnumeration.hasMore()) { System.out.println("" + attributeEnumeration.next()); } attributeEnumeration.close();
@Override public boolean engineContainsAlias(String alias) { DirContext context = obtainDirContext(); if (context == null) { log.trace("Unable to obtain DirContext"); return false; } try { NamingEnumeration<SearchResult> results = context.search(searchPath, filterAlias, new String[]{alias}, createSearchControl(new String[]{aliasAttribute})); boolean found = results.hasMore(); results.close(); return found; } catch (NamingException e) { throw log.ldapKeyStoreFailedToTestAliasExistence(alias, e); } finally { returnDirContext(context); } }
private static String getUid (String username) throws Exception { DirContext ctx = ldapContext(); String filter = String.format(config.searchFilter, username); SearchControls ctrl = new SearchControls(); ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration answer = ctx.search(config.searchBase, filter, ctrl); String dn; if (answer.hasMore()) { SearchResult result = (SearchResult) answer.next(); dn = result.getNameInNamespace(); } else { dn = null; } answer.close(); return dn; }
/** * Returns a flag whether this configuration is empty. * * @return the empty flag */ public boolean isEmpty() { try { NamingEnumeration enumeration = null; try { enumeration = getBaseContext().list(""); return !enumeration.hasMore(); } finally { // close the enumeration if (enumeration != null) { enumeration.close(); } } } catch (NamingException e) { fireError(EVENT_READ_PROPERTY, null, null, e); return true; } }