简体   繁体   English

Java Spring LDAP-警告LDAP密码已过期

[英]Java spring LDAP - Waring LDAP password expire

We are using active directory to manage user account. 我们正在使用活动目录来管理用户帐户。 Now we want to use password policy to set max password age to force user reset password after 2 months. 现在,我们要使用密码策略设置最长密码使用期限,以强制用户在2个月后重设密码。 And we need to warn user after they login if his password is going to be expired soon (3 days, for example). 而且,如果用户的密码即将过期(例如3天),我们需要在用户登录后警告用户。 How can we obtain this? 我们如何获得呢? We are using Spring LDAP 1.3.0. 我们正在使用Spring LDAP 1.3.0。 I googled and see the password max age property is set in domain. 我用谷歌搜索,发现密码最大使用期限属性已在域中设置。 However, I don't know how to get this value. 但是,我不知道如何获得此值。

Thanks COL 谢谢COL

You need to use the extended password request and response controls to get this information. 您需要使用扩展的密码请求和响应控件来获取此信息。 See my answer to this question for a link to the necessary Java code. 请参阅我对此问题的答案,以获取必要的Java代码的链接。

Credentials expiration date and time 凭证到期日期和时间

Getting the date and time at which the password was last changed: 获取上次更改密码的日期和时间:

private final static long DIFF_NET_JAVA_FOR_DATE_AND_TIMES = 11644473600000L;
long adDateTime = Long.parseLong(pwdLastSet);
long milliseconds = (adDateTime / 10000) - DIFF_NET_JAVA_FOR_DATE_AND_TIMES;
Date pwdLastSetDate = new Date(milliseconds);

Getting the number of max days that could have the password: 获取可以使用密码的最大天数:

private final static int ONE_HUNDRED_NANOSECOND = 10000000;
private final static long SECONDS_IN_DAY = 86400;
long maxPwdAge = Math.abs(Long.parseLong(maxPwdAgeStr));
long maxPwdAgeSecs = maxPwdAge / ONE_HUNDRED_NANOSECOND;
int maxPwdAgeDays = (int) (maxPwdAgeSecs / SECONDS_IN_DAY);

Getting the the date and time at which the password will expire 获取密码过期的日期和时间

Calendar cal = Calendar.getInstance();
cal.setTime(pwdLastSetDate);
cal.add(Calendar.DATE, maxPwdAgeDays);
Date credentialsExpiresDate = cal.getTime();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM