在配置CAS做单点登录服务的时候,经常会遇到因证书的问题影响服务的配置,于是就萌生了去除CAS客户端的SSL安全验证功能的想法。最近研究了一下casclient的代码,发现做这个手术相当简单,而且在安全的网络环境下,没有SSL的客户端验证也还是比较安全的,另外,客户端省去了安全证书配置的麻烦,使配置部署过程相对简单了许多。
下面就直接说说我们的改动吧。
根据casclient中edu.yale.its.tp.cas.util.SecureURL类的retrieve(String url)方法,我们把其中安全验证部分的代码删除,可以创建一个新的简单处理方法:
/**
* Retrieve the contents from the given URL as a String, assuming the
* URL's server matches what we expect it to match.
*/
public static String retrieve(String url) throws IOException {
BufferedReader r = null;
try {
URL u = new URL(url);
URLConnection uc = u.openConnection();
uc.setRequestProperty("Connection", "close");
r = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String line;
StringBuffer buf = new StringBuffer();
while ((line = r.readLine()) != null)
buf.append(line + "n");
return buf.toString();
} finally {
try {
if (r != null)
r.close();
} catch (IOException ex) {
// ignore
}
}
}
这样,我们仅使用http标准协议的URL就可以了。另外,我们修改一下edu.yale.its.tp.cas.client.ServiceTicketValidator类里的validate方法,将其中进行HTTPS验证的代码块:
response = SecureURL.retrieve(url);
修改如下:
URL u = new URL(url);
String response;
if (u.getProtocol().equals("https")){
response = SecureURL.retrieve(url);
}else{
response = HttpURL.retrieve(url);
}
这样修改之后,我们只要灵活配置一下filter,就可以进行双向选择了,即可以使用HTTP,也可以使用HTTPS,不会对原来的应用有影响。
[@more@]来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8700374/viewspace-1005580/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8700374/viewspace-1005580/