Java 使用Foxpass绑定后对LDAP用户进行身份验证

Java 使用Foxpass绑定后对LDAP用户进行身份验证,java,ldap,Java,Ldap,我一直在尝试获取一段简单的代码以在java中运行—身份验证作为Foxpass(托管LDAP服务)的绑定,然后尝试对另一个用户进行身份验证。 我基本上在我的Foxpass设置中创建了一个活页夹,并创建了一些用户 代码是: Hashtable<String,String> env = new Hashtable <String,String>(); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Cont

我一直在尝试获取一段简单的代码以在java中运行—身份验证作为Foxpass(托管LDAP服务)的绑定,然后尝试对另一个用户进行身份验证。 我基本上在我的Foxpass设置中创建了一个活页夹,并创建了一些用户

代码是:

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()
}
但似乎什么都不管用。任何关于找到正确的搜索格式的帮助


谢谢你

在我看来,你的搜索字符串曾经生活在Active Directory环境中。用Foxbase试试

String searchString=String.format((uid=%s)”,用户名)

sAMAccountName=myusername
sAMAccountName=myusername@mydomain.com
sAMAccountName=CN=myusername,DC=mydomain,DC=com
Or
username=myusername
...
Or
Email=myusername@mydomain.com