---
title: "openjweb平台配置cas server单点登录"
author: "cjc"
date: "2009-08-05T13:20:00Z"
tags: []
slug: "openjweb-cas-server"
draft: false
lastmod: "2009-08-05T13:20:00Z"
id: 446830
url: "https://cjc.iteye.com/blog/446830"
---

web.xml:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;web-app xmlns="[http://java.sun.com/xml/ns/j2ee](http://java.sun.com/xml/ns/j2ee)"  
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)" version="2.4"  
xsi:schemaLocation="[http://java.sun.com/xml/ns/j2ee](http://java.sun.com/xml/ns/j2ee) [http://java.sun.com/xml/ns/j2ee/web-app\_2\_4.xsd](http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd)"&gt;  
&lt;display-name&gt;openjweb&lt;/display-name&gt;  
&lt;context-param&gt;  
&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;  
&lt;param-value&gt;  
/WEB-INF/classes/applicationContext-security-cas.xml  
/WEB-INF/classes/core-service-demo.xml  
/WEB-INF/classes/system-config.xml  
/WEB-INF/classes/CasContext.xml  
&lt;/param-value&gt;  
&lt;/context-param&gt;

&lt;context-param&gt;  
&lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;  
&lt;param-value&gt;/WEB-INF/classes/log4j.properties&lt;/param-value&gt;  
&lt;/context-param&gt;

&lt;filter&gt;  
&lt;filter-name&gt;Character Encoding&lt;/filter-name&gt;  
&lt;filter-class&gt;org.openjweb.core.filter.CharacterEncodingFilter&lt;/filter-class&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;encoding&lt;/param-name&gt;  
&lt;param-value&gt;UTF-8&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;ignore&lt;/param-name&gt;  
&lt;param-value&gt;false&lt;/param-value&gt;  
&lt;!-- &lt;param-value&gt;true&lt;/param-value&gt; --&gt;  
&lt;/init-param&gt;  
&lt;/filter&gt;

&lt;filter&gt;  
&lt;filter-name&gt;struts2&lt;/filter-name&gt;  
&lt;filter-class&gt;  
org.apache.struts2.dispatcher.FilterDispatcher  
&lt;/filter-class&gt;  
&lt;/filter&gt;

&lt;!--  
&lt;filter&gt;  
&lt;filter-name&gt;CAS Authentication Filter&lt;/filter-name&gt;  
&lt;filter-class&gt;org.jasig.cas.client.authentication.AuthenticationFilter&lt;/filter-class&gt;

&lt;init-param&gt;  
&lt;param-name&gt;casServerLoginUrl&lt;/param-name&gt;  
&lt;param-value&gt;https://casserver.haoyisheng.com:8443/cas/login&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;renew&lt;/param-name&gt;  
&lt;param-value&gt;false&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;gateway&lt;/param-name&gt;  
&lt;param-value&gt;false&lt;/param-value&gt;  
&lt;/init-param&gt;

&lt;init-param&gt;  
&lt;param-name&gt;serverName&lt;/param-name&gt;  
&lt;param-value&gt;http://bzwang.haoyisheng.com:8088&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;/filter&gt;

&lt;filter&gt;  
&lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;  
&lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;targetBeanName&lt;/param-name&gt;  
&lt;param-value&gt;cas.validationfilter&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;/filter&gt;

&lt;filter-mapping&gt;  
&lt;filter-name&gt;CAS Authentication Filter&lt;/filter-name&gt;  
&lt;url-pattern&gt;/comm/\*&lt;/url-pattern&gt;  
&lt;/filter-mapping&gt;

&lt;filter-mapping&gt;  
&lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;  
&lt;url-pattern&gt;/comm/\*&lt;/url-pattern&gt;  
&lt;/filter-mapping&gt;

--&gt;

&lt;filter-mapping&gt;  
&lt;filter-name&gt;Character Encoding&lt;/filter-name&gt;  
&lt;url-pattern&gt;\*.jsp&lt;/url-pattern&gt;  
&lt;/filter-mapping&gt;

