现在的位置: 首页 > 综合 > 正文

spring security +cas单点登录

2013年10月18日 ⁄ 综合 ⁄ 共 9094字 ⁄ 字号 评论关闭

cas服务端和cas客户端配好,访问cas服务端可以登录,访问客户端应用资源的时候出现拒绝访问问题 
首次登录直接出现拒绝访问 

cas服务端配置: 
cas.properties 

  1. #server.prefix=http://localhost:8080/cas   
  2. #server.prefix=http://cas.wucht.com:8080/casServer   
  3. server.prefix=http://localhost:8080/casServer   
  4.   
  5.   
  6. cas.securityContext.serviceProperties.service=${server.prefix}/j_acegi_cas_security_check  
  7. # Names of roles allowed to access the CAS service manager   
  8. cas.securityContext.serviceProperties.adminRoles=ROLE_ADMIN   
  9. cas.securityContext.casProcessingFilterEntryPoint.loginUrl=${server.prefix}/login   
  10. cas.securityContext.ticketValidator.casServerUrlPrefix=${server.prefix}   
  11.   
  12.   
  13. cas.themeResolver.defaultThemeName=cas-theme-default   
  14. #cas.themeResolver.defaultThemeName=default   
  15. cas.viewResolver.basename=default_views   
  16.   
  17. #host.name=cas   
  18. host.name=casServer   
  19.   
  20. #database.hibernate.dialect=org.hibernate.dialect.OracleDialect   
  21. database.hibernate.dialect=org.hibernate.dialect.MySQLDialect   
  22. #database.hibernate.dialect=org.hibernate.dialect.HSQLDialect   

