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

http://hi.baidu.com/five00/blog/item/8bccc213cdbb83065aaf53b2.html

1.     使用Spring配置文件配置Ldap认证源

Spring中配置Ldap的过程与配置JDBC的过程类似,LdapJDBC多出一个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.     SpringTemplateLdap测试代码编写

在配置文件中,需要配置数据源和LdapTemplateLdapTemplate就是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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值