我需要能够使用 Java 类更新 OpenLDAP 上的属性。
我尝试创建一个 LDAP 条目,但它看起来像一个 Java 对象,而不是一个正确的 LDAP 条目。(咕咕咕)
导入 javax.naming.Context; 导入 javax.naming.InitialContext; 导入 javax.naming.NamingException; 导入 javax.naming.NameAlreadyBoundException; 导入 javax.naming.directory.*; 导入 java.util.*; 公共类 TestLDAP { 静态最终长序列版本UID = -1240113639782150930L; 最终静态字符串 ldapServerName = "localhost:636"; final static String rootdn = "cn=The Manager,ou=mydept,o=mycompany"; 最终静态字符串 rootpass = "密码"; final static String rootContext = "ou=mydept,o=mycompany"; 公共静态无效主要(字符串[]参数){ System.setProperty("javax.net.ssl.trustStore", "C:\\cacerts"); 属性 env = new Properties(); env.put("com.sun.jndi.ldap.trace.ber", System.out); env.put(Context.INITIAL_CONTEXT_FACTORY, “com.sun.jndi.ldap.LdapCtxFactory”); env.put(Context.SECURITY_PROTOCOL, "ssl"); env.put(Context.PROVIDER_URL, "ldap://" + ldapServerName + "/" + rootContext ); env.put(Context.SECURITY_PRINCIPAL, rootdn); env.put(Context.SECURITY_CREDENTIALS, rootpass); 尝试 { // 使用环境获取初始目录上下文 DirContext ctx = new InitialDirContext( env ); // 添加 LDAP 条目 属性 myAttrs = new BasicAttributes(true); 属性 oc = new BasicAttribute("objectclass"); oc.add("inetOrgPerson"); oc.add("组织人员"); oc.add("人"); oc.add("top"); myAttrs.put(oc); myAttrs.put("cn","test996"); myAttrs.put("sn","test 996"); ctx.bind("cn=test997", myAttrs); } 捕捉(NameAlreadyBoundException nabe){ System.err.println("值已经被绑定!"); } 捕捉(异常 e){ e.printStackTrace(); } } }
请帮忙!