---
title: "CAS连接微软活动目录的配置方法"
author: "cjc"
date: "2009-02-02T09:09:00Z"
tags: []
slug: "cas"
draft: false
lastmod: "2009-02-02T09:09:00Z"
id: 446873
url: "https://cjc.iteye.com/blog/446873"
---

&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;beans xmlns="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)"  
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
xmlns:p="[http://www.springframework.org/schema/p](http://www.springframework.org/schema/p)"  
xsi:schemaLocation="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans) [http://www.springframework.org/schema/beans/spring-beans-2.0.xsd](http://www.springframework.org/schema/beans/spring-beans-2.0.xsd)"&gt;  
&lt;bean id="authenticationManager"  
class="org.jasig.cas.authentication.AuthenticationManagerImpl"&gt;  
&lt;property name="credentialsToPrincipalResolvers"&gt;  
&lt;list&gt;  
&lt;bean  
class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" /&gt;  
&lt;bean  
class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" /&gt;  
&lt;/list&gt;  
&lt;/property&gt;

&lt;property name="authenticationHandlers"&gt;  
&lt;list&gt;  
&lt;bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"  
p:httpClient-ref="httpClient" /&gt;  
&lt;!--&lt;bean  
class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" /&gt;--&gt;

&lt;bean class="org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler" &gt;  
&lt;property name="filter" value="uid=%u" /&gt;  
&lt;!--seem must have ou node--&gt;  
&lt;!--&lt;property name="searchBase" value="ou=nsc,dc=nhncdev,dc=com" /&gt; --&gt;  
&lt;property name="searchBase" value="ou=nsc,dc=nhncdev,dc=com" /&gt;  
&lt;property name="contextSource" ref="contextSource" /&gt;  
&lt;/bean&gt;

&lt;/list&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="userDetailsService" class="org.springframework.security.userdetails.memory.InMemoryDaoImpl"&gt;  
&lt;property name="userMap"&gt;  
&lt;value&gt;

&lt;/value&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="attributeRepository"  
class="org.jasig.services.persondir.support.StubPersonAttributeDao"&gt;  
&lt;property name="backingMap"&gt;  
&lt;map&gt;  
&lt;entry key="uid" value="uid" /&gt;  
&lt;entry key="eduPersonAffiliation" value="eduPersonAffiliation" /&gt;  
&lt;entry key="groupMembership" value="groupMembership" /&gt;  
&lt;/map&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;bean  
id="serviceRegistryDao"  
class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl" /&gt;

&lt;bean id="contextSource" class="org.jasig.cas.adaptors.ldap.util.AuthenticatedLdapContextSource"&gt;

&lt;property name="anonymousReadOnly" value="false" /&gt;

&lt;property name="userName" value="cn=zhenyu wang,ou=nsc,dc=nhncdev,dc=com" /&gt;  
&lt;property name="password" value="Hello123" /&gt;

&lt;property name="pooled" value="true" /&gt;  
&lt;property name="urls"&gt;  
&lt;list&gt;  
&lt;value&gt;ldap://10.34.114.54:389/&lt;/value&gt;  
&lt;/list&gt;  
&lt;/property&gt;

&lt;property name="baseEnvironmentProperties"&gt;  
&lt;map&gt;  
&lt;entry&gt;  
&lt;key&gt;&lt;value&gt;java.naming.security.authentication&lt;/value&gt;&lt;/key&gt;  
&lt;value&gt;simple&lt;/value&gt;  
&lt;/entry&gt;  
&lt;/map&gt;  
&lt;/property&gt;  
&lt;/bean&gt;

&lt;/beans&gt;

说明:在微软活动目录中建立一个用户节点,帐号为wangzhenyu,cn为zhenyu wang,并设置登陆口令,这时候在cas中用wangzhenyu的帐号登陆失败,解决办法是:安装apache directory studio,建立一个到微软活动目录的连接,连接时使用微软活动目录所在的windows2003服务器的超级用户帐号,连接成功后,在LDAP树中找从ou=nsc下找i到CN=zhengyu wang这个节点,给这个节点手工添加一个uid属性，设置uid的值为wangzhenyu,添加成功后，在cas登陆页面中再使用wangzhenyu帐号及ad中设置的口令就可以成功登录了．

--openjweb作者 ldap ad