ExtendedLdapUserMapper extends LdapUserDetailsMapper { protected String configureMailAttribute(String username, Map<String, String[]> record) { String result = getMailAttributeName(); if (getMailSubstitute() != null) { String subemail = substituteMail(username); record.put(SUBSTITUTE_MAIL_ATTR_NAME, new String[]{subemail}); if (isMailSubstituteOverridesLdap() || record.get(getMailAttributeName()) == null || record.get(getMailAttributeName()).length == 0) { result = SUBSTITUTE_MAIL_ATTR_NAME; } } return result; }  @Override UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities); String getMailAttributeName(); void setMailAttributeName(String mailAttributeName); String getPhoneNumberAttributeName(); void setPhoneNumberAttributeName(String phoneNumberAttributeName); String getGivenNameAttributeName(); void setGivenNameAttributeName(String givenNameAttributeName); String getFamilyNameAttributeName(); void setFamilyNameAttributeName(String familyNameAttributeName); String getMailSubstitute(); void setMailSubstitute(String mailSubstitute); boolean isMailSubstituteOverridesLdap(); void setMailSubstituteOverridesLdap(boolean mailSubstituteOverridesLdap); String getEmailVerifiedAttributeName(); void setEmailVerifiedAttributeName(String emailVerifiedAttributeName); static final String SUBSTITUTE_MAIL_ATTR_NAME; }
@Test public void testConfigureMailAttribute() { ExtendedLdapUserMapper mapper = new ExtendedLdapUserMapper(); mapper.setMailAttributeName("mail"); mapper.setMailSubstitute("{0}@substitute.org"); mapper.setMailSubstituteOverridesLdap(true); Map<String, String[]> records = new HashMap<>(); String result = mapper.configureMailAttribute("marissa", records); assertEquals(SUBSTITUTE_MAIL_ATTR_NAME, result); assertEquals("marissa@substitute.org", records.get(SUBSTITUTE_MAIL_ATTR_NAME)[0]); mapper.setMailSubstituteOverridesLdap(false); result = mapper.configureMailAttribute("marissa", records); assertEquals(SUBSTITUTE_MAIL_ATTR_NAME, result); records.put("mail", new String[] {"marissa@test.org"}); result = mapper.configureMailAttribute("marissa", records); assertEquals("mail", result); }