sasikals26
sasikals26

Reputation: 865

Reg. Extending Active Directory Expires using UnboundID LDAP SDK

I am trying to change the active directory account expires setting using UnboundID LDAP SDK. But i can not able to find the way to do it. Can any one please help me on this?

enter image description here

I need to know how to extend the Account expires by days and also how we can change it to Never.

Thanks,

Sasi Kumar M.

Upvotes: 0

Views: 348

Answers (2)

sasikals26
sasikals26

Reputation: 865

Using 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();
}               

Upvotes: 0

jwilleke
jwilleke

Reputation: 10996

"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."

In java,

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

and

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);

Should get you on the right track.

-jim

Upvotes: 1

Related Questions