/** * convert search result into URI * * @param result * search result to convert to URI */ protected URI toURI(SearchResult result) throws Exception { Attributes attributes = result.getAttributes(); String address = (String) attributes.get("iphostnumber").get(); String port = (String) attributes.get("ipserviceport").get(); String protocol = (String) attributes.get("ipserviceprotocol").get(); URI connectorURI = new URI("static:(" + protocol + "://" + address + ":" + port + ")"); LOG.debug("retrieved URI from SearchResult [{}]", connectorURI); return connectorURI; }
/** * Looks up the DNS name provided in the JNDI context. */ public static Set<String> getCNamesFromTxtRecord(String discoveryDnsName) throws NamingException { Attributes attrs = getDirContext().getAttributes(discoveryDnsName, new String[]{TXT_RECORD_TYPE}); Attribute attr = attrs.get(TXT_RECORD_TYPE); String txtRecord = null; if (attr != null) { txtRecord = attr.get().toString(); /** * compatible splited txt record of "host1 host2 host3" but not "host1" "host2" "host3". * some dns service provider support txt value only format "host1 host2 host3" */ if (txtRecord.startsWith("\"") && txtRecord.endsWith("\"")) { txtRecord = txtRecord.substring(1, txtRecord.length() - 1); } } Set<String> cnamesSet = new TreeSet<String>(); if (txtRecord == null || txtRecord.trim().isEmpty()) { return cnamesSet; } String[] cnames = txtRecord.split(" "); Collections.addAll(cnamesSet, cnames); return cnamesSet; } }
@Override public Enumeration<String> engineAliases() { DirContext context = obtainDirContext(); if (context == null) { log.trace("Unable to obtain DirContext"); return null; } try { NamingEnumeration<SearchResult> results = context.search(searchPath, filterIterate, null, createSearchControl(new String[]{aliasAttribute})); // TODO pagination List<String> aliases = new LinkedList<>(); while (results.hasMore()) { Attribute attribute = results.next().getAttributes().get(aliasAttribute); if (attribute != null) aliases.add((String) attribute.get()); } return Collections.enumeration(aliases); } catch (NamingException e) { throw log.ldapKeyStoreFailedToIterateAliases(e); } finally { returnDirContext(context); } }
Attributes attrs = result.getAttributes(); Attribute dnAttr = attrs.get("distinguishedName"); String dn = (String) dnAttr.get();
System.exit(1); SearchResult result = renum.next(); Attribute memberOf = result.getAttributes().get("memberOf"); if (memberOf != null) {// null if this user belongs to no group at all for (int i = 0; i < memberOf.size(); i++) { Attributes atts = context.getAttributes(memberOf.get(i).toString(), new String[] { "CN" }); Attribute att = atts.get("CN"); groups.add(new GrantedAuthorityImpl(att.get().toString()));
@Override public boolean verifyCertificate(X509Certificate certificate, Attributes attributes) throws NamingException { Attribute attribute = attributes.get(ldapAttribute); if (attribute == null) return false; final int size = attribute.size(); for (int i = 0; i < size; i++) { Object attrSerialNumber = attribute.get(i); if (attrSerialNumber != null){ BigInteger value = new BigInteger((String) attrSerialNumber); if (certificate.getSerialNumber().equals(value)) { return true; } } } return false; } }
private String getAttribute(SearchResult searchResult, String attributeId) { if (searchResult == null) { return null; } Attribute entry = searchResult.getAttributes().get(attributeId); if (entry == null) { log.warn("The attribute with ID '{}' has not been found.", attributeId); return null; } try { return entry.get().toString(); } catch (NamingException ex) { log.error("Failed to get attribute value", ex); return null; } }
return principal; Attributes atrs = ((SearchResult)answer.next()).getAttributes(); Attribute usernameAttribute = atrs.get(usernameField); username = (String) usernameAttribute.get();
do { Attributes attrs = getDirContext().getAttributes(currentHost, new String[]{A_RECORD_TYPE, CNAME_RECORD_TYPE}); Attribute attr = attrs.get(A_RECORD_TYPE); if (attr != null) { targetHost = attr.get().toString(); attr = attrs.get(CNAME_RECORD_TYPE); if (attr != null) { currentHost = attr.get().toString(); } else { targetHost = currentHost;
void getGroupNames(SearchResult groupResult, Collection<String> groups, Collection<String> groupDNs, boolean doGetDNs) throws NamingException { Attribute groupName = groupResult.getAttributes().get(groupNameAttr); if (groupName == null) { throw new NamingException("The group object does not have " + "attribute '" + groupNameAttr + "'."); } groups.add(groupName.get().toString()); if (doGetDNs) { groupDNs.add(groupResult.getNameInNamespace()); } }
public String getTXT(String key) throws ConfigException { checkInitialized(); String qkey = fullyQualify(key); try { Attributes attrs = m_context.getAttributes(qkey, s_TXT); return (String) attrs.getAll().next().get(); } catch (Throwable e) { LOGGER.debug(getClass().getName(), "getTXT", e); // throw new NotFoundException("Unable to retrieve key: " + qkey, e); } return null; }
Attribute memberAttribute = result.getAttributes().get(permissionGroupMemberAttribute); NamingEnumeration<?> memberAttributeEnum = memberAttribute.getAll(); Attribute memberEntryObjectClassAttribute = memberAttributes.get("objectClass"); NamingEnumeration<?> memberEntryObjectClassAttributeEnum = memberEntryObjectClassAttribute.getAll(); Attribute name = memberAttributes.get(groupNameAttribute); if (name == null) { LOG.error("Policy not applied! Group {} does not have name attribute {} under entry {}", new Object[]{ memberDn, groupNameAttribute, result.getNameInNamespace() }); principalName = (String) name.get(); principalName = (String) name.get();
/** * Looks up the DNS name provided in the JNDI context. * * @param discoveryDnsName The discovery DNS name * @throws NamingException when the record cannot be found * @return A set of cname records */ static Set<String> getCNamesFromTxtRecord(String discoveryDnsName) throws NamingException { Attributes attrs = DIR_CONTEXT.getAttributes(discoveryDnsName, new String[]{TXT_RECORD_TYPE}); Attribute attr = attrs.get(TXT_RECORD_TYPE); String txtRecord = null; if (attr != null) { txtRecord = attr.get().toString(); /** * compatible splited txt record of "host1 host2 host3" but not "host1" "host2" "host3". * some dns service provider support txt value only format "host1 host2 host3" */ if (txtRecord.startsWith("\"") && txtRecord.endsWith("\"")) { txtRecord = txtRecord.substring(1, txtRecord.length() - 1); } } Set<String> cnamesSet = new TreeSet<>(); if (txtRecord == null || txtRecord.trim().isEmpty()) { return cnamesSet; } String[] cnames = txtRecord.split(" "); Collections.addAll(cnamesSet, cnames); return cnamesSet; }
String gidNumber = null; String uidNumber = null; Attribute gidAttribute = result.getAttributes().get(posixGidAttr); Attribute uidAttribute = result.getAttributes().get(posixUidAttr); String reason = ""; if (gidAttribute == null) { reason = "Can't find attribute '" + posixGidAttr + "'."; } else { gidNumber = gidAttribute.get().toString(); uidNumber = uidAttribute.get().toString();
public DNSServiceRecord getSRV(String key) throws ConfigException { checkInitialized(); String qkey = fullyQualify(key); try { Attributes attrs = m_context.getAttributes(qkey, s_SRV); return new DNSServiceRecord((String) attrs.getAll().next().get()); } catch (Throwable e) { LOGGER.debug(getClass().getName(), "getSRV", e); // throw new NotFoundException("Unable to retrieve key: " + qkey, e); } return null; }
Attributes attrs = ctx.getAttributes(userDN, attributes); String name = null; Attribute nameField = attrs.get(manager.getNameField()); if (nameField != null) { name = (String)nameField.get(); Attribute emailField = attrs.get(manager.getEmailField()); if (emailField != null) { email = (String)emailField.get(); Attribute creationDateField = attrs.get("createTimestamp"); if (creationDateField != null && "".equals(((String) creationDateField.get()).trim())) { creationDate = parseLDAPDate((String) creationDateField.get()); Attribute modificationDateField = attrs.get("modifyTimestamp"); if (modificationDateField != null && "".equals(((String) modificationDateField.get()).trim())) { modificationDate = parseLDAPDate((String)modificationDateField.get()); Attribute authPasswordValue = (Attribute) values.next(); String[] parts = ((String) authPasswordValue.get()).split("$"); String[] authInfo = parts[1].split(":"); String[] authValue = parts[2].split(":");
@Override public boolean verifyCertificate(X509Certificate certificate, Attributes attributes) throws NamingException { Attribute attribute = attributes.get(ldapAttribute); if (attribute == null) return false; final int size = attribute.size(); for (int i = 0; i < size; i++) { Object attrSubject = attribute.get(i); if (attrSubject != null){ X500Principal certSubjectX500Principal = certificate.getSubjectX500Principal(); X500Principal attSubjectX500Principal = new X500Principal((String) attrSubject); if ( certSubjectX500Principal.equals(attSubjectX500Principal) ) { return true; } } } return false; } }