LDAP认证的两种方式

LDAP认证的两种方式

[第一种] FastBindLdapAuthenticationHandler
这种认证处理器一般用于DN是由用户名直接组成的,比如:uid=%u,ou=dev,dc=micmiu.com,dc=com ,其中 %u 就是CAS登录的用户名。
修改web的配置文件 WEB-INF\ deployerConfigContext.xml
首先在<beans> 跟节点下增加 bean ContextSource  的配置:
  1. <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">  
  2.   <property name="pooled" value="false"/>  
  3.   <property name="url" value="ldap://127.0.0.1:389" />  
  4.   <property name="userDn" value="cn=Manager"/>  
  5.   <property name="password" value="secret"/>  
  6.   <property name="baseEnvironmentProperties">  
  7. <map>  
  8.   <entry key="com.sun.jndi.ldap.connect.timeout" value="3000" />  
  9.   <entry key="com.sun.jndi.ldap.read.timeout" value="3000" />  
  10.   <entry key="java.naming.security.authentication" value="simple" />  
  11. </map>  
  12.   </property>  
  13. </bean>  
  在<bean id=”authenticationManager” /> 下找到 SimpleTestUsernamePasswordAuthenticationHandler 的配置,修改成如下:
  1. <bean class="org.jasig.cas.adaptors.ldap.FastBindLdapAuthenticationHandler">  
  2. <property name="filter" value="uid=%u,ou=Developer,dc=micmiu,dc=com" />  
  3. <property name="contextSource" ref="contextSource" />  
  4. </bean>  


[第二种] BindLdapAuthenticationHandler 

这种认证处理器一般用于需要验证的用户名是DN的其他的属性比如email,而不是上面第一种处理器中的uid(当然uid属性同样适用,下面我们配置的示例是用mail)。
修改web的配置文件 WEB-INF\ deployerConfigContext.xml
同样在<beans> 跟节点下增加 bean ContextSource  的配置:
  1. <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">  
  2. <property name="anonymousReadOnly" value="false" />  
  3. <property name="password" value="secret" />  
  4. <property name="pooled" value="true" />  
  5. <property name="urls">  
  6. <list>  
  7. <value>ldap://127.0.0.1:389</value>  
  8. </list>  
  9. </property>  
  10. <property name="userDn" value="cn=Manager,dc=micmiu,dc=com" />  
  11. <property name="baseEnvironmentProperties">  
  12. <map>  
  13. <!-- LDAP SSL访问配置  
  14. <entry key="java.naming.security.protocol" value="ssl" />  
  15. -->  
  16. <entry key="java.naming.security.authentication" value="simple" />  
  17. </map>  
  18. </property>  
  19. </bean>  
在<bean id=”Manaauthenticationger” /> 修改认证 bean 的配置,修改成如下:
  1. <bean class="org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler">  
  2. <property name="filter" value="mail=%u" />  
  3. <property name="searchBase" value="dc=micmiu,dc=com" />  
  4. <property name="contextSource" ref="contextSource" />  
  5. <!-- 允许多个账号-->  
  6. <property name="allowMultipleAccounts" value="true" />  
  7. </bean>  





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值