cas-ad支持ldap的配置方法

CAS-Ad.war进行解包,增加两个jar文件到web-inf/lib目录下,

1.   cas-server-support-ldap-3.4.2.1.jar

2.   spring-ldap-core-1.3.2.RELEASE.jar

注:因为cas-server中采用了Spring的框架,所以需要加入spring-ldapjar文件,另外cas-server-support-ldapcas-server/modules下面

 

修改cas-ad/ WEB-INF/ deployerConfigContext.xml

1.   找到authenticationManager

2.   找到authenticationHandlers

3.   <bean

class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" /> 注释掉

4.   在注释的配置下面增加

<bean class="org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler"

                   p:filter="sAMAccountName=%u"

                   p:searchBase="ou=根路径,dc=域名,dc=com"

                   p:contextSource-ref="contextSource"

                   p:ignorePartialResultException="true" />

   请根据应用的环境替换oudc的信息

 

5.   authenticationManager下面增加新的bean

<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">

  <!-- DO NOT enable JNDI pooling for context sources that perform LDAP bind operations. -->

  <property name="pooled" value="false"/>

 

  <!--

    Although multiple URLs may defined, it's strongly recommended to avoid this configuration

    since the implementation attempts hosts in sequence and requires a connection timeout

    prior to attempting the next host, which incurs unacceptable latency on node failure.

    A proper HA setup for LDAP directories should use a single virtual host that maps to multiple

    real hosts using a hardware load balancer.

  -->

  <property name="url" value="LDAP://192.168.0.1:389" />

 

  <!--  请根据环境信息更换url的地址以及下面的链接帐号信息

    Manager credentials are only required if your directory does not support anonymous searches.

    Never provide these credentials for FastBindLdapAuthenticationHandler since the user's

    credentials are used for the bind operation.

  -->

  <property name="userDn" value="test\test_admin"/>

  <property name="password" value="123"/>

 

  <!-- Place JNDI environment properties here. -->

  <property name="baseEnvironmentProperties">

    <map>

      <!-- Three seconds is an eternity to users. -->

      <entry key="com.sun.jndi.ldap.connect.timeout" value="3000" />

      <entry key="com.sun.jndi.ldap.read.timeout" value="3000" />

 

      <!-- Explained at http://download.oracle.com/javase/1.3/docs/api/javax/naming/Context.html#SECURITY_AUTHENTICATION -->

      <entry key="java.naming.security.authentication" value="simple" />

    </map>

  </property>

  </bean>

 

 

完成以上修改后,将改好的cas-ad文件夹进行打包,打包示例:

jar cvf cas-ad.war -C cas-ad /.

-C是指的当前需要编译的目录  /.是包含所有的内容

 

重新部署后,可访问LDAP域信息了

 

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

补充下关于LDAP的知识  转载于

常用的LDAP服务器有以下几种

     1:Apache directory server

     2:Sun directory server 

     3:openDS 一个开源的,基于LDAPDSML标准的Directory serviceDirectory service不仅包括Directory server,还有其它与directory相关的基本servicedirectory  proxyvirtual dirctorynamespace distribution和数据同步Directory server是一个可以通过网络访问,信息分级存储的数据库。OpenDS只能用在linux操作系统。该项目的地址为:http://www.opends.org/ 

    4: Netscape Directory Server

    5: Window AD

    6: IBM Tivoli Diectory Server

 

LDAP认证配置有两种:

 

[第一种]FastBindLdapAuthenticationHandler

这种认证处理器一般用于DN是由用户名直接组成的,比如:uid=%u,ou=dev,dc=micmiu.com,dc=com ,其中 %u 就是CAS

录的用户名。

修改web的配置文件 WEB-INF\deployerConfigContext.xml

首先在<beans>根节点下添加beanContextSource 的配置:

 <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">

   <property name="pooled" value="false"/>

   <property name="url" value="ldap://ldapServerIp:389" />

   <property name="userDn" value="cn=root"/>

   <property name="password" value="your_password"/>

   <property name="baseEnvironmentProperties">

     <map>

       <entry key="com.sun.jndi.ldap.connect.timeout" value="3000" />

       <entry key="com.sun.jndi.ldap.read.timeout" value="3000" />

       <entry key="java.naming.security.authentication" value="simple" />

     </map>

   </property>

 </bean>

 

ContextSource 的配置说明:

(1)如果有多个LDAP服务器,可以通过参数urls 配置多个。

(2)FastBindLdapAuthenticationHandler配置时,这里的userDn 可以配置成 “cn=root,ou=dev,dc=micmiu,dc=com”

“cn=root,ou=dev”  “cn=root” “root” 这四个都可以。其中的cn=rootLDAP服务器实例的管理员用户,password为对应的密码

(3)如果LDAP服务器有SSL,注意url配置的前缀是ldaps”ldaps://ldapServerIp:636″

<bean id=”authenticationManager” />下找到SimpleTestUsernamePasswordAuthenticationHandler的配置,修改

成如下:

 <bean class="org.jasig.cas.adaptors.ldap.FastBindLdapAuthenticationHandler">

     <property name="filter" value="uid=%u,ou=dev,dc=micmiu,dc=com" />

     <property name="contextSource" ref="contextSource" />

 </bean>

 

[第二种]BindLdapAuthenticationHandler

这种认证处理器一般用于需要验证的用户名是DN的其他的属性比如email,而不是上面第一种处理器中的uid(当然uid属性同

样适用,下面我们配置的示例就还是用uid)。

修改web的配置文件 WEB-INF\deployerConfigContext.xml

同样在<beans>根节点下添加beanContextSource 的配置:

 <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">

     <property name="anonymousReadOnly" value="false" />

     <property name="password" value="your_password" />

     <property name="pooled" value="false" />

     <property name="urls">

         <list>

             <value>ldap://ldapServerIp:389</value>

         </list>

     </property>

     <property name="userDn" value="cn=root,dc=micmiu,dc=com" />

     <property name="baseEnvironmentProperties">

         <map>

             <!-- LDAP SSL访问配置

             <entry key="java.naming.security.protocol" value="ssl" />

                 -->

             <entry key="java.naming.security.authentication" value="simple" />

         </map>

     </property>

 </bean>

<bean id=”authenticationManager” />修改认证bean的配置,修改成如下:

 <bean class="org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler">

     <property name="filter" value="uid=%u" />

     <property name="searchBase" value="dc=micmiu,dc=com" />

     <property name="contextSource" ref="contextSource" />

     <!-- 允许多个账号-->

     <property name="allowMultipleAccounts" value="true" />

 </bean>

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值