注册。使用UnboundID LDAP SDK扩展Active Directory过期

时间:2014-06-02 12:36:35

标签: ldap spring-ldap ldapconnection unboundid-ldap-sdk

我正在尝试使用UnboundID LDAP SDK更改活动目录帐户过期设置。但我无法找到办法。任何人都可以帮我这个吗?

enter image description here

我需要知道如何将帐户过期延长天数,以及我们如何将其更改为从不。

谢谢,

Sasi Kumar M。

2 个答案:

答案 0 :(得分:1)

"The date when the account expires. This value represents the number of 100-nanosecond intervals since January 1, 1601 (UTC) A value of 0 or 0x7FFFFFFFFFFFFFFF (9223372036854775807) indicates that the account never expires."

在java中,

private static final String ACCOUNT_NEVER_EXPIRE_VALUE = "9223372036854775807";
boolean accountNeverExpire = accountExpires.equals("0") || ACCOUNT_NEVER_EXPIRE_VALUE.equals(accountExpires);

private final static long DIFF_NET_JAVA_FOR_DATES = 11644473600000L + 24 * 60 * 60 * 1000;

long adAccountExpires= Long.parseLong(accountExpires);
long milliseconds = (adAccountExpires / 10000) - DIFF_NET_JAVA_FOR_DATES;
Date accountExpiresDate= new Date(milliseconds);

应该让你走上正确的轨道。

-Jim

答案 1 :(得分:0)

使用UNboundID LDAP SDK

Try{
System.out.println("Going to replace account expires to never");
final Modification mod = new Modification(ModificationType.REPLACE,
                "accountExpires", "9223372036854775807");
LDAPResult result=connection.modify(userDN, mod);
System.out.println("Password status : " + result);
}catch(LDAPException e) {
// TODO Auto-generated catch block
System.out.println("Error in replacing account expires to never");
e.printStackTrace();
}finally
{
System.out.println("Closing the connection.");
connection.close();
}