@Override public boolean process(SearchResult record) throws NamingException { result.add(record.getNameInNamespace()); NamingEnumeration<? extends Attribute> allAttributes = record.getAttributes().getAll(); while(allAttributes.hasMore()) { Attribute attribute = allAttributes.next(); addAllAttributeValuesToResult(attribute.getAll()); } return true; }
public Object mapFromContext(Object ctx) { DirContextAdapter adapter = (DirContextAdapter) ctx; Map<String, List<String>> record = new HashMap<String, List<String>>(); if (attributeNames == null || attributeNames.length == 0) { try { for (NamingEnumeration ae = adapter.getAttributes().getAll(); ae .hasMore();) { Attribute attr = (Attribute) ae.next(); extractStringAttributeValues(adapter, record, attr.getID()); } } catch (NamingException x) { org.springframework.ldap.support.LdapUtils .convertLdapException(x); } } else { for (String attributeName : attributeNames) { extractStringAttributeValues(adapter, record, attributeName); } } record.put(DN_KEY, Arrays.asList(getAdapterDN(adapter))); set.add(record); return null; } };
private Collection<String> extractGroupNamesFromSearchResult(final SearchResult searchResult) { // Get all attributes for that group final Iterator<? extends Attribute> attributesIterator = Iterators.forEnumeration(searchResult.getAttributes().getAll()); // Find the attribute representing the group name final Iterator<? extends Attribute> groupNameAttributesIterator = Iterators.filter(attributesIterator, new Predicate<Attribute>() { @Override public boolean apply(final Attribute attribute) { return groupNameId.equalsIgnoreCase(attribute.getID()); } }); // Extract the group name from the attribute // Note: at this point, groupNameAttributesIterator should really contain a single element final Iterator<Iterator<?>> groupNamesIterator = Iterators.transform(groupNameAttributesIterator, new Function<Attribute, Iterator<?>>() { @Override public Iterator<?> apply(final Attribute groupNameAttribute) { try { final NamingEnumeration<?> enumeration = groupNameAttribute.getAll(); return Iterators.forEnumeration(enumeration); } catch (final NamingException namingException) { log.warn("Unable to read group name(s)", namingException); return null; } } }); final Iterator<?> finalGroupNamesIterator = Iterators.filter(Iterators.concat(groupNamesIterator), Predicates.notNull()); return ImmutableList.<String>copyOf(Iterators.transform(finalGroupNamesIterator, Functions.toStringFunction())); }
DirContext ctx = new InitialDirContext(env); Attributes attrs = ctx.getAttributes(lookup, new String[] {"PTR"}); for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements();) { Attribute attr = (Attribute) ae.next(); for (Enumeration vals = attr.getAll(); vals.hasMoreElements();) {
NamingEnumeration ae = attrs.getAll(); while (ae.hasMore()) { Attribute attr = (Attribute) ae.next();
protected List<Address> resolveSRVEntries(String dnsQuery) { List<Address> addresses = new ArrayList<>(); try { // We are parsing this kind of structure: // {srv=SRV: 10 100 8888 9089f34a.jgroups-dns-ping.myproject.svc.cluster.local.} // The frst attribute is the type of record. We are not interested in this. Next are addresses. Attributes attributes = dnsContext.getAttributes(dnsQuery, new String[] { DNSRecordType.SRV.toString() }); if (attributes != null && attributes.getAll().hasMoreElements()) { NamingEnumeration<?> namingEnumeration = attributes.get(DNSRecordType.SRV.toString()).getAll(); while (namingEnumeration.hasMoreElements()) { try { String srvEntry = namingEnumeration.nextElement().toString(); Matcher matcher = SRV_REGEXP.matcher(srvEntry); if (matcher.find()) { String srcPort = matcher.group(1); String srcDNSRecord = matcher.group(2); // The implementation here is not optimal but it's easy to read. SRV discovery will be performed // extremely rarely, only when a fine grained discovery using ports is needed (ie: when using containers). addresses.addAll(resolveAEntries(srcDNSRecord, srcPort)); } } catch (Exception e) { log.trace("non critical DNS resolution error", e); } } } } catch (NamingException ex) { log.trace("no DNS records for query %s, ex: %s", dnsQuery, ex.getMessage()); } return addresses; }
@Override protected List<Address> resolveAEntries(String dnsQuery) { List<Address> addresses = new ArrayList<>(); try { // We are parsing this kind of structure: // {a=A: 172.17.0.2, 172.17.0.7} // The frst attribute is the type of record. We are not interested in this. Next are addresses. Attributes attributes = getDnsContext().getAttributes(dnsQuery, new String[] { DNSRecordType.A.toString() }); if (attributes != null && attributes.getAll().hasMoreElements()) { NamingEnumeration<?> namingEnumeration = attributes.get(DNSRecordType.A.toString()).getAll(); while (namingEnumeration.hasMoreElements()) { try { addresses.add(new IpAddress(namingEnumeration.nextElement().toString())); } catch (Exception e) { log.trace("non critical DNS resolution error", e); } } } } catch (NamingException ex) { log.trace("no DNS records for query %s, ex: %a", dnsQuery, ex); } return addresses; } }
while ( ( attributes = getAttributes() ) != null ) { NamingEnumeration<? extends Attribute> ne = attributes.getAll();
private String lookupPtrRecord(String reversedDomain) throws Exception { Attributes attrs = ctx.getAttributes(reversedDomain, new String[] {"PTR"}); for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements(); ) { Attribute attr = (Attribute) ae.next(); for (Enumeration<?> vals = attr.getAll(); vals.hasMoreElements(); ) return vals.nextElement().toString(); } return null; }
NamingEnumeration ae = attrs.getAll(); while (ae.hasMore()) { Attribute attr = (Attribute) ae.next();
new String[] {EWSConstants.SRVRECORD}); if (contextAttributes != null) { NamingEnumeration<?> attributes = contextAttributes.getAll(); if (attributes != null) { while (attributes.hasMore()) {
@Override protected Object doMapFromContext(DirContextOperations ctx) { if (resultFilter != null && !resultFilter.needSelect(ctx.getNameInNamespace())){ return null; } Map<String, Object> result = new HashMap<>(); result.put(LdapConstant.LDAP_DN_KEY, ctx.getNameInNamespace()); List<Object> list = new ArrayList<>(); result.put("attributes", list); Attributes attributes = ctx.getAttributes(); NamingEnumeration it = attributes.getAll(); try { while (it.hasMore()){ list.add(it.next()); } } catch (javax.naming.NamingException e){ logger.error("query ldap entry attributes fail", e.getCause()); throw new OperationFailureException(operr("query ldap entry fail, %s", e.toString())); } return result; } }, processor);
public Object mapFromAttributes(Attributes attrs) throws NamingException { NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); while (attrEnum.hasMore()) { return attrEnum.next().get(); } return null; } };
private String lookupPtrRecord(String reversedDomain) throws Exception { Attributes attrs = ctx.getAttributes(reversedDomain, new String[]{"PTR"}); for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements(); ) { Attribute attr = (Attribute) ae.next(); for (Enumeration<?> vals = attr.getAll(); vals.hasMoreElements(); ) return vals.nextElement().toString(); } return null; }
public Map<String, Attribute> mapFromAttributes(Attributes attrs) throws NamingException { Map<String, Attribute> map = new HashMap<>(); NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); while (attrEnum.hasMore()) { Attribute att = attrEnum.next(); map.put(att.getID(), att); } return map; } };
public Map<String, Attribute> mapFromAttributes(Attributes attrs) throws NamingException { Map<String, Attribute> map = new HashMap<>(); NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); while (attrEnum.hasMore()) { Attribute att = attrEnum.next(); map.put(att.getID(), att); } return map; } };
public Map<String, Attribute> mapFromAttributes(Attributes attrs) throws NamingException { Map<String, Attribute> map = new HashMap<>(); NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); while (attrEnum.hasMore()) { Attribute att = attrEnum.next(); map.put(att.getID(), att); } return map; } };
public Map<String, Attribute> mapFromAttributes(Attributes attrs) throws NamingException { Map<String, Attribute> map = new HashMap<>(); NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); while (attrEnum.hasMore()) { Attribute att = attrEnum.next(); map.put(att.getID(), att); } return map; } };
private static void printAttrs(Attributes attrs) throws NamingException { NamingEnumeration<? extends Attribute> attrsEnum = attrs.getAll(); while (attrsEnum.hasMore()) { Attribute currentAttr = attrsEnum.next(); outstream.print(String.format("%1$s:", currentAttr.getID())); NamingEnumeration<?> valuesEnum = currentAttr.getAll(); while (valuesEnum.hasMoreElements()) { outstream.print(String.format("%1$s ", valuesEnum.nextElement().toString())); } outstream.println(); } }
public Map<String, Attribute> mapFromAttributes(Attributes attrs) throws NamingException { Map<String, Attribute> map = new HashMap<>(); NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); while (attrEnum.hasMore()) { Attribute att = attrEnum.next(); map.put(att.getID(), att); } return map; } };