前言
继上一篇博文:可跨域的单点登录(SSO)实现方案【附.net代码】虽然实现了单点登录,也存在很多不合理的地方。很多热心的朋友也给出了很多指导性的意见,特别是 LoveCoder提出的意见。
在很多亲自操刀过单点登录的朋友看来,单点登录很简单啊,不过如此。但是还有很多如我一样刚刚接触过或者没有接触过单点登录的朋友却不清楚单点登录具体该怎么做。虽然网上单点登录的教程很多很多,大都是实现思路、实现原理,真正涉及到代码级别的实现细节却很少。
单点登录产生的原因是为了解决多个子系统共享登录状态的问题,每个人的思想或者能力不同,实现方式可能都不尽相同。好比过河,各有各的招,有的人坐船过去,还有人拽着绳蹚水过去的,安全吗?坐船船会漏,拽绳绳会断,怎么办?每个人身上再绑个救生圈,这样安全了吗?不见得。针对某个问题域我们每个人都想给出一个完美的解决方案,而现实往往是因为个人能力或者公司业务情况所限而做不到完美。我们只能做到首先要保证能解决存在的问题,然后针对使用情况做各种优化,好的系统是用出来的而不是设计出来的。
在这一篇博文中,主要优化的地方是:将轮询跳转写cookie到各个分站改为使用ajax分发写cookie到各个分站。
如有不正欢迎指教
改进方案
是在上一篇博文:可跨域的单点登录(SSO)实现方案【附.net代码】的基础上进行的改进,如有疑惑请先查看上篇博文。
改进后的单点登录交互效果如下:
具体代码如下:
1.sso.com登录验证方法不再重定向,而是输出一段js代码进行ajax分发
后台代码如下:
对应的试图页面如下:
2.各个分站jump方法的改变如下:
3.a.com和b.com中需要登录的action验证方式的优化:
总结
解决问题:
1.不需要各个分站之间来回跳转写cookie,而是在sso.com以ajax分发的形式向各个分站写cookie
2.代码更加干净
未解决问题:
1.按需写cookie
2.安全性验证
3.不支持ajax登录