private boolean modifyUser(Attributes attrs, String userDN) {
try {
//如果用户要修改用户的 的用户组CN,则需要控制不能被修改,故将此项给 REMOVE 掉
attrs.remove("CN");
ctx.modifyAttributes(userDN, LdapContext.REPLACE_ATTRIBUTE, attrs);
System.out.println("Update User Successful ! ");
return true;
} catch (NamingException e) {
System.err.println("Problem changing password: " + e);
} catch (Exception e) {
System.err.println("Problem: " + e);
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return false;
}
调用:
/* 实例化一个属性集合 */
Attributes attrs = new BasicAttributes(true);
/* 设置属性"mail"的值为"xie@163.com"、"liu@sina.com.cn"、 "
attrs.put("mail", "sunny2011.com,liu@sina.com.cn,xyh@powerise.com.cn");
/* 建立一个属性,其属性名为"uid"*/
attrs.put("uid", "sunny");
modifyUser(attrs, "CN=test2,CN=Users,DC=kvmad,DC=com");