CAS 取消HTTPS配置

原帖[url] http://blog.csdn.net/yys79/article/details/6456915[/url]


客户觉得cas证书的提示太烦了,想去掉,又不想花钱认证证书,这两天闲暇之时看了一下最新的cas文章,自己也配置了一套apache2.2+ Tomcat7+casserver 3.4.8+Casclient3.2的配置,实现了负载均衡下Tomcat集群中的Cas认证,并使用了https的方式和http认证都通过验证。



首先下载cas服务端和客户端,这个不说了。然后将casserver包中的.war文件复制到webapps目录下,改名为cas,这个部署也就这么回事了。及其简单,可以使用用户名密码一样的方式来登录了。

1.首先从casserver 3.4.8的压缩包里把他的war包copy出来,直接解包,修改文件夹名为cas,复制到tomcat的webapps目录,这一步非常简单,启动tomcat后就可以访问这个应用了。

2.不采用https验证,服务器端需要配置

修改第一处:

cas/WEB-INF/deployerConfigContext.xml

<bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
p:httpClient-ref="httpClient"/>



增加参数p:requireSecure="false",是否需要安全验证,即HTTPS,false为不采用。修改后为:

  <bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
p:httpClient-ref="httpClient"  p:requireSecure="false"/>



  修改第二处:

  cas/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml

<bean id="ticketGrantingTicketCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"

      p:cookieSecure="true"

      p:cookieMaxAge="-1"

      p:cookieName="CASTGC"

      p:cookiePath="/cas" />



参数p:cookieSecure="true",同理为HTTPS验证相关,TRUE为采用HTTPS验证,FALSE为不采用https验证。

参数p:cookieMaxAge="-1",简单说是COOKIE的最大生命 周期,-1为无生命周期,即只在当前打开的IE窗口有效,IE关闭或重新打开其它窗口,仍会要求验证。可以根据需要修改为大于0的数字,比如3600等, 意思是在3600秒内,打开任意IE窗口,都不需要验证。

这里把 cookieSecure修改为false就行了



3.修改客户端应用的web.xml,增加如下filter和mapping



   <filter>
   <filter-name>CAS Authentication Filter</filter-name>
   <filter-class>
    org.jasig.cas.client.authentication.AuthenticationFilter
   </filter-class>
   <init-param>
    <param-name>casServerLoginUrl</param-name>
    <param-value>
    http://localhost:8080/cas/login
    </param-value>
   </init-param>
   <init-param>
    <param-name>renew</param-name>
    <param-value>false</param-value>
   </init-param>
   <init-param>
    <param-name>gateway</param-name>
    <param-value>false</param-value>
   </init-param>
   <init-param>
    <param-name>serverName</param-name>
    <param-value>http://localhost:8080</param-value>
   </init-param>
</filter>

<filter>
   <filter-name>CAS Validation Filter</filter-name>
   <filter-class>
    org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter
   </filter-class>
   <init-param>
    <param-name>casServerUrlPrefix</param-name>
    <param-value>http://localhost:8080/cas</param-value>
   </init-param>
   <init-param>
    <param-name>serverName</param-name>
    <param-value>http://localhost:8080</param-value>
   </init-param>
   <init-param>
    <param-name>useSession</param-name>
    <param-value>true</param-value>
   </init-param>
   <init-param>
    <param-name>redirectAfterValidation</param-name>
    <param-value>true</param-value>
   </init-param>
</filter>

<filter>
   <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
   <filter-class>
    org.jasig.cas.client.util.HttpServletRequestWrapperFilter
   </filter-class>
</filter>

<filter>
   <filter-name>CAS Assertion Thread Local Filter</filter-name>
   <filter-class>
    org.jasig.cas.client.util.AssertionThreadLocalFilter
   </filter-class>
</filter>
<filter>
        <filter-name>loginFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        <init-param>
            <param-name>targetFilterLifecycle</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
<filter-mapping>
   <filter-name>CAS Authentication Filter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
   <filter-name>CAS Validation Filter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
   <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
   <filter-name>CAS Assertion Thread Local Filter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>



里面的localhost在发布环境下应修改为实际的服务器IP地址或域名。8080为端口号,如果只用tomcat,则可以这样设置,如果使用apache和80端口,那:8080 可以去掉.至于配置apache和tomcat集群,可以看我关于apache配置的文章。

在配置上单独用tomat和使用apache+tomcat也就是端口号上的区别,apache将请求转发到tomcat后,实际上就由tomcat来处理了,apache不会拦截什么的。

在cas客户端应用的web-inf/lib下,放入cas-client-core-3.2.0.jar文件,这需要去cas官方网站下载。

这样就ok了。



还有,如果想使用安全证书的话,那需要开启apache的https。需要从apache官方下载带ssl的apache,安装好以后,在httpd.conf里增加ssl配置:Include conf/extra/httpd-ssl.conf,那里面的配置我想不复杂,大家都看得懂。生成 证书 时,让你输入名字的时候,一定要输入域名,因为https信任域名,不信任ip的。这个证书也不需要在jre里配置,只需要在apache里配置,也就是那个 conf/extra/httpd-ssl.conf文件,主要就是证书证书文件名。生成的证书文件要注意,字节数千万不能是0,那表示生成失败,生成时仔细看一下就能看到是否有错误。。

猜你喜欢

转载自xuliangyong.iteye.com/blog/2210379