LdapUtils { public static Object getValue(Name name, String key) { NamingEnumeration<? extends Attribute> allAttributes = getRdn(name, key).toAttributes().getAll(); while (allAttributes.hasMoreElements()) { Attribute oneAttribute = allAttributes.nextElement(); if(key.equalsIgnoreCase(oneAttribute.getID())) { try { return oneAttribute.get(); } catch (javax.naming.NamingException e) { throw convertLdapException(e); } } } throw new NoSuchElementException("No Rdn with the requested key: '" + key + "'"); } private  LdapUtils(); static void closeContext(DirContext context); static NamingException convertLdapException(javax.naming.NamingException ex); static Class getActualTargetClass(DirContext context); static void collectAttributeValues(Attributes attributes, String name, Collection<Object> collection); static void collectAttributeValues(
            Attributes attributes, String name, Collection<T> collection, Class<T> clazz); static void iterateAttributeValues(Attribute attribute, AttributeValueCallbackHandler callbackHandler); static String convertCompositeNameToString(
			CompositeName compositeName); static LdapName newLdapName(Name name); static LdapName newLdapName(String distinguishedName); static LdapName removeFirst(Name dn, Name pathToRemove); static LdapName prepend(Name dn, Name pathToPrepend); static LdapName emptyLdapName(); static Rdn getRdn(Name name, String key); static Object getValue(Name name, String key); static Object getValue(Name name, int index); static String getStringValue(Name name, int index); static String getStringValue(Name name, String key); static String convertBinarySidToString(byte[] sid); static byte[] convertStringSidToBinary(String string);  }
@Test public void testGetValueNamed() throws InvalidNameException { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); assertThat("john.doe").isEqualTo(LdapUtils.getValue(ldapName, "cn")); }
@Test public void testGetValueNamedReturnesFirstFound() throws InvalidNameException { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); assertThat("M").isEqualTo(LdapUtils.getValue(ldapName, "ou")); }
@Test public void testGetValueNamedWithMultivalue() throws InvalidNameException { LdapName ldapName = new LdapName(EXPECTED_MULTIVALUE_DN_STRING); assertThat("GR").isEqualTo(LdapUtils.getValue(ldapName, "o")); }
@Test public void testGetValueIndexed() throws InvalidNameException { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); assertThat("G").isEqualTo(LdapUtils.getValue(ldapName, 2)); }
@Test public void testGetStringValueIndexed() throws InvalidNameException { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); assertThat("I").isEqualTo(LdapUtils.getValue(ldapName, 1)); }