bsc*_*ach 7 java authentication jndi ldap active-directory
我正在尝试让我的自定义Java应用程序使用我们的Active Directory服务器进行身份验证,但由于某种原因我无法让它工作.谁能明白为什么会这样?这是我的方法如下:
private boolean authenticate(String serverName, String userId, String password) throws NamingException {
DirContext ctx = null;
Hashtable env = new Hashtable(11);
boolean b = false;
try {
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://servername.org:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid="+ userId +",ou=All Users,dc=site,dc=org");
env.put(Context.SECURITY_CREDENTIALS, password);
System.out.println("before context");
// If there isn't a naming exception then the user is authenticated. Return true
ctx = new InitialDirContext(env);
//The user is authenticated.
b = true;
} catch (NamingException e) {
System.out.println("the user is not authenticated return false");
b = false;
}finally{
if(ctx != null)
ctx.close();
}
return b;
}
Run Code Online (Sandbox Code Playgroud)
结果:
[12/14/11 16:27:47:746 CST] 0000001f SystemErr R
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece
Run Code Online (Sandbox Code Playgroud)
你尝试过这种方法吗?
//...
env.put(Context.SECURITY_PRINCIPAL, "cn="+ userId +",ou=All Users,dc=site,dc=org");
//...
Run Code Online (Sandbox Code Playgroud)
也更换
Hashtable env = new Hashtable(11);
Run Code Online (Sandbox Code Playgroud)
和
Hashtable env = new Hashtable();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16605 次 |
| 最近记录: |