您的位置:首页 > 理论基础 > 计算机网络

将CAS 单点登录协议由https改为http

2011-12-04 15:37 323 查看
近期公司的一个单点登录框架移交到我手上维护,之前采用的是https,服务器的配置比较麻烦,就想换成http来访问,这样服务器端的配置和维护就简单多啦!

CAS Server: cas-server-core-3.3.2.jar cas-client-core-3.1.3.jar

CAS Client: casclient-2.1.0.jar

下面是我的改进的步骤:

1.首先是需要在CAS服务器配置是CAS服务器端支持http协议方式

主要改进一下配置文件:

ticketGrantingTicketCookieGenerator.xml 配置文件:

<bean id="ticketGrantingTicketCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="true"
p:cookieMaxAge="-1"
p:cookieName="CASTGC"
p:cookiePath="/cas" />


将这个地方的配置改为下面的配置:
<bean id="ticketGrantingTicketCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="false"
p:cookieMaxAge="-1"
p:cookieName="CASTGC"
p:cookiePath="/cas" />


warnCookieGenerator.xml 配置文件

<bean id="warnCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="true"
p:cookieMaxAge="-1"
p:cookieName="CASPRIVACY"
p:cookiePath="/cas" />


将这个地方的配置改为下面的配置:

<bean id="warnCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="false"
p:cookieMaxAge="-1"
p:cookieName="CASPRIVACY"
p:cookiePath="/cas" />


deployerConfigContext.xml 配置文件:

<bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
p:httpClient-ref="httpClient"
/>
将这个地方的配置文件修改为下面的配置:

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


完成这些地方的修改后,服务器端就支持了http协议的访问了 下面开始客户端的改动

看过CAS客户端的源码的都知道,在配置过滤器类中,都做了访问协议的判断 如下代码:

if (casServiceUrl != null){
if (! (casServiceUrl.startsWith("https://")|| (casServiceUrl.startsWith("http://") ))){
throw new ServletException("service URL must start with http:// or https://; its current value is [" + casServiceUrl + "]");
}
}


所以首先我们要做的 是需要将casclient.jar的源码找到,将上面类似的这种协议判断屏蔽掉。具体在一下2个类里面:

第一个是:CASFilter这个类里面中的init()方法中,https的判断屏蔽后如下:

   if (casGateway && Boolean.valueOf(casRenew).booleanValue()) {
throw new ServletException("gateway and renew cannot both be true in filter configuration");
}
if (casServerName != null && casServiceUrl != null) {
throw new ServletException("serverName and serviceUrl cannot both be set: choose one.");
}
if (casServerName == null && casServiceUrl == null) {
throw new ServletException("one of serverName or serviceUrl must be set.");
}
/* if (casServiceUrl != null){ if (! (casServiceUrl.startsWith("https://")|| (casServiceUrl.startsWith("http://") ))){ throw new ServletException("service URL must start with http:// or https://; its current value is [" + casServiceUrl + "]"); } }*/

if (casValidate == null){
throw new ServletException("validateUrl parameter must be set.");
}
/* if (! casValidate.startsWith("https://")){
throw new ServletException("validateUrl must start with https://, its current value is [" + casValidate + "]");
}
*/
if (casAuthorizedProxy != null){

// parse and remember authorized proxies
StringTokenizer casProxies =
new StringTokenizer(casAuthorizedProxy);
while (casProxies.hasMoreTokens()) {
String anAuthorizedProxy = casProxies.nextToken();
/* if (!anAuthorizedProxy.startsWith("https://")){
throw new ServletException("CASFilter initialization parameter for authorized proxies " +
"must be a whitespace delimited list of authorized proxies. " +
"Authorized proxies must be secure (https) addresses. This one wasn't: [" + anAuthorizedProxy + "]");
}*/
this.authorizedProxies.add(anAuthorizedProxy);
}
}


第二个是:edu.yale.its.tp.cas.util.SecureURL这个类里面的retrieve方法中,屏蔽后如下:

URL u = new URL(url);
/*if (!u.getProtocol().equals("https")){
// IOException may not be the best exception we could throw here
// since the problem is with the URL argument we were passed, not
// IO. -awp9
log.error("retrieve(" + url + ") on an illegal URL since protocol was not https.");
throw new IOException("only 'https' URLs are valid for this method");
}*/

URLConnection uc = u.openConnection();
重新打包后将casclient.jar更新到我们的程序第三方lib包中。

剩下的就是修改我们程序的web.xml中关于cas的配置,把https的配置全部修改为http,记得端口号改为你CAS服务器的访问端口号,而不再是https的访问端口号。

另外要说明的是:在网上看到有鞋童说 退出时还是必须使用https,于是我就在我本地尝试了下,我退出时并没有使用https,退出没有问题。如果退出仍然需要使用https,那么我们把访问改成http,就没有任何意义了,服务器仍然需要进行https的配置。

下面提供我修改好的casclient.jar的文件,只是把https的协议判断屏蔽了,没有做其他的修改。如果需要源码的,可以在网上找找,或者直接问我要都可以。以上有不正确的,还望斧正。

casclient-2.1.0.jar
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: