[英]LDAP/AD - How to determine whether user name or password is mismatch
在我的应用程序中,我使用LDAP绑定身份验证机制。 即使任何一个不匹配(用户名或密码),我也会收到AuthenticationException。
我想显示用户名不匹配或密码不匹配的错误消息。 目前,使用AuthenticationException无法获取正确的详细信息。
是否有任何现有的API会有所帮助? 或者需要使用API查询?
提前致谢。
如果用户提供用于身份验证的用户名和密码,最好不要告诉他们登录失败的确切原因。 您总是告诉他们用户名和密码之间存在不匹配,因此攻击者无法了解特定用户名是否存在。
我同意最好的做法是不说出原因。
-
但是如果你不管怎么做都必须这样做:
使用用户名进行search
以检查用户名是否存在。 如果它不存在则是一个错误。
如果用户存在且它继续进行身份验证但您收到AuthenticationException,那么它是一个错误的密码。
-
编辑:
If(checkUserExists(username)){
//construct the hashtable environment
//...
ht.put(Context.SECURITY_PRINCIPAL, username);
ht.put(Context.SECURITY_PRINCIPAL, password);
//...
try {
localLdapContent = new InitialLdapContext(ht, null);
} catch (Exception e) {
//suppose it's a wrong password
}
}else{
//error user doesn't exist
}
您需要另一个具有权限的ldap连接,以检查用户是否有所有请求。
boolean checkUserExists(String username) {
//...
ht_administrator.put(Context.SECURITY_PRINCIPAL, admin_username);
ht_administrator.put(Context.SECURITY_PRINCIPAL, admin_password);
//...
adminconn = new InitialLdapContext(ht_administrator, null);
return adminconn.search(
"uid="+username+",ou=people,dc=example,dc=com", "(objectclass=*)", searchControls
).hasMore();
}
Microsoft Active Directory 返回的错误代码提供该信息。
“例外是[LDAP:错误代码49 - 80090308:LdapErr:DSID-0Cxxxxxx,注释:AcceptSecurityContext错误,数据,vece]。”
数据值将告知问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.