在我的应用程序中,我使用LDAP绑定验证机制。即使任何一个不匹配(用户名或密码),我都会收到AuthenticationException。
我想显示错误消息:用户名不匹配或密码不匹配。目前,使用AuthenticationException无法获得适当的细节。LDAP/AD - 如何确定用户名或密码是否不匹配
是否有任何现有的API将帮助?或需要使用API进行查询?
在此先感谢。
在我的应用程序中,我使用LDAP绑定验证机制。即使任何一个不匹配(用户名或密码),我都会收到AuthenticationException。
我想显示错误消息:用户名不匹配或密码不匹配。目前,使用AuthenticationException无法获得适当的细节。LDAP/AD - 如何确定用户名或密码是否不匹配
是否有任何现有的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();
}
您可以共享Java代码以进行评论 –
我没有全局上下文。是否有办法查询用户ID是否存在或没有提供密码(握手ldap服务器)? –
你可以简单地用管理员用户名和密码实例化新的InitialLdapContext来进行搜索。 – cshu
来自Microsoft Active Directory的returned error codes提供了该信息。
“例外是[LDAP:错误代码49 - 80090308:LdapErr:DSID-0Cxxxxxx,注释:AcceptSecurityContext错误,数据,vece]”。
数据值将通知问题。
对于用户名和密码不匹配,我得到相同的错误消息“javax.naming.AuthenticationException:[LDAP:错误代码49 - 80090308:LdapErr:DSID-0C090334,评论:AcceptSecurityContext错误,数据52e,vece ” –
有没有办法查询用户ID是否存在或没有提供密码(握手ldap服务器)? –
我没有在UI中显示哪一个错误,但是我的代码需要了解哪一个与用户名或密码不匹配 –