&lt;filter-mapping&gt;  
&lt;filter-name&gt;Character Encoding&lt;/filter-name&gt;  
&lt;url-pattern&gt;\*.action&lt;/url-pattern&gt;  
&lt;/filter-mapping&gt;

&lt;filter&gt;  
&lt;filter-name&gt;CAS Single Sign Out Filter&lt;/filter-name&gt;  
&lt;filter-class&gt;org.jasig.cas.client.session.SingleSignOutFilter&lt;/filter-class&gt;  
&lt;/filter&gt;

&lt;filter&gt;  
&lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;  
&lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;  
&lt;/filter&gt;

&lt;filter-mapping&gt;  
&lt;filter-name&gt;CAS Single Sign Out Filter&lt;/filter-name&gt;  
&lt;url-pattern&gt;/\*&lt;/url-pattern&gt;  
&lt;/filter-mapping&gt;

&lt;filter-mapping&gt;  
&lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;  
&lt;url-pattern&gt;/\*&lt;/url-pattern&gt;  
&lt;/filter-mapping&gt;

&lt;filter-mapping&gt;  
&lt;filter-name&gt;struts2&lt;/filter-name&gt;  
&lt;url-pattern&gt;/\*&lt;/url-pattern&gt;  
&lt;/filter-mapping&gt;

&lt;listener&gt;  
&lt;listener-class&gt;org.jasig.cas.client.session.SingleSignOutHttpSessionListener&lt;/listener-class&gt;  
&lt;/listener&gt;

&lt;listener&gt;  
&lt;listener-class&gt;  
org.springframework.web.context.ContextLoaderListener  
&lt;/listener-class&gt;  
&lt;/listener&gt;

&lt;listener&gt;  
&lt;listener-class&gt;  
org.springframework.security.ui.session.HttpSessionEventPublisher  
&lt;/listener-class&gt;  
&lt;/listener&gt;

&lt;listener&gt;  
&lt;listener-class&gt;  
org.springframework.web.util.Log4jConfigListener  
&lt;/listener-class&gt;  
&lt;/listener&gt;

&lt;servlet&gt;  
&lt;servlet-name&gt;action&lt;/servlet-name&gt;  
&lt;servlet-class&gt;  
org.apache.struts.action.ActionServlet  
&lt;/servlet-class&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;config&lt;/param-name&gt;  
&lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;debug&lt;/param-name&gt;  
&lt;param-value&gt;3&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;detail&lt;/param-name&gt;  
&lt;param-value&gt;3&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;load-on-startup&gt;0&lt;/load-on-startup&gt;  
&lt;/servlet&gt; &lt;!--DWR --&gt;

&lt;servlet&gt;  
&lt;servlet-name&gt;dwr-invoker&lt;/servlet-name&gt;  
&lt;servlet-class&gt; org.directwebremoting.servlet.DwrServlet &lt;/servlet-class&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;debug&lt;/param-name&gt;  
&lt;param-value&gt;true&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;crossDomainSessionSecurity&lt;/param-name&gt;  
&lt;param-value&gt;false&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;load-on-startup&gt;3&lt;/load-on-startup&gt;  
&lt;/servlet&gt;

&lt;!--fckeditor servlet--&gt;  
&lt;servlet&gt;  
&lt;servlet-name&gt;Connector&lt;/servlet-name&gt;  
&lt;servlet-class&gt;com.fredck.FCKeditor.connector.ConnectorServlet&lt;/servlet-class&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;baseDir&lt;/param-name&gt;  
&lt;param-value&gt;/resupload/&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;debug&lt;/param-name&gt;  
&lt;param-value&gt;false&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;  
&lt;/servlet&gt;

