Java ldap认证问题
我试图让我的自定义 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;
}
结果:
[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
I'm trying to have my custom java application use our Active Directory Server for authentication but I cannot get it to work for some reason. Can anyone see why this is? Here is my method below:
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;
}
Result:
[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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过这种方法吗?
也替换
为
Have you tried this way?
Also replace
with