`
aben328
  • 浏览: 1457215 次
  • 性别: Icon_minigender_1
  • 来自: 广东
社区版块
存档分类

访问LDAP数据的API--JLDAP

    博客分类:
  • LDAP
 
阅读更多

访问LDAP数据的API--JLDAP 晴
作者: Leo   分类:技术文档   出处:本站原创       大 | 中 | 小
   JLDAP是由novel开发的,原是针对Novel的NDS目录设计的JAVA访问工具。NOVEL的NDS和网景(NETSCAPE)的目录是工具界最早的目录产品。JLDAP并非JNDI的服务供应者,而是同一抽象层次下的访问工具集。与JNDI-LDAP相比,JLDAP更接近于类关系数据库的访问方式。

   NDS是遵守LDAP协议的并进行了扩展的类MAD产品。而NOVEL也已把JLDAP捐献给了OPENLDAP开源项目,可以世界范围内自由使用。与 JNDI相比,JLDAP无须继承DirContext才能实现添加,也无需预先生成添加的类,可以象普通数据访问那样,生成连接,然后使用::add方法添加。这样,添加的灵活性要强于JNDI。

   但由于JLDAP目前是访问NDS,因此,它不具备JNDI完全面向对象存储的能力,对于高级的LDAP应用,JLDAP不是合适的选择。

例:

======================================================================

   1. package com.yydt.test; 
   2.  
   3. import com.novell.ldap.LDAPAttribute; 
   4. import com.novell.ldap.LDAPAttributeSet; 
   5. import com.novell.ldap.LDAPConnection; 
   6. import com.novell.ldap.LDAPEntry; 
   7. import com.novell.ldap.LDAPException; 
   8.  
   9. public class AddEntry { 
  10.   int ldapVersion = LDAPConnection.LDAP_V3; 
  11.    
  12.   public void testAddEntry(){ 
  13. //    int ldapPort = LDAPConnection.DEFAULT_PORT; 
  14.     int ldapPort = 10389;     
  15.     String ldapHost = "localhost"; 
  16.     String loginDN = "uid=admin,ou=system"; 
  17.     String password = "secret"; 
  18.     String dn = "cn=Huang zhenwei,ou=system"; 
  19.      
  20.     LDAPAttribute attribute = null; 
  21.     LDAPAttributeSet attributeSet = new LDAPAttributeSet();     
  22.      
  23.     String objectclass_values[] = {"inetOrgPerson"}; 
  24.     attribute = new LDAPAttribute("objectclass",objectclass_values); 
  25.     attributeSet.add(attribute); 
  26.     String cn_values[] = {"James Smith","Jim Smith","Jimmy Smith"}; 
  27.     attribute = new LDAPAttribute("cn",cn_values); 
  28.     attributeSet.add(attribute); 
  29.     String givenname_values[] = {"James","Jim","Jimmy"}; 
  30.     attribute = new LDAPAttribute("givenname",givenname_values); 
  31.     attributeSet.add(attribute); 
  32.     attributeSet.add(new LDAPAttribute("sn","Smith")); 
  33.     attributeSet.add(new LDAPAttribute("telephonenumber","1 801 555 1212")); 
  34.     attributeSet.add(new LDAPAttribute("mail","JSmith@boolean.cn")); 
  35.     this.addEntry(ldapHost,ldapPort,loginDN,password,dn,attributeSet); 
  36.   }   
  37.  
  38.    
  39.   /*To Add an entry to the directory,
  40.    * --Create the attributes of the entry and add them to an attribute set
  41.    * --Specify the DN of the entry to be created
  42.    * --Create an LDAPEntry object with the DN and the attribute set
  43.    * --Call the LDAPConnection add method to add it to the directory
  44.    */ 
  45.   public void addEntry(String ldapHost,int ldapPort,String loginDN,String password,String dn,LDAPAttributeSet attributeSet){ 
  46.     LDAPConnection lc = new LDAPConnection();     
  47.      
  48.     LDAPEntry newEntry = new LDAPEntry(dn,attributeSet); 
  49.     try{ 
  50.       //connect to the server 
  51.       lc.connect(ldapHost,ldapPort); 
  52.       //authenticate to the server 
  53.       lc.bind(ldapVersion,loginDN,password.getBytes("UTF8));
  54.       lc.add(newEntry);
  55. //      lc.delete(dn);
  56.       System.out.println("\nAdded object: " +  dn + " successfully.");
  57.       //disconnect with the server
  58.       lc.disconnect();
  59.     }catch(LDAPException e){
  60.       System.out.println("Error: " + e.toString()); 
  61.     } catch (UnsupportedEncodingException e) { 
  62.       // TODO Auto-generated catch block 
  63.       e.printStackTrace(); 
  64.     } 
  65.     System.exit(0); 
  66.   } 
  67.  
  68.   /**
  69.    * @param args
  70.    */ 
  71.   public static void main(String[] args) {     
  72.     new AddEntry().testAddEntry(); 
  73.   } 
  74.  
  75. } 

 

======================================================================

分享到:
评论
2 楼 wooham 2012-03-23  
想知道新建基DN怎么搞,可是在doc中没找到。。。
1 楼 summer754 2011-11-17  
我做个LDAP的验证Windows server 2003上AD域用户的功能  当域用户的账户属性中的“登录到“属性指定一个计算机ip后,认证就失败了,我使用的认证级别是simple!

相关推荐

    api-ldap-codec-core-1.0.0-M24.zip

    本篇文章将重点探讨两个关键组件:“api-ldap-codec-core-1.0.0-M24”和“azure-sdk-for-java”,特别是它们在Java开发中的应用。 首先,让我们关注“api-ldap-codec-core-1.0.0-M24”。LDAP(轻量级目录访问协议)...

    Go-ldap-test-tool一个轻量级的ldap测试工具

    【Go-ldap-test-tool:一个轻量级的LDAP测试工具】 在信息技术领域,LDAP(Lightweight Directory Access Protocol)是一种用于访问和管理分布式目录服务的标准协议。它被广泛应用于组织内部的身份验证、用户权限...

    api-ldap-model-1.0.0-M22.zip

    【标题】"API-LDAP-Model-1.0.0-M22.zip" 提供的是一个关于 LDAP(轻量级目录访问协议)的模型库,版本为1.0.0的第二个候选发布版M22。这个库可能是用于帮助开发者在Scala或Java环境中与LDAP服务器进行交互,提供...

    python_ldap-3.4.4-cp38-cp38-win_amd64.whl.zip

    这个`python_ldap-3.4.4-cp38-cp38-win_amd64.whl`文件是一个预编译的Python轮子(Wheel)包,特别为Python 3.8(cp38)和64位Windows(win_amd64)平台设计。"whl"是一种二进制分发格式,它简化了Python库的安装...

    apache-ldap-api-1.0.0-M13-bin

    在"apache-ldap-api-1.0.0-M13-bin"压缩包中,包含的是Apache LDAP API的一个特定版本,即1.0.0-M13。 在描述中提到的"shared-all-1.0.0-M13.jar"是Apache LDAP API的核心组件之一。这个JAR文件包含了所有必要的类...

    python_ldap-3.4.4-cp312-cp312-win_amd64.whl.zip

    这个`python_ldap-3.4.4-cp312-cp312-win_amd64.whl`文件是专门为Python 3.12版本编译的Windows 64位平台的Python LDAP库的轮子文件(wheel file)。轮子文件是预编译的Python软件包,旨在简化安装过程,避免了通常...

    python_ldap-3.3.1-cp37-cp37m-win_amd64

    python_ldap-3.3.1-cp37-cp37m-win_amd64

    python_ldap-3.1.0-cp36-wheel.zip

    这个`python_ldap-3.1.0-cp36-wheel.zip`压缩包包含了适用于Python 3.6版本的Python LDAP库的二进制安装包。"cp36"代表的是Python 3.6的版本标识,而"win32"和"x64"分别表示这些文件是为32位和64位的Windows系统编译...

    python_ldap-3.4.4-cp39-cp39-win32.whl.zip

    这个“python_ldap-3.4.4-cp39-cp39-win32.whl.zip”文件是Python LDAP库的特定版本,适用于Python 3.9解释器,并且是为32位Windows系统编译的。在Python生态系统中,`whl`(Wheel)文件是一种预编译的Python软件包...

    python_ldap-3.3.1-cp38-cp38-win_amd64

    python_ldap-3.3.1-cp38-cp38-win_amd64

    ldap-account-manager-3.7

    3. **安全性增强**:作为处理敏感用户信息的工具,ldap-account-manager-3.7可能会包含加强的安全措施,比如HTTPS连接,更强的密码策略,以及访问控制等,以保护数据安全。 4. **性能优化**:版本升级通常会带来...

    spring-ldap-core-1.3.0.RELEASE.jar

    spring-ldap-core-1.3.0.RELEASE.jar

    ldap-connector-4.2.2.jar

    Java 连接ldap需要驱动包,否则JDBC无法访问数据库(无法注册驱动),常用的是ldap-connector

    python_ldap-3.4.4-cp37-cp37m-win32.whl.zip

    Python LDAP库是一个用于Python的轻量级目录访问协议(LDAP)接口,它允许开发者与LDAP服务器进行交互,例如进行用户身份验证、数据检索或管理目录服务。`python_ldap-3.4.4-cp37-cp37m-win32.whl` 是这个库的一个...

    python_ldap-3.3.1-cp39-cp39-win32

    python_ldap-3.3.1-cp39-cp39-win32

    ldap-account-manager-5.0.tar.gz

    ldap页面化管理工具,ldap-account-manager-5.0.tar.gz

    python_ldap-3.2.0-cp35-cp35m-win32

    python_ldap-3.2.0-cp35-cp35m-win32

    python_ldap-2.5.2-cp27-cp27m-win32

    python_ldap-2.5.2-cp27-cp27m-win32

    bind-dyndb-ldap-1.1.0-0.9.b1.el6.i686.rpm

    bind-dyndb-ldap-1.1.0-0.9.b1.el6.i686.rpm是centos开发工具包。

Global site tag (gtag.js) - Google Analytics