http://hi.baidu.com/five00/blog/item/8bccc213cdbb83065aaf53b2.html
1. ????? 使用 Spring 配置文件配置 Ldap 認證源
在 Spring 中配置 Ldap 的過程與配置 JDBC 的過程類似, Ldap 比 JDBC 多出一個 base 屬性,這個是配置 Ldap 基結點( 注意:這個基結點不僅僅指最高父節點 ),之后 Ldap 會查找基節點下所有子節點的信息。
< 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 >
注意紅字標示部分 " ou=People,ou=rootOrg,o=sevenSeas " 的順序,這句話的意思是:基節點的位置是 sevenSeas 父節點下的 rootOrg 節點下的 People 節點;再次強調,這個解釋是由于順序的原因,父節點要在子節點的右面這樣,當前 Ldap 源的數據就是在這個基節點下的各子節點中操作。
如圖:
people 基節點下的用戶
2. ????? SpringTemplate 的 Ldap 測試代碼編寫
在配置文件中,需要配置數據源和 LdapTemplate , LdapTemplate 就是 Spring 提供的操作 Ldap 服務器數據的類。
配置文件 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 >
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
