本文共 698 字,大约阅读时间需要 2 分钟。
小智..
45
我希望这可以帮助你们中的许多人.
您不需要具有CN,DN等的所有用户层次结构.
您只需登录通过域\用户和密码即可登录.
我的代码工作原理如下:
try
{
// Set up the environment for creating the initial context
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://ldap_server:389");
//
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "domain\\user"); //we have 2 \\ because it's a escape char
env.put(Context.SECURITY_CREDENTIALS, "test");
// Create the initial context
DirContext ctx = new InitialDirContext(env);
boolean result = ctx != null;
if(ctx != null)
ctx.close();
return result;
}
catch (Exception e)
{
return false;
}
转载地址:http://yjncl.baihongyu.com/