我正在尝试更改account expiration date
in windows active directory
。
我可以使用以下代码在帐户到期时更改从不选项。
final Modification mod = new Modification(ModificationType.REPLACE,
"accountExpires", "9223372036854775807");//Can change the required date with milliseconds
LDAPResult result=connection.modify(userDN, mod);
但是,如果我尝试更改account expiry date
方法,代码执行成功并且成功打印在控制台中。但日期没有更改AD
。
这是我更改或延长帐户到期日期的代码。
公共类 AccountExpireSetting {
public void ChangeAccountExpires(String userDN,String password , String dateToChange) throws LDAPException
{
LDAPConnection connection=null;
String someDate = null;
try {
connection = new LDAPConnectionObject().getConnection();
} catch (LDAPException e1) {
e1.printStackTrace();
}
try{
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
Date date = sdf.parse(dateToChange);
System.out.println("Date to MillSeconds : "+date.getTime());
someDate = String.valueOf(date.getTime());
Date date1=new Date(date.getTime());
System.out.println("MillSeconds to Date : "+date1);
}
catch(Exception e){
e.printStackTrace();
}
try{
System.out.println("Going to replace account expires to never");
final Modification mod = new Modification(ModificationType.REPLACE,
"accountExpires", someDate);// 9223372036854775807 milliseconds can change the password to never expire
// 9223372036854775807
LDAPResult result=connection.modify(userDN, mod);
System.out.println("Account expires status : " + result); // Password status : LDAPResult(resultCode=0 (success), messageID=2, opType='modify')
}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();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String temp="CN=Anand,OU=Java,OU=Chennai,OU=Department,dc=tstdmn,dc=com";
try {
new AccountExpireSetting().ChangeAccountExpires(temp, "password@123","08.06.2014");
} catch (LDAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
希望各位大侠给出更好的解决方案。