首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

施用Spring配置文件配置Ldap认证源

2012-10-27 
使用Spring配置文件配置Ldap认证源http://hi.baidu.com/five00/blog/item/8bccc213cdbb83065aaf53b2.html1

使用Spring配置文件配置Ldap认证源
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源的数据就是在这个基节点下的各子节点中操作。

如图:

施用Spring配置文件配置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>

热点排行