能够在LDAP中使用旧密码登录

时间:2016-08-23 07:39:44

标签: java windows authentication ldap

我们在应用程序中使用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 密码登录。我该如何防止这种情况?用户应该只能使用新密码登录。

1 个答案:

答案 0 :(得分:1)

通常情况下,由于default timeout of 60 min旧密码或由于复制而发生。查看更多here