java对Ldap操作Word格式文档下载.docx
- 文档编号:17215731
- 上传时间:2022-11-29
- 格式:DOCX
- 页数:14
- 大小:17.81KB
java对Ldap操作Word格式文档下载.docx
《java对Ldap操作Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《java对Ldap操作Word格式文档下载.docx(14页珍藏版)》请在冰豆网上搜索。
SearchControls
类
OBJECT_SCOPE,
ONELEVEL_SCOPE,
SUBTREE_SCOPE三个查询范围,分别代表
当前对象查询、当前节点下对象查询、当前节点所有子目录查询
distinct
true,去掉结构中的重复值;
false
允许结果中包含重复值
@return
查询范围下返回的cn列表
List&
lt;
String&
gt;
getAllPersonNames(int
scope,
boolean
distinct)
//
存储查询结果的集合
final
ArrayList&
allPersonCnList
new
();
使用ldapTemplate提供的接口查询,objectclass=person
表示对象为person的对象
ldapTemplate.search(&
quot;
&
(objectclass=person)&
createSearchControls(scope),
AttributesMapper()
Object
mapFromAttributes(Attributes
attrs)
throws
NamingException
获取cn的属性,用户名存在cn中
Attribute
attr
attrs.get(&
cn&
);
若没有该属性返回null
if
(attr
==
null)
return
null;
}
else
...{
获取属性
若包含多个cn属性,需要循环获取
Enumeration
ent
attr.getAll();
while
(ent.hasMoreElements())
allPersonCnList.add(ent.nextElement()
.toString());
});
true,去掉结果中的重复值
(distinct)
templist
for
(String
cn
:
allPersonCnList)
(!
templist.contains(cn))
templist.add(cn);
返回无重复值的结果
templist;
返回包含重复值的结果
allPersonCnList;
查询指定范围下的所有用户信息
查询范围下返回的所有用户信息列表
List
getAllPersons(int
scope)
LdapObjectAttributesMapper());
根据Uid查询用户信息,*代表任意长度的任意字符
uid
用户的uid
用户信息
getPersonByUid(String
uid,
int
uid
和
objectclass
组成联合查询条件,两个同时满足的查询结果
(&
amp;
(objectclass=person)(uid=&
+
))&
createSearchControls(scope),
查询包含当前Cn信息的所有用户,*代表任意长度的任意字符
cn
用户的cn
用户列表
getPersonByCn(String
cn,
(objectclass=person)(cn=&
返回查询控制器对象
createSearchControls(int
查询控制类SearchControls设定查询范围
constraints
SearchControls();
constraints.setSearchScope(scope);
constraints;
使用LdapPersonInfo类对象实现复合查询,属性中可使用通配符*,*代表任意长度的任意字符
ldapPersonInfo
查询条件
getPersonByPersonEnty(LdapPersonInfo
ldapPersonInfo,
strb存储、组装查询条件集合
StringBuffer
strb
StringBuffer(&
属性
(ldapPersonInfo.getUid()
!
null
ldapPersonInfo.getUid()
)
strb.append(&
(uid=&
)&
givenname
(ldapPersonInfo.getFirstName()
null
ldapPersonInfo.getFirstName()
(givenname=&
sn
(ldapPersonInfo.getLastName()
ldapPersonInfo.getLastName()
(sn=&
(ldapPersonInfo.getCn()
ldapPersonInfo.getCn().size()
0)
(int
i
0;
ldapPersonInfo.getCn().size();
i++)
(cn=&
ldapPersonInfo.getCn().get(i)
telephonenumber
(ldapPersonInfo.getTelephone()
ldapPersonInfo.getTelephone()
(telephonenumber=&
ldapPersonInfo.getTelephone()
facsimiletelephonenumber
(ldapPersonInfo.getFax()
ldapPersonInfo.getFax()
(facsimiletelephonenumber=&
ldapPersonInfo.getFax()
(ldapPersonInfo.getMail()
ldapPersonInfo.getMail()
(mail=&
String
filter
).toString();
filter,
根据dn查找用户,dn为base
dn
的相对dn.(若basedn为:
dc=koal,dc=com,user
dn为:
uid=123,dc=koal,dc=com,则此处只需要提供
123
作为参数)
dn
相对base
dn的dn参数
LdapPersonInfo
getLdapObjectByDn(String
dn)
(LdapPersonInfo)
ldapTemplate.lookup(dn,
登陆验证
userDn
用户的user
password
用户登陆密码
登陆成功返回true,不成功返回false
loginCheack(String
userDn,
password)
获取DirContext对象
DirContext
ctxs
ldapTemplate.getContextSource().getReadOnlyContext();
try
组装登陆ldap需要的信息数据
Hashtable&
Object,
Object&
ht
获取已有的登陆信息
(Hashtable&
ctxs.getEnvironment();
设置用户
ht.put(Context.SECURITY_PRINCIPAL,
userDn);
设置用户登陆密码
ht.put(Context.SECURITY_CREDENTIALS,
password);
设置用户验证方式为simple
ht.put(Context.SECURITY_AUTHENTICATION,
simple&
出现异常时表示用当前登陆人登陆失败
c
InitialDirContext(ht);
c.close();
true;
catch
(Exception
e)
e.printStackTrace();
System.out.println(&
login
false&
false;
finally
ctxs.close();
ie)
验证用户登陆
用户uid
用户密码
是否登陆成功
userLogin(String
获取用户id所在ldap中的user
dnlist
getUserDnByUid(uid);
根据查询到的所有dn遍历,检查是否某一user
dn与用户密码可以登陆ldap
(Object
dnlist)
(loginCheack(dn.toString(),
true)
查询用户user
用户dn列表,当前目录节点下可能存在多个相同uid的多个user
getUserDnByUid(String
uid)
获取DirC
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java Ldap 操作