【发布时间】:2017-05-31 08:54:45
【问题描述】:
我正在尝试从 LDAP 验证用户的用户名和密码,这是我的 java 代码
Hashtable<Object, String> props = new Hashtable<Object, String>();
//props.put(Context.SECURITY_AUTHENTICATION, "simple");
props.put(Context.SECURITY_PRINCIPAL,
"uid=muhammad.zafar,ou=IT Operations,ou=Information Systems,dc=bi,dc=com,dc=pk");
props.put(Context.SECURITY_CREDENTIALS, "Passw0rd");
DirContext context;
try {
context = com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance("ldap://ldap.bi.com.pk:389/dc=bi,dc=com,dc=pk" + '/', props);
context.close();
} catch (Exception e) {
throw new BadCredentialsException("Invalid Username or Password");
}
由于用户 muhammad.zafar 存在于 IT 操作“ou”中,因此效果很好。但我不想用它的 ou 验证用户,所以我尝试了 SECURITY_PRINCIPAL 的许多设置,但没有一个对我有用
props.put(Context.SECURITY_PRINCIPAL,
"uid=muhammad.zafar");
它抛出异常“javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]” 甚至我试图放入
props.put(Context.SECURITY_AUTHENTICATION, "simple");
它们都不适合我。我希望我的问题很清楚,因为我的应用程序中没有每个用户“ou”。
【问题讨论】:
标签: java active-directory ldap