ldap 用户名需要在输入框中显示为自动完成功能。我正在尝试获取如下用户列表:
String ldapURL = "ldap://192.26.75.5:389/dc=northamerica,dc=company,dc=com";
String principalPrefix = "domainName";
String username = SecurityContextHolder.getContext().getAuthentication().getName();
String password = SecurityContextHolder.getContext().getAuthentication().getCredentials().toString();
Hashtable<String, String>environment = new Hashtable<String, String>();
environment.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL,ldapURL);
environment.put(Context.SECURITY_AUTHENTICATION,"simple");
environment.put(Context.SECURITY_PRINCIPAL,principalPrefix + "\\" + username);
environment.put(Context.SECURITY_CREDENTIALS,password);
environment.put( Context.REFERRAL, "follow" );
DirContext context = null;
NamingEnumeration<SearchResult> enumResult = null;
try
{
context = new InitialDirContext(environment);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attrIDs ={"ou","uid", "givenname", "sn", "mail"};
controls.setReturningAttributes(attrIDs);
enumResult = context.search("","(&(objectCategory=person)(objectClass=user)(CN=*))", controls);
if(enumResult != null)
{
//authentication successful
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
但是“enumResult”总是获得单个用户的价值。让我知道我是否遗漏了某些东西,或者它的方法是否错误。任何帮助/建议/建议将不胜感激!谢谢。