http://hi.baidu.com/five00/blog/item/8bccc213cdbb83065aaf53b2.html
1. ????? 使用 Spring 配置文件配置 Ldap 認(rèn)證源
在 Spring 中配置 Ldap 的過(guò)程與配置 JDBC 的過(guò)程類(lèi)似, Ldap 比 JDBC 多出一個(gè) base 屬性,這個(gè)是配置 Ldap 基結(jié)點(diǎn)( 注意:這個(gè)基結(jié)點(diǎn)不僅僅指最高父節(jié)點(diǎn) ),之后 Ldap 會(huì)查找基節(jié)點(diǎn)下所有子節(jié)點(diǎn)的信息。
< bean? id = "ldapContextSource"
??????? class = "org.springframework.ldap.support.LdapContextSource" >
??? < property? name = "url"? value = "ldap://localhost:10389"? />
??? < property? name = "base"? value = " ou=People,ou=rootOrg,o=sevenSeas "? />
??? < property? name = "userName"? value = "uid=admin,ou=system"? />
??? < property? name = "password"? value = "secret"? />
</ bean >
注意紅字標(biāo)示部分 " ou=People,ou=rootOrg,o=sevenSeas " 的順序,這句話(huà)的意思是:基節(jié)點(diǎn)的位置是 sevenSeas 父節(jié)點(diǎn)下的 rootOrg 節(jié)點(diǎn)下的 People 節(jié)點(diǎn);再次強(qiáng)調(diào),這個(gè)解釋是由于順序的原因,父節(jié)點(diǎn)要在子節(jié)點(diǎn)的右面這樣,當(dāng)前 Ldap 源的數(shù)據(jù)就是在這個(gè)基節(jié)點(diǎn)下的各子節(jié)點(diǎn)中操作。
如圖:
people 基節(jié)點(diǎn)下的用戶(hù)
2. ????? SpringTemplate 的 Ldap 測(cè)試代碼編寫(xiě)
在配置文件中,需要配置數(shù)據(jù)源和 LdapTemplate , LdapTemplate 就是 Spring 提供的操作 Ldap 服務(wù)器數(shù)據(jù)的類(lèi)。
配置文件 applicationContext-ldap.xml :
<? xml? version = "1.0"? encoding = "UTF-8" ?>
< beans? xmlns = "http://www.springframework.org/schema/beans"
???? xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
???? xmlns:aop = "http://www.springframework.org/schema/aop"
???? xsi:schemaLocation = "http://www.springframework.org/schema/beans?????http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
????http://www.springframework.org/schema/aop
????http://www.springframework.org/schema/aop/spring-aop-2.0.xsd" >
??? ?? < bean? id = "ldapContextSource"
???????? class = "org.springframework.ldap.support.LdapContextSource" >
???? < property? name = "url"? value = "ldap://localhost:10389"? />
???? < property? name = "base"? value = "ou=People,ou=rootOrg,o=sevenSeas"? />
???? < property? name = "userName"? value = "uid=admin,ou=system"? />
???? < property? name = "password"? value = "secret"? />
???? </ bean >
??? ?? < bean? id = "ldapTemplate"? class = "org.springframework.ldap.LdapTemplate" >
?????? < property? name = "contextSource"? ref = "ldapContextSource"? />
???? </ bean > ???
</ beans >
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元

