我正在尝试更改account expiration date
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();
}
}
}
希望大家能给出更好的解决方案。
acountExpires不是毫秒,而是自1601年1月1日(UTC)起100纳秒间隔的数量。
如果Active Directory中的用户对象从未有过期日期,则accountExpires属性将设置为一个巨大的数字。实际值为2 ^ 63 – 1或9,223,372,036,854,775,807。这是因为64位数字的范围可以是-2 ^ 63到2 ^ 63-1,这使其成为可以保存为64位值的最大数字。显然,这代表了迄今为止无法解释的日期。实际上,如果AccountExpirationDate尝试读取此值,则会引发错误。如果用户对象具有到期日期,然后通过在“帐户”选项卡上选择“从不”在ADUC中删除该日期,则GUI会将accountExpires设置为0。因此,值0和2 ^ 63-1都意味着“绝不”
有关更改Java的一种方法,请尝试查看此讨论。
-吉姆
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句