单点登录CAS及LDAP整合的实现.doc
-在做SOA工程或者单点登录的时候,用户目录往往都是通过LDAP来完成的,则CAS与LDAP整合的问题是必须要做的,这里采用OpenLDAP和CAS来记录一下自己的配置过程1. 下载CAS Server 2. 下载CAS Client 3. 下载OpenLDAP 都安装完成配置完成后,下面做CAS+OpenLDAP整合至于配置过程,见我的另一篇博客文章:【推荐】单点登录的实现 ,在cas的web工程下翻开:deployerConfigConte*t.*ml,配置文件修改如下:*ml代码 1. <"*mlversion="1.0"encoding="UTF-8">2. <!DOCTYPE beans PUBLIC "-/SPRING/DTD BEAN/EN" ".springframework.org/dtd/spring-beans.dtd">3. <!- 4. | deployerConfigConte*t.*ml centralizes into one file some of the declarative configuration that 5. | all CAS deployers will need to modify. 6. | 7. | This file declares some of the Spring-managed JavaBeans that make up a CAS deployment. 8. | The beans declared in this file are instantiated at conte*t initialization time by the Spring 9. | Conte*tLoaderListener declared in web.*ml. It finds this file because this 10. | file is among those declared in the conte*t parameter "conte*tConfigLocation". 11. | 12. | By far the most mon change you will need to make in this file is to change the last bean 13. | declaration to replace the default SimpleTestUsernamePasswordAuthenticationHandler with 14. | one implementing your approach for authenticating usernames and passwords. 15. +->16. <beans>17. <!- 18. | This bean declares our AuthenticationManager. The CentralAuthenticationService service bean 19. | declared in applicationConte*t.*ml picks up this AuthenticationManager by reference to its id, 20. | "authenticationManager". Most deployers will be able to use the default AuthenticationManager 21. | implementation and so do not need to change the class of this bean. We include the whole 22. | AuthenticationManager here in the userConfigConte*t.*ml so that you can see the things you will 23. | need to change in conte*t. 24. +->25. <beanid="authenticationManager"26. class="org.jasig.cas.authentication.AuthenticationManagerImpl">27. <!- 28. | This is the List of CredentialToPrincipalResolvers that identify what Principal is trying to authenticate. 29. | The AuthenticationManagerImpl considers them in order, finding a CredentialToPrincipalResolver which 30. | supports the presented credentials. 31. | 32. | AuthenticationManagerImpl uses these resolvers for two purposes. First, it uses them to identify the Principal 33. | attempting to authenticate to CAS /login . In the default configuration, it is the DefaultCredentialsToPrincipalResolver 34. | that fills this role. If you are using some other kind of credentials than UsernamePasswordCredentials, you will need to replace 35. | DefaultCredentialsToPrincipalResolver with a CredentialsToPrincipalResolver that supports the credentials you are 36. | using. 37. | 38. | Second, AuthenticationManagerImpl uses these resolvers to identify a service requesting a pro*y granting ticket. 39. | In the default configuration, it is the HttpBasedServiceCredentialsToPrincipalResolver that serves this purpose. 40. | You will need to change this list if you are identifying services by something more or other than their callback URL. 41. +->42. <propertyname="credentialsToPrincipalResolvers">43. <list>44. <!- 45. | UsernamePasswordCredentialsToPrincipalResolver supports the UsernamePasswordCredentials that we use for /login 46. | by default and produces SimplePrincipal instances conveying the username from the credentials. 47. | 48. | If you've changed your LoginFormAction to use credentials other than UsernamePasswordCredentials then you will also 49. | need to change this bean declaration (or add additional declarations) to declare a CredentialsToPrincipalResolver that supports the 50. | Credentials you are using. 51. +->52. <beanclass="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver"/>53. <!- 54. | HttpBasedServiceCredentialsToPrincipalResolver supports HttpBasedCredentials. It supports the CAS 2.0 approach of 55. | authenticating services by SSL callback, e*tracting the callback URL from the Credentials and representing it as a 56. | SimpleService identified by that callback URL. 57. | 58. | If you are representing services by something more or other than an HTTPS URL whereat they are able to 59. | receive a pro*y callback, you will need to change this bean declaration (or add additional declarations). 60. +->61. <bean62. class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver"/>63. </list>64. </property>65. <!- 66. | Whereas CredentialsToPrincipalResolvers identify who it is some Credentials might authenticate, 67. | AuthenticationHandlers actually authenticate credentials. Here we declare the AuthenticationHandlers that 68. | authenticate the Principals that the CredentialsToPrincipalResolvers identified. CAS will try these handlers in turn 69. | until it finds one that both supports the Credentials presented and succeeds in authenticating. 70. +->71. <propertyname="authenticationHandlers">72. <list>73. <!- 74. | This is the authentication handler that authenticates services by means of callback via SSL, thereby validating 75. | a server side SSL certificate. 76. +->77. <bean78. class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"/>79. <!- 80. | This is the authentication handler declaration that every CAS deployer will need to change before deploying CAS 81. | into production. The default SimpleTestUsernamePasswordAuthenticationHandler authenticates UsernamePasswordCredentials 82. | where the username equals the password. You will need to replace this with an AuthenticationHandler that implements your 83. | local authentication strategy. You might acplish this by coding a new such handler and declaring 84. | edu.someschool.its.cas.MySpecialHandler here, or you might use one of the handlers provided in the adaptors modules. 85. +->86. <beanclass="org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler">87. <propertyname="filter"value="uid=%u"/>88. <propertyname="searchBase"value="o=nbpt,c="/>89. <propertyname="conte*tSource"ref="conte*tSource"/>90. </bean>91. </list>92. </property>93. </bean>94. <beanid="conte*tSource"class="org.jasig.cas.adaptors.ldap.util.AuthenticatedLdapConte*tSource">95. <propertyname="anonymousReadOnly"value="false"/>96. <propertyname="password"value="password"/>97. <propertyname="pooled"value="true"/>98. <propertyname="urls">99. <list>100. <value>ldap:/localhost:389/</value>101. </list>102. </property>103. <propertyname="userName"value="=manager,o=nbpt,c="/>104. <propertyname="baseEnvironmentProperties">105. <map>106. <entry>107. <key><value></value></key>108. <value>none</value>109. </entry>110. <entry>111. <key><value></value></key>112. <value>simple</value>113. </entry>114. </map>115. </property>116. </bean>117. <!- 118. This bean defines the security roles for the Services Management application. Simple deployments can use the in-memory version. 119. More robust deployments will want to use another option, such as the Jdbc version. 120. The name of this should remain "userDetailsService" in order for Acegi to find it. 121. To use this, you should add an entry similar to the following between the two value tags: 122. battags=notused,ROLE_ADMIN 123. where battags is the username you want to grant access to. You can put one entry per line. 124. ->125. <beanid="userDetailsService"class="org.springframework.security.userdetails.memory.InMemoryDaoImpl">126. <propertyname="userMap">127. <value>128. </value>129. </property>130. </bean>131. <!- 132. Bean that defines the attributes that a service may return. This e*ample uses the Stub/Mock version. A real implementation 133. may go against a database or LDAP server. The id should remain "attributeRepository" though. 134. ->135. <beanid="attributeRepository"136. class="org.jasig.services.persondir.support.StubPersonAttributeDao">137. <propertyname="backingMap">138. <map>139. <entrykey="uid"value="uid"/>140. <entrykey="eduPersonAffiliation"value="eduPersonAffiliation"/>141. <entrykey="groupMembership"value="groupMembership"/>142. </map>143. </property>144. </bean>145. <!- 146. Sample, in-memory data store for the ServiceRegistry. A real implementation 147. would probably want to replace this with the JPA-backed ServiceRegistry DAO 148. The name of this bean should remain "serviceRegistryDao". 149. ->150. <bean151. id="serviceRegistryDao"152. class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl"/>153. </beans><"*ml version="1.0" encoding="UTF-8"><!DOCTYPE beans PUBLIC "-/SPRING/DTD BEAN/EN" ".springframework.org/dtd/spring-beans.dtd"><!-| deployerConfigConte*t.*ml centralizes into one file some of the declarative configuration that| all CAS deployers will need to modify.| This file declares some of the Spring-managed JavaBeans that make up a CAS deployment. | The beans declared in this file are instantiated at conte*t initialization time by the Spring | Conte*tLoaderListener declared in web.*ml. It finds this file because this| file is among those declared in the conte*t parameter "conte*tConfigLocation".| By far the most mon change you will need to make in this file is to change the last bean| declaration to replace the default SimpleTestUsernamePasswordAuthenticationHandler with| one implementing your approach for authenticating usernames and passwords.+-><beans><!-| This bean declares our AuthenticationManager. The CentralAuthenticationService service bean| declared in applicationConte*t.*ml picks up this AuthenticationManager by reference to its id, | "authenticationManager". Most deployers will be able to use the default AuthenticationManager| implementation and so do not need to change the class of this bean. We include the whole| AuthenticationManager here in the userConfigConte*t.*ml so that you can see the things you will| need to change in conte*t.+-><bean id="authenticationManager"class="org.jasig.cas.authentication.AuthenticationManagerImpl"><!-| This is the List of CredentialToPrincipalResolvers that identify what Principal is trying to authenticate.| The AuthenticationManagerImpl considers them in order, finding a CredentialToPrincipalResolver which | supports the presented credentials.| AuthenticationManagerImpl uses these resolvers for two purposes. First, it uses them to identify the Principal| attempting to authenticate to CAS /login . In the default configuration, it is the DefaultCredentialsToPrincipalResolver| that fills this role. If you are using some other kind of credentials than UsernamePasswordCredentials, you will need to replace| DefaultCredentialsToPrincipalResolver with a CredentialsToPrincipalResolver that supports the credentials you are| using.| Second, AuthenticationManagerImpl uses these resolvers to identify a service requesting a pro*y granting ticket. | In the default configuration, it is the HttpBasedServiceCredentialsToPrincipalResolver that serves this purpose. | You will need to change this list if you are identifying services by something more or other than their callback URL.+-><property name="credentialsToPrincipalResolvers"><list><!-| UsernamePasswordCredentialsToPrincipalResolver supports the UsernamePasswordCredentials that we use for /login | by default and produces SimplePrincipal instances conveying the username from the credentials.| | If you've changed your LoginFormAction to use credentials other than UsernamePasswordCredentials then you will also| need to change this bean declaration (or add additional declarations) to declare a CredentialsToPrincipalResolver that supports the| Credentials you are using.+-><beanclass="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" /><!-| HttpBasedServiceCredentialsToPrincipalResolver supports HttpBasedCredentials. It supports the CAS 2.0 approach of| authenticating services by SSL callback, e*tracting the callback URL from the Credentials and representing it as a| SimpleService identified by that callback URL.| If you are representing services by something more or other than an HTTPS URL whereat they are able to| receive a pro*y callback, you will need to change this bean declaration (or add additional declarations).+-><beanclass="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" /></list></property><!-| Whereas CredentialsToPrincipalResolvers identify who it is some Credentials might authenticate, | AuthenticationHandlers actually authenticate credentials. Here we declare the AuthenticationHandlers that| authenticate the Principals that the CredentialsToPrincipalResolvers identified. CAS will try these handlers in turn| until it finds one that both supports the Credentials presented and succeeds in authenticating.+-><property name="authenticationHandlers"><list><!-| This is the authentication handler that authenticates services by means of callback via SSL, thereby validating| a server side SSL certificate.+-><beanclass="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" /><!-| This is the authentication handler declaration that every CAS deployer will need to change before deploying CAS | into production. The default SimpleTestUsernamePasswordAuthenticationHandler authenticates UsernamePasswordCredentials| where the us