我需要以编程方式向openDS服务器添加一些用户帐户,但即使在通过openDS wiki查看后,我也不知道如何执行此操作。任何人都可以帮我吗?如何以编程方式将用户帐户添加到openDS?
2
A
回答
5
以下代码使用jndi。这只会添加一个用户对象与提供的密码。这并不多。但是这可能会帮助你开始。
此外,我宁愿坚持jndi相比opend-sdk。
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.DirContext;
import javax.naming.directory.Attributes;
import javax.naming.directory.Attribute;
import javax.naming.NamingException;
public class App {
/* Ugly HardCoded stuff */
public static String ldapUri = "ldap://localhost:2389";
public static String admindn = "cn=Directory Manager";
public static String admincred = "password";
public static String usersContainer = "ou=users,dc=example,dc=com";
public static void main(String args[]){
if (args.length != 2) {
System.out.println("Usage: App userName password");
return;
}
String username = args[0];
String password = args[1];
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapUri);
env.put(Context.SECURITY_PRINCIPAL, admindn);
env.put(Context.SECURITY_CREDENTIALS, admincred);
try {
DirContext ctx = new InitialDirContext(env);
Attributes attrs = new BasicAttributes(true);
Attribute objclass = new BasicAttribute("objectclass");
objclass.add("top");
objclass.add("inetorgperson");
Attribute surname = new BasicAttribute("sn");
surname.add(username);
Attribute pwd = new BasicAttribute("userpassword");
pwd.add(password);
attrs.put(objclass);
attrs.put(surname);
attrs.put(pwd);
ctx.createSubcontext("cn="+username+","+usersContainer, attrs);
ctx.close();
} catch (NamingException e) {
e.printStackTrace();
}
}
}
2
要在OpenDS中以编程方式添加用户帐户,您需要为您的操作系统和首选编程语言使用LDAP客户端库。 OpenDS有一个用于Java的LDAP库,带有许多示例代码。 http://www.opends.org/promoted-builds/sdk/20110126210001/ Sample位于示例目录中。
0
在这里,在PHP中使用的代码工作正常,我
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>
<?php
$ldapconfig['host'] = 'PC100';
$ldapconfig['port'] = 1389;
$ldapconfig['basedn'] = 'dc=company,dc=com';
$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
$password=1;
$username="cn=Directory Manager";
if ($bind=ldap_bind($ds, $username, $password)) {
echo("Login correct");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); // IMPORTANT
$dn = "cn=roshanis,dc=example,dc=com";
$ldaprecord['cn'] = "roshanis";
$ldaprecord['givenName'] = "mkljl";
$ldaprecord['sn'] = "roshan";
$ldaprecord['objectclass'][0] = "inetOrgPerson";
$ldaprecord['objectclass'][1] = "test";
$ldaprecord['mail'] = "[email protected]";
// add data to directory
$r = ldap_add($ds, $dn, $ldaprecord);
// $r= ldap_modify($ds, $dn, $ldaprecord);
} else {
echo("Unable to bind to server.</br>");
}
?>
</body>
</html>
相关问题
- 1. 如何以编程方式添加用户帐户策略?
- 2. 以编程方式添加SIP帐户
- 3. 以编程方式将明星添加到Google地图帐户
- 4. 以编程方式将已有用户添加到AAD租户
- 5. 以编程方式将帐户添加到Android电子邮件应用程序
- 6. 以编程方式将用户添加到莲花笔记组
- 7. 以编程方式将用户添加到C#中的IIS_Usrs
- 8. 以编程方式将用户添加到列表中
- 9. 以编程方式将本地用户添加到本地组
- 10. 如何以wordpress环境以编程方式将用户添加到wordpress
- 11. 如何以编程方式将客户添加至心愿单?
- 12. 以编程方式注销Twitter帐户
- 13. 以编程方式创建Outlook帐户
- 14. 以编程方式删除Twitter帐户
- 15. 以编程方式断开Facebook帐户
- 16. 以编程方式将数据添加到客户端
- 17. 如何以编程方式将OpenID用户添加到Plone站点
- 18. 如何以编程方式向TFS添加用户
- 19. 如何以编程方式向tomcat UserDatabaseRealm添加用户?
- 20. 如何在Android中以编程方式调用帐户设置
- 21. Android - 同步联系人以编程方式添加到Google帐户
- 22. 如何以编程方式确定ASP.Net工作进程帐户
- 23. 如何以编程方式将绑定添加到CXF客户端代码?
- 24. 如何使用Java将用户添加到OpenDS并将其删除?
- 25. 如何将多个Google帐户添加到Android应用以便用户可以在帐户之间切换
- 26. 如何将域帐户用户添加到本地组?
- 27. 以编程方式将用户添加到Active Directory和角色到tfs项目
- 28. 如何以编程方式添加WCF客户端端点?
- 29. Android帐户首选项:如何添加“编辑帐户”按钮?
- 30. 如何在node.js中以编程方式创建ftp帐户
感谢卢多,但我没有发现添加用户帐户的样品。你可以给我的网址? – eric2323223 2011-03-01 10:41:55
你在找opend-sdk的例子吗? – kalyan 2011-03-02 13:52:55
是的,我遵循卢多的网址,但没有找到添加用户帐户的示例。你有吗? – eric2323223 2011-03-04 13:43:20