I've been trying to get a simple snippet of code to run in java - authentication as binder to Foxpass (hosted LDAP service) and then trying to authenticate another user to it. I basically created a binder in my Foxpass settings and created some users as well.
The code is:
Hashtable<String,String> env = new Hashtable <String,String>();
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, bindUser);
env.put(Context.SECURITY_CREDENTIALS, bindPassword);
env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
env.put(Context.PROVIDER_URL, myFoxpassUrl);
try {
DirContext ldapContext = new InitialDirContext(env);
NamingEnumeration<SearchResult> results = null;
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
controls.setCountLimit(1);
controls.setTimeLimit(5000);
String searchString = "(&(objectCategory=user)(sAMAccountName=username))";
results = ldapContext.search("", searchString, controls);
System.out.println(results.hasMore());
}
catch (Exception e)
{
e.printStackTrace()
}
The binding (authentication with bindUsername and bindPassword works well). However, searching for the users return 0 values. I tried using:
sAMAccountName=myusername
sAMAccountName=myusername@mydomain.com
sAMAccountName=CN=myusername,DC=mydomain,DC=com
Or
username=myusername
...
Or
Email=myusername@mydomain.com
But nothing seems to work. Any help on finding the right format to do the search.
Thank you
It seems to me your searchString once lived in an Active Directory environment. With Foxbase try
String searchString = String.format("(uid=%s)", username);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.