ProfileMapper implements Function<LdapEntry, ProfileImpl> { @Override public ProfileImpl apply(LdapEntry entry) { final ProfileImpl profile = new ProfileImpl(); profile.setUserId(entry.getAttribute(idAttr).getStringValue()); for (Map.Entry<String, String> attrMapping : appToLdapAttrNames.entrySet()) { final LdapAttribute ldapAttr = entry.getAttribute(attrMapping.getValue()); if (ldapAttr != null) { profile.getAttributes().put(attrMapping.getKey(), ldapAttr.getStringValue()); } } return profile; } ProfileMapper(String idAttr, Pair<String, String>[] attributes); @Override ProfileImpl apply(LdapEntry entry);  }
@Test public void testMappingFromLdapAttributesToProfile() throws Exception { final LdapEntry entry = new LdapEntry("uid=user123,dc=codenvy,dc=com"); entry.addAttribute(new LdapAttribute("uid", "user123")); entry.addAttribute(new LdapAttribute("cn", "name")); entry.addAttribute(new LdapAttribute("mail", "user@codenvy.com")); entry.addAttribute(new LdapAttribute("sn", "LastName")); entry.addAttribute(new LdapAttribute("givenName", "FirstName")); entry.addAttribute(new LdapAttribute("telephoneNumber", "0123456789")); @SuppressWarnings("unchecked") final ProfileMapper profileMapper = new ProfileMapper( "uid", new Pair[] { Pair.of("lastName", "sn"), Pair.of("firstName", "givenName"), Pair.of("phone", "telephoneNumber") }); final ProfileImpl profile = profileMapper.apply(entry); assertEquals( profile, new ProfileImpl( "user123", ImmutableMap.of( "lastName", "LastName", "firstName", "FirstName", "phone", "0123456789"))); }