&lt;servlet&gt;  
&lt;servlet-name&gt;SimpleUploader&lt;/servlet-name&gt;  
&lt;servlet-class&gt;com.fredck.FCKeditor.uploader.SimpleUploaderServlet&lt;/servlet-class&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;baseDir&lt;/param-name&gt;  
&lt;param-value&gt;/resupload/&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;debug&lt;/param-name&gt;  
&lt;param-value&gt;false&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;enabled&lt;/param-name&gt;  
&lt;param-value&gt;true&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;AllowedExtensionsFile&lt;/param-name&gt;  
&lt;param-value&gt;&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;DeniedExtensionsFile&lt;/param-name&gt;  
&lt;param-value&gt;php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;AllowedExtensionsImage&lt;/param-name&gt;  
&lt;param-value&gt;jpg|gif|jpeg|png|bmp&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;DeniedExtensionsImage&lt;/param-name&gt;  
&lt;param-value&gt;&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;AllowedExtensionsFlash&lt;/param-name&gt;  
&lt;param-value&gt;swf|fla&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;DeniedExtensionsFlash&lt;/param-name&gt;  
&lt;param-value&gt;&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;load-on-startup&gt;2&lt;/load-on-startup&gt;  
&lt;/servlet&gt;

&lt;!--  
&lt;servlet&gt;  
&lt;servlet-name&gt;easyjf&lt;/servlet-name&gt;  
&lt;servlet-class&gt;com.easyjf.web.ActionServlet&lt;/servlet-class&gt;  
&lt;/servlet&gt;

&lt;servlet&gt;  
&lt;servlet-name&gt;test&lt;/servlet-name&gt;  
&lt;servlet-class&gt;com.easyjf.action.CommAction&lt;/servlet-class&gt;  
&lt;/servlet&gt;

&lt;servlet-mapping&gt;  
&lt;servlet-name&gt;easyjf&lt;/servlet-name&gt;  
&lt;url-pattern&gt;\*.ejf&lt;/url-pattern&gt;  
&lt;/servlet-mapping&gt;

&lt;servlet-mapping&gt;  
&lt;servlet-name&gt;test&lt;/servlet-name&gt;  
&lt;url-pattern&gt;/testServlet&lt;/url-pattern&gt;  
&lt;/servlet-mapping&gt;

--&gt;

&lt;!--  
&lt;servlet&gt;  
&lt;servlet-name&gt;DisplayChart &lt;/servlet-name&gt;  
&lt;servlet-class&gt;  
org.jfree.chart.servlet.DisplayChart  
&lt;/servlet-class&gt;  
&lt;/servlet&gt;  
&lt;servlet-mapping&gt;  
&lt;servlet-name&gt;DisplayChart &lt;/servlet-name&gt;  
&lt;url-pattern&gt;/temp &lt;/url-pattern&gt;  
&lt;/servlet-mapping&gt;  
\--&gt;  
&lt;servlet-mapping&gt;  
&lt;servlet-name&gt;dwr-invoker&lt;/servlet-name&gt;  
&lt;url-pattern&gt;/dwr/\*&lt;/url-pattern&gt;  
&lt;/servlet-mapping&gt;

&lt;servlet-mapping&gt;  
&lt;servlet-name&gt;action&lt;/servlet-name&gt;  
&lt;url-pattern&gt;\*.do&lt;/url-pattern&gt;  
&lt;/servlet-mapping&gt;

&lt;session-config&gt;  
&lt;session-timeout&gt;30&lt;/session-timeout&gt;  
&lt;/session-config&gt;

