LdapRealm extends JndiLdapRealm { protected String getUserDnForSearch(String userName) { if (userSearchAttributeName == null || userSearchAttributeName.isEmpty()) { return memberDn(userName); } else { return getUserDn(userName); } } LdapRealm(); void setHadoopSecurityCredentialPath(String hadoopSecurityCredentialPath); @Override AuthorizationInfo queryForAuthorizationInfo(final PrincipalCollection principals,
      final LdapContextFactory ldapContextFactory); Map<String, String> getListRoles(); String getSearchBase(); void setSearchBase(String searchBase); String getUserSearchBase(); void setUserSearchBase(String userSearchBase); int getPagingSize(); void setPagingSize(int pagingSize); String getGroupSearchBase(); void setGroupSearchBase(String groupSearchBase); String getGroupObjectClass(); void setGroupObjectClass(String groupObjectClassAttribute); String getMemberAttribute(); void setMemberAttribute(String memberAttribute); String getGroupIdAttribute(); void setGroupIdAttribute(String groupIdAttribute); void setMemberAttributeValueTemplate(String template); void setAllowedRolesForAuthentication(List<String> allowedRolesForAuthencation); void setRolesByGroup(Map<String, String> rolesByGroup); Map<String, String> getRolesByGroup(); void setPermissionsByRole(String permissionsByRoleStr); Map<String, List<String>> getPermissionsByRole(); boolean isAuthorizationEnabled(); void setAuthorizationEnabled(boolean authorizationEnabled); String getUserSearchAttributeName(); void setUserSearchAttributeName(String userSearchAttributeName); String getUserObjectClass(); void setUserObjectClass(String userObjectClass); String getPrincipalRegex(); void setPrincipalRegex(String regex); String getUserSearchAttributeTemplate(); void setUserSearchAttributeTemplate(final String template); String getUserSearchFilter(); void setUserSearchFilter(final String filter); String getGroupSearchFilter(); void setGroupSearchFilter(final String filter); boolean getUserLowerCase(); void setUserLowerCase(boolean userLowerCase); String getUserSearchScope(); void setUserSearchScope(final String scope); String getGroupSearchScope(); void setGroupSearchScope(final String scope); boolean isGroupSearchEnableMatchingRuleInChain(); void setGroupSearchEnableMatchingRuleInChain(
      boolean groupSearchEnableMatchingRuleInChain); @Override void setUserDnTemplate(final String template);  }
@Test public void getUserDnForSearch() { LdapRealm realm = new LdapRealm(); realm.setUserSearchAttributeName("uid"); assertEquals("foo", realm.getUserDnForSearch("foo")); realm.setUserSearchAttributeName(null); realm.setMemberAttributeValueTemplate("cn={0},ou=people,dc=hadoop,dc=apache"); assertEquals("cn=foo,ou=people,dc=hadoop,dc=apache", realm.getUserDnForSearch("foo")); }