geo*_*nez 4 java active-directory ou
我正在开发一个需要在活动目录中创建和维护用户的应用程序。
我的问题是用户有层次结构,主控可以使用不同的密码过期值创建它们。我正在阅读有关内容,也许可以使用 OU 来完成此操作,但我找不到有关它的一些代码示例。
也许存在更好的方法来满足要求,但不幸的是这是我找到的唯一方法。
解决方案(对我有用)
创建专有名称 (dn) 时,必须将 OU 添加到值中。这是我制作的代码:
protected String getDN(User user)
{
//User name
String dn = "CN=" + user.getLogin();
//OU
String ou;
if (user.getPasswordExpirationTime() == 1)
ou = "PJ1"; //one day
else if (usuario.getPasswordExpirationTime() == 30)
ou = "PJ30"; //thirty days
else if (usuario.getPasswordExpirationTime() == 60)
ou = "PJ60"; //sixty days
else
ou = "PJ90"; //default, ninety days
dn += ",OU=" + ou;
//Domain
dn += ",DC=domain,DC=local";
return dn;
}
Run Code Online (Sandbox Code Playgroud)
以下是有关如何执行此操作的示例:
String oldUserName = "CN=Albert Einstein,OU=Research,DC=antipodes,DC=com";
String newUserName = "CN=Albert Einstein,OU=Sales,DC=antipodes,DC=com";
// Create the initial directory context
LdapContext ctx = new InitialLdapContext(env,null);
// Move the user
ctx.rename(oldUserName,newUserName);
Run Code Online (Sandbox Code Playgroud)
https://forums.oracle.com/forums/thread.jspa?threadID=1157099