对于NOVELL LDAP 轻量级目录服务的学习理解

本文详细介绍了使用NOVELL API获取、添加、修改、删除LDAP服务器实体的方法,包括连接配置、实体操作流程及错误代码解释。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

对于NOVELL LDAP 轻量级目录服务的学习理解
采用NOVELL 的API
用到得包如下

import com.novell.ldap.LDAPAttributeSet;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPException;


如何获取到一个LDAP服务器的连接

   首先要知道
    服务器地址ldapHost,
    服务器端口ldapPort, 默认为 LDAPConnection.DEFAULT_PORT|389
    服务器版本ldapVersion, 默认为 LDAPConnection.LDAP_V3|3
    服务器管理员DN,
    服务器密码password,
   第一步
   LDAPConnectionlc = new LDAPConnection();
   lc.connect(ldapHost,ldapPort);
   lc.bind(ldapVersion,username, password.getBytes("UTF8"));
   如果没抛异常,lc即为到LDAPConnection的连接
   
   在操作完成之后一定要关闭LDAP连接lc.disconnect();

如何在LDAP服务器中加入一个实体即com.novell.ldap.LDAPEntry;

   定义LDAPAttributeSetattributeSet = new LDAPAttributeSet();
   在attributeSet中加入属性 注意各种实体参数正确 比如 objectclass 具体说明见:ldap 协议 objectclasses 与attribute
    attributeSet.add(newLDAPAttribute("objectclass", "inetOrgPerson"));
    attributeSet.add(newLDAPAttribute("riseGUID", riseGUID.toString()));
    attributeSet.add(newLDAPAttribute("fullName", name));
    attributeSet.add(newLDAPAttribute("userpassword", password));
    attributeSet.add(newLDAPAttribute("sn", name));
   确定实体dn 即实体在LDAP 上的树形结构中的位置
   建立实体对象
   LDAPEntrynewEntry = new LDAPEntry(dn, attributeSet);
   通过LDAPConnection 连接 添加此实体 
   lc.add(newEntry);

如何在LDAP服务器中获取某实体

   第一、获取到LDAP服务器的管理员连接
   第二、确定查找参数包括:该实体的DN 、String returnAttrs[] = {"LoginDisabled", 
      "loginExpirationTime","passwordExpirationTime","loginAllowedTimeMap","lockedByIntruder"};
     //字符串数组表示要查找的参数 类似数据库中要查找的数据表字段名
   第三、验证某实体的属性
   LDAPAttributeattribute = new LDAPAttribute("userPassword", userPWD);
   lc.compare(userDN,attribute)   //返回trueor false 可以用来判断用户的密码是否正确
   第四、进行查找
    LDAPEntryentry = lc.read(userDN, returnAttrs); //返回的是 LDAPEntry 对象 通过LDAPEntry 对象来获取该实体的信息
如何在LDAP服务器中查找实体 
   第一、获取到LDAP服务器的管理员连接
   第二、确定查找范围,查找参数,查找内容等
    如:StringsearchBase = "o=武钢氧气有限责任公司";
     StringsearchFilter = "(cn=a000001)";      // 此处为查找表达式,支持正则表达式
     StringsearchScope LDAPConnection.SCOPE_ONE // 只查找基节点第一层的子节点
           |LDAPConnection.SCOPE_BASE //只查找基节点
           |LDAPConnection.SCOPE_SUB // 查找基节点下面的所有子节点
   第三、根据参数进行查找返回 LDAPSearchResults 对象
   LDAPSearchResultssearchResults = lc.search(searchBase,
     searchScope,searchFilter, new String[] { "cn",
       "objectClass","userPassword","riseGUID"},false);
                  //此方法中字符串数组表示查询的实体的属性,并在结果中返回这些属性
   第四:列出查询结果
   
    while(searchResults.hasMore()) {       //LDAPSearchResults实现了 collection 接口
    LDAPEntryle = searchResults.next();     //结果集中每个内容都是一个LDAPEntry 对象
    System.out.println(le.getDN());
    LDAPAttributeSetattributeSet = le.getAttributeSet();  //通过LDAPEntry 对象来获取 LDAPAttributeSet 对象
    SetsortedAttributes = new TreeSet(attributeSet);
    IteratorallAttributes = sortedAttributes.iterator();

    while(allAttributes.hasNext()) {
     LDAPAttributeattribute = (LDAPAttribute) allAttributes.next();
     StringattributeName = attribute.getName();  //获取参数名
     System.out.println("\t\t"+attributeName);   
     EnumerationallValues = attribute.getStringValues();//其参数值可以为多个,利用Enumeration列出全部该属性的值
     if(allValues != null) {
      while(allValues.hasMoreElements()) {
       StringValue = (String) allValues.nextElement();
       System.out.println("\t\t\t"+ Value);
      }
     }
    }
   }
如何修改、删除 已存在的某实体的 属性 Attribute
    第一、获取到LDAP服务器的管理员连接
    第二、创建该实体要修改的属性列表ArrayList modList = new ArrayList();
    第三、用LDAPModification 对象填充该列表 如:
      LDAPAttributeattribute = new LDAPAttribute("telephoneNumber", "1 801 5551212");
      modList.add(newLDAPModification(LDAPModification.ADD, attribute));
      //这里 LDAPModification 对象有几种方式LDAPModification.ADD、LDAPModification.DELETE、LDAPModification.REPLACE
    第四、用list填充LDAPModification  对象
      LDAPModification[]modsadd = new LDAPModification[modList.size()];
      modsadd= (LDAPModification[]) modList.toArray(modsadd);
    第五、通过LDAP连接就行修改操作
      lc.modify(dn,modsadd);        //注:lc为LDAP服务器的连接modsadd 为封装后的LDAPModification 对象
      
      
如何删除某个已存在实体
    通过获取LDAP连接deleteDN为该节点的DN
    lc.delete(deleteDN);
    
    
    
    
JLDAP 访问LDAP服务器的错误代码含义(已知的)

91:Unable to connect to server 172.16.5.12:389 (91) ConnectError  //在获取连接的时候LDAP 服务器连接地址或端口不正确
68:Entry Already Exists (68) Entry Already Exists     //添加实体时抛出实体已经存在信息
32:No Such Object (32) No SuchObject        //实体不存在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值