deployerConfigContext.xml 

  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <!--   
  3. | deployerConfigContext.xml centralizes into one file some of the declarative configuration that   
  4. | all CAS deployers will need to modify.   
  5. |   
  6. | This file declares some of the Spring-managed JavaBeans that make up a CAS deployment.    
  7. | The beans declared in this file are instantiated at context initialization time by the Spring   
  8. | ContextLoaderListener declared in web.xml.  It finds this file because this   
  9. | file is among those declared in the context parameter "contextConfigLocation".   
  10. |   
  11. | By far the most common change you will need to make in this file is to change the last bean   
  12. | declaration to replace the default SimpleTestUsernamePasswordAuthenticationHandler with   
  13. | one implementing your approach for authenticating usernames and passwords.   
  14. +-->   
  15. <beans xmlns="http://www.springframework.org/schema/beans"   
  16.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  17.        xmlns:p="http://www.springframework.org/schema/p"   
  18.        xmlns:sec="http://www.springframework.org/schema/security"   
  19.        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   
  20.        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">   
  21. <!--   
  22. | This bean declares our AuthenticationManager.  The CentralAuthenticationService service bean   
  23. | declared in applicationContext.xml picks up this AuthenticationManager by reference to its id,   
  24. "authenticationManager".  Most deployers will be able to use the default AuthenticationManager   
  25. | implementation and so do not need to change the class of this bean.  We include the whole   
  26. | AuthenticationManager here in the userConfigContext.xml so that you can see the things you will   
  27. | need to change in context.   
  28. +-->   
  29. <bean id="authenticationManager"   
  30. class="org.jasig.cas.authentication.AuthenticationManagerImpl">   
  31. <!--   
  32. | This is the List of CredentialToPrincipalResolvers that identify what Principal is trying to authenticate.   
  33. | The AuthenticationManagerImpl considers them in order, finding a CredentialToPrincipalResolver which   
  34. | supports the presented credentials.   
  35. |   
  36. | AuthenticationManagerImpl uses these resolvers for two purposes.  First, it uses them to identify the Principal   
  37. | attempting to authenticate to CAS /login .  In the default configuration, it is the DefaultCredentialsToPrincipalResolver   
  38. | that fills this role.  If you are using some other kind of credentials than UsernamePasswordCredentials, you will need to replace   
  39. | DefaultCredentialsToPrincipalResolver with a CredentialsToPrincipalResolver that supports the credentials you are   
  40. | using.   
  41. |   
  42. | Second, AuthenticationManagerImpl uses these resolvers to identify a service requesting a proxy granting ticket.   
  43. | In the default configuration, it is the HttpBasedServiceCredentialsToPrincipalResolver that serves this purpose.   
  44. | You will need to change this list if you are identifying services by something more or other than their callback URL.   
  45. +-->   
  46.   
  47.   
  48. <property name="credentialsToPrincipalResolvers">   
  49. <list>   
  50. <!--   
  51. | UsernamePasswordCredentialsToPrincipalResolver supports the UsernamePasswordCredentials that we use for /login   
  52. | by default and produces SimplePrincipal instances conveying the username from the credentials.   
  53. |   
  54. | If you've changed your LoginFormAction to use credentials other than UsernamePasswordCredentials then you will also   
  55. | need to change this bean declaration (or add additional declarations) to declare a CredentialsToPrincipalResolver that supports the   
  56. | Credentials you are using.   
  57. +-->   
  58. <bean   
  59. class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver">  
  60. <!--增加此属性,为认证过的用户的Principal添加属性-->   
  61. <property name="attributeRepository" ref="attributeRepository"></property>   
  62. </bean>   
  63. <!--   
  64. | HttpBasedServiceCredentialsToPrincipalResolver supports HttpBasedCredentials.  It supports the CAS 2.0 approach of   
  65. | authenticating services by SSL callback, extracting the callback URL from the Credentials and representing it as a   
  66. | SimpleService identified by that callback URL.   
  67. |   
  68. | If you are representing services by something more or other than an HTTPS URL whereat they are able to   
  69. | receive a proxy callback, you will need to change this bean declaration (or add additional declarations).   
  70. +-->   
  71. <bean   
  72. class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" />   
  73. </list>   
  74. </property>   
  75.   
  76. <!--   
  77. | Whereas CredentialsToPrincipalResolvers identify who it is some Credentials might authenticate,   
  78. | AuthenticationHandlers actually authenticate credentials.  Here we declare the AuthenticationHandlers that   
  79. | authenticate the Principals that the CredentialsToPrincipalResolvers identified.  CAS will try these handlers in turn   
  80. | until it finds one that both supports the Credentials presented and succeeds in authenticating.   
  81. +-->   
  82.   
  83.   
  84.   
  85. <property name="authenticationHandlers">   
  86. <list>   
  87. <!--   
  88. | This is the authentication handler that authenticates services by means of callback via SSL, thereby validating   
  89. | a server side SSL certificate.   
  90. +-->   
  91. <bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"  
  92. p:httpClient-ref="httpClient" />   
  93. <!--   
  94. | This is the authentication handler declaration that every CAS deployer will need to change before deploying CAS   
  95. | into production.  The default SimpleTestUsernamePasswordAuthenticationHandler authenticates UsernamePasswordCredentials   
  96. | where the username equals the password.  You will need to replace this with an AuthenticationHandler that implements your   
  97. | local authentication strategy.  You might accomplish this by coding a new such handler and declaring   
  98. | edu.someschool.its.cas.MySpecialHandler here, or you might use one of the handlers provided in the adaptors modules.   
  99. +-->   
  100.   
  101. <!--   
  102. <bean   
  103. class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" />   
  104. -->   
  105.   
  106. <!-- 数据库认证.wucht-->   
  107.   
  108. <bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">   
  109. <property name="dataSource" ref="dataSource" />   
  110. <property name="sql" value="select password from users where name=?" />   
  111. </bean>   
  112.   
  113. </list>   
  114. </property>   
  115. </bean>   
  116.   
  117.   
  118. <!-- DATABASE 增加数据源配置 -->   
  119. <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">   
  120. <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>   
  121. <property name="url"><value>jdbc:mysql://localhost:3306/mysql?useUnicode=true&amp;characterEncoding=utf-8</value></property>   
  122. <property name="username"><value>root</value></property>   
  123. <property name="password"><value>root</value></property>   
  124. </bean>   
  125.   
  126. <!--   
  127. This bean defines the security roles for the Services Management application.  Simple deployments can use the in-memory version.   
  128. More robust deployments will want to use another option, such as the Jdbc version.   
  129.   
  130. The name of this should remain "userDetailsService" in order for Spring Security to find it.   
  131. -->   
  132.     <!-- <sec:user name="@@THIS SHOULD BE REPLACED@@" password="notused" authorities="ROLE_ADMIN" />-->   
  133.   
  134.     <sec:user-service id="userDetailsService">   
  135.         <sec:user name="@@THIS SHOULD BE REPLACED@@" password="notused" authorities="ROLE_ADMIN" />   
  136.     </sec:user-service>   
  137.   
  138. <!--   
  139. Bean that defines the attributes that a service may return.  This example uses the Stub/Mock version.  A real implementation   
  140. may go against a database or LDAP server.  The id should remain "attributeRepository" though.   
  141. -->   
  142.   
  143. <!--   
  144. <bean id="attributeRepository"   
  145. class="org.jasig.services.persondir.support.StubPersonAttributeDao">   
  146. <property name="backingMap">   
  147. <map>   
  148. <entry key="uid" value="uid" />   
  149. <entry key="eduPersonAffiliation" value="eduPersonAffiliation" />   
  150. <entry key="groupMembership" value="groupMembership" />   
  151. </map>   
  152. </property>   
  153. </bean>   
  154. -->   

抱歉!评论已关闭.