java 6.0 api_Java6.0 API for LDAP概述

本文介绍了Java 6.0 API中针对LDAP的javax.naming.directory包,详细阐述了InitialDirContext、BasicAttribute、BasicAttributes和SearchControls等关键类的使用方法,包括初始化目录服务上下文、创建/绑定LDAP条目、获取和修改条目属性、删除条目以及搜索条目等操作。同时,提供了示例代码以帮助理解API的实战应用。
摘要由CSDN通过智能技术生成

摘自:http://linliangyi2007.iteye.com/blog/167128

从JDK5.0开始,对LDAP协议的数据访问操作就被集成在javax的扩展API包中,并随同JDK一并发布,这一章节,我们主要介绍API包中的类信息。

javax.naming.directory 包的结构

24c622a6768af1fc6b4d2b2f91996e9a.gif 

常用API解析

javax.naming.directory.InitialDirContext,初始化目录服务上下文类

该类是LDAP数据内容的操作工具类,通过该类可以执行绑定LDAP服务器、新增LDAP条目、获取条目实例、修改条目属性、删除条目和根据条件搜索条目等操作。常用方法说明如下:

初始化LDAP 目录服务上下文(相当于使用JDBC打开一个数据库链接)

InitialDirContext(Hashtable,?> environment)

绑定/创建LDAP条目对象(相当于新增一个LDAP条目数据bind(Name

name, Object obj, Attributes attrs)

bind(String name, Object obj, Attributes attrs)

createSubcontext(Name name, Attributes attrs)

createSubcontext(String name, Attributes attrs)

获取条目实例(属性集)

getAttributes(Name name)

getAttributes(Name name, String[] attrIds)

getAttributes(String name)

getAttributes(String name, String[] attrIds)

修改条目属性

modifyAttributes(Name name, int mod_op, Attributes attrs)

modifyAttributes(Name name, ModificationItem[] mods)

modifyAttributes(String name, int mod_op, Attributes attrs)

modifyAttributes(String name, ModificationItem[] mods)

删除条目

destroySubcontext(Name name)

destroySubcontext(String name)

根据属性集搜索条目

search(Name name, Attributes matchingAttributes)

search(Name name, Attributes matchingAttributes, String[] attributesToReturn)

search(String name, Attributes matchingAttributes)

search(String name, Attributes matchingAttributes, String[] attributesToReturn)

根据过滤器搜索条目

search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons)

search(Name name, String filter, SearchControls cons)

search(String name, String filterExpr, Object[] filterArgs, SearchControls cons)

search(String name, String filter, SearchControls cons)

javax.naming.directory.BasicAttribute,LDAP基本属性对象

该类用来表示LDAP条目中的单个属性对象。在目录服务中,每个属性名称是可以对应多个的属性值的。

构建属性对象

BasicAttribute(String id)

BasicAttribute(String id, boolean ordered)

BasicAttribute(String id, Object value)

BasicAttribute(String id, Object value, boolean ordered)

添加属性值

add(int ix, Object attrVal),添加属性值到多值属性的指定位置

add(Object attrVal) , 追加属性值到多值属性尾部

判断属性值是否包含

contains(Object attrVal) , 多值属性中有一个值是匹配的,返回true

获取属性值

get(),取得属性值中的一个

get(int ix),从多值属性中的指定位置取值

获取属性ID

getID(),属性的ID就是属性名

删除属性值

remove(int ix),删除指定位置的属性值

remove(Object attrval),删除指定的属性值

javax.naming.directory.BasicAttributes,LDAP实体的属性集

该类表示一个LDAP条目绑定的属性集合,在绝大多数情况下,一个LDAP条目存在多个属性。

构造属性集

BasicAttributes()

BasicAttributes(boolean ignoreCase),属性ID是否大小写敏感,建议不要使用敏感

BasicAttributes(String attrID, Object val)

BasicAttributes(String attrID, Object val, boolean ignoreCase)

获取属性集中的单个属性对象

get(String attrID)

获取全部属性的枚举

getAll()

获取全部属性的ID枚举

getIDs()

添加新属性

put(Attribute attr)

put(String attrID, Ob

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值