&lt;welcome-file-list&gt;  
&lt;welcome-file&gt;/secure/redirect.jsp&lt;/welcome-file&gt;  
&lt;/welcome-file-list&gt;  
&lt;jsp-config&gt;  
&lt;taglib&gt;  
&lt;taglib-uri&gt;  
[http://www.springframework.org/security/tags](http://www.springframework.org/security/tags)  
&lt;/taglib-uri&gt;  
&lt;taglib-location&gt;/WEB-INF/security.tld&lt;/taglib-location&gt;  
&lt;/taglib&gt;

&lt;taglib&gt;  
&lt;taglib-uri&gt;/WEB-INF/struts-bean.tld&lt;/taglib-uri&gt;  
&lt;taglib-location&gt;/WEB-INF/tld/struts-bean.tld&lt;/taglib-location&gt;  
&lt;/taglib&gt;

&lt;taglib&gt;  
&lt;taglib-uri&gt;/WEB-INF/struts-html.tld&lt;/taglib-uri&gt;  
&lt;taglib-location&gt;/WEB-INF/tld/struts-html.tld&lt;/taglib-location&gt;  
&lt;/taglib&gt;

&lt;taglib&gt;  
&lt;taglib-uri&gt;/WEB-INF/struts-logic.tld&lt;/taglib-uri&gt;  
&lt;taglib-location&gt;/WEB-INF/tld/struts-logic.tld&lt;/taglib-location&gt;  
&lt;/taglib&gt;

&lt;taglib&gt;  
&lt;taglib-uri&gt;/WEB-INF/struts-nested.tld&lt;/taglib-uri&gt;  
&lt;taglib-location&gt;  
/WEB-INF/tld/struts-nested.tld  
&lt;/taglib-location&gt;  
&lt;/taglib&gt;

&lt;taglib&gt;  
&lt;taglib-uri&gt;/WEB-INF/struts-tiles.tld&lt;/taglib-uri&gt;  
&lt;taglib-location&gt;/WEB-INF/tld/struts-tiles.tld&lt;/taglib-location&gt;  
&lt;/taglib&gt;

&lt;/jsp-config&gt;

&lt;/web-app&gt;

applicationContext-security-cas.xml:

&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:sec="[http://www.springframework.org/schema/security](http://www.springframework.org/schema/security)"  
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
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)  
[http://www.springframework.org/schema/security](http://www.springframework.org/schema/security) [http://www.springframework.org/schema/security/spring-security-2.0.xsd](http://www.springframework.org/schema/security/spring-security-2.0.xsd)"&gt;

&lt;sec:http entry-point-ref="casProcessingFilterEntryPoint"&gt;  
&lt;sec:intercept-url pattern="/secure/extreme/\*\*" access="ROLE\_SUPERVISOR" requires-channel="https"/&gt;  
&lt;sec:intercept-url pattern="/secure/\*\*" access="ROLE\_USER" /&gt;  
&lt;sec:logout logout-success-url="/apps/index.jsp"/&gt;  
&lt;/sec:http&gt;

&lt;sec:authentication-manager alias="authenticationManager"/&gt;

&lt;bean id="casProcessingFilter" class="org.springframework.security.ui.cas.CasProcessingFilter"&gt;  
&lt;sec:custom-filter after="CAS\_PROCESSING\_FILTER"/&gt;  
&lt;property name="authenticationManager" ref="authenticationManager"/&gt;  
&lt;property name="authenticationFailureUrl" value="/casfailed.jsp"/&gt;  
&lt;property name="defaultTargetUrl" value="/apps/index.jsp" /&gt;  
&lt;property name="proxyGrantingTicketStorage" ref="proxyGrantingTicketStorage" /&gt;  
&lt;property name="proxyReceptorUrl" value="/secure/receptor" /&gt;

&lt;/bean&gt;

&lt;bean id="casProcessingFilterEntryPoint" class="org.springframework.security.ui.cas.CasProcessingFilterEntryPoint"&gt;  
&lt;property name="loginUrl" value="[https://crm.lucene.cn:8443/cas/login"/](https://crm.lucene.cn:8443/cas/login%22/)&gt;  
&lt;property name="serviceProperties" ref="serviceProperties"/&gt;  
&lt;/bean&gt;

&lt;bean id="casAuthenticationProvider" class="org.springframework.security.providers.cas.CasAuthenticationProvider"&gt;  
&lt;sec:custom-authentication-provider /&gt;  
&lt;property name="userDetailsService" ref="userDetailsService"/&gt;  
&lt;property name="serviceProperties" ref="serviceProperties" /&gt;  
&lt;property name="ticketValidator"&gt;  
&lt;bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator"&gt;  
&lt;constructor-arg index="0" value="[https://crm.lucene.cn:8443/cas](https://crm.lucene.cn:8443/cas)" /&gt;  
&lt;property name="proxyGrantingTicketStorage" ref="proxyGrantingTicketStorage" /&gt;  
&lt;property name="proxyCallbackUrl" value="[https://crm.lucene.cn:8443/crm/secure/receptor](https://crm.lucene.cn:8443/crm/secure/receptor)" /&gt;

&lt;/bean&gt;  
&lt;/property&gt;  
&lt;property name="key" value="an\_id\_for\_this\_auth\_provider\_only"/&gt;  
&lt;/bean&gt;

&lt;bean id="proxyGrantingTicketStorage" class="org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl" /&gt;

&lt;bean id="serviceProperties" class="org.springframework.security.ui.cas.ServiceProperties"&gt;  
&lt;property name="service" value="[https://crm.lucene.cn:8443/crm/j\_spring\_cas\_security\_check"/](https://crm.lucene.cn:8443/crm/j_spring_cas_security_check%22/)&gt;  
&lt;property name="sendRenew" value="false"/&gt;  
&lt;/bean&gt;

&lt;bean id="daoAuthenticationProvider"  
class="org.springframework.security.providers.dao.DaoAuthenticationProvider"&gt;  
&lt;property name="userDetailsService" ref="userDetailsService" /&gt;  
&lt;property name="userCache" ref="userCache" /&gt;  
&lt;property name="passwordEncoder" ref="passwordEncoder" /&gt;  
&lt;/bean&gt;  
&lt;bean id="passwordEncoder"  
class="org.springframework.security.providers.encoding.Md5PasswordEncoder" /&gt;  
&lt;bean id="userDetailsService"  
class="org.openjweb.core.springsecurity.UserDetailsServiceImpl"&gt;  
&lt;constructor-arg&gt;  
&lt;ref bean="IBaseDao3" /&gt;  
&lt;/constructor-arg&gt;  
&lt;/bean&gt;

&lt;bean id="userCache"  
class="org.springframework.security.providers.dao.cache.EhCacheBasedUserCache"&gt;  
&lt;property name="cache" ref="userCacheBacked" /&gt;  
&lt;/bean&gt;

&lt;bean id="userCacheBacked"  
class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;  
&lt;property name="cacheManager" ref="cacheManager" /&gt;  
&lt;property name="cacheName" value="userCache" /&gt;  
&lt;/bean&gt;

&lt;bean id="cacheManager"  
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"&gt;  
&lt;property name="configLocation"  
value="classpath:ehcache-security.xml" /&gt;  
&lt;/bean&gt;  
&lt;bean id="filterSecurityInterceptor"  
class="org.springframework.security.intercept.web.FilterSecurityInterceptor"&gt;  
&lt;sec:custom-filter before="FILTER\_SECURITY\_INTERCEPTOR" /&gt;  
&lt;property name="authenticationManager"  
ref="authenticationManager" /&gt;  
&lt;property name="accessDecisionManager"  
ref="accessDecisionManager" /&gt;  
&lt;property name="alwaysReauthenticate" value="true" /&gt;  
&lt;property name="objectDefinitionSource"  
ref="databaseFilterInvocationDefinitionSource" /&gt;  
&lt;/bean&gt;  
&lt;bean id="accessDecisionManager"  
class="org.springframework.security.vote.AffirmativeBased"&gt;  
&lt;property name="decisionVoters"&gt;  
&lt;list&gt;  
&lt;bean  
class="org.springframework.security.vote.RoleVoter"&gt;  
&lt;property name="rolePrefix" value="" /&gt;  
&lt;/bean&gt;  
&lt;/list&gt;  
&lt;/property&gt;  
&lt;/bean&gt;  
&lt;bean id="databaseFilterInvocationDefinitionSource"  
class="org.springframework.security.intercept.web.DefaultFilterInvocationDefinitionSource"&gt;  
&lt;constructor-arg  
type="org.springframework.security.util.UrlMatcher"  
ref="antUrlPathMatcher" /&gt;  
&lt;constructor-arg type="java.util.LinkedHashMap" ref="requestMap" /&gt;  
&lt;/bean&gt;

&lt;bean id="antUrlPathMatcher"  
class="org.springframework.security.util.AntUrlPathMatcher" /&gt;

&lt;bean id="requestMap"  
class="org.openjweb.core.springsecurity.RequestMapFactoryBean"  
init-method="init"&gt;

&lt;/bean&gt;

&lt;/beans&gt;