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

系统 1568 0

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 >

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


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论