我们在应用程序中使用LDAP进行Windows身份验证。
代码看起来像
public LdapContext adAuth(String userName, String passWord, String domainName, String url,String port) {
LdapContext ctx = null;
try{
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://"+url+":"+port);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, userName + "@" + domainName );
env.put(Context.SECURITY_CREDENTIALS, passWord);
ctx = new InitialLdapContext(env, null);
}catch(NamingException nex){
ctx = null;
}
return ctx;
}
这很好用。但问题是当用户更改密码并设置新密码时,他可以使用新密码和 OLD 密码登录。我该如何防止这种情况?用户应该只能使用新密码登录。