- 浏览: 86723 次
- 性别:
- 来自: 天津
文章分类
- 全部博客 (110)
- java (110)
- Comparing PHP Frameworks ( Symfony (1)
- CakePHP (1)
- YII and CodeIgniter) (1)
- spring定时任务的实现 (1)
- 获得一个节点对象的节点类型 (1)
- SWT 文本框Text通过GC重绘改变边框颜色 (1)
- 常用命令收集(系统设置) (1)
- openlayers 应用Google图层你必须做的 (1)
- Shell Sort in Java (1)
- Java网络编程 (1)
- 删除more里面的Edit (1)
- Android颜色选择器 (1)
- Linux安全配置步骤简述 (1)
- 职场官话 (1)
- TOMCAT常用优化 (1)
- 2008 ==> 2009 (1)
- 01_Android介绍 (1)
- HTML特殊字符 (1)
- 终于完成一个最重要的任务——找工作 (1)
- java 加密算法 base64 (1)
- 《南方周末》《南方日报》《新京报》《南方体育》等报纸在线阅读 (1)
- 由ORM框架设计看到微软与苹果的最大差别 (1)
- 通过发微博控制电脑的程序源码 (1)
- flex入门 (1)
- JS合并单元格、JavaScript单元格合并 (1)
- 各种常用编译开关位置 (1)
- 单一入口应用程序概述 (1)
- [转]Cocoa中回调delegate的方法时判断delegate是否已经被释放 (1)
- java简单的通用ajax分页方法 (1)
- /dev/shm放/tmp (1)
- Java中HashMap排序和遍历 . (1)
- Chrome+SwitchySharp+myentunnel+SSH (1)
- LINUX-网卡Bond (1)
最新评论
-
ken890202:
java简单的通用ajax分页方法 -
hanmiao:
真够乱的,什么都看不清。
Linux安全配置步骤简述 -
houxinyou:
说一下我自己的想法.苹果只是做一款相同的东西,然后是完善.有什 ...
由ORM框架设计看到微软与苹果的最大差别 -
delphixp:
微软技术方案很多?。。。。Java 系统笑而不语。。。
由ORM框架设计看到微软与苹果的最大差别 -
huchiwei:
同意楼上说法。这代码....怎么看!!
web应用dao层的开发经验小结
<span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">王昱[/size]<span lang="en-us"><span style="font-family: times new roman;"> yuwang881@gmail.com<span style=""> </span></span></span><span style="">博客地址</span><span lang="en-us"><span style="font-family: times new roman;">http://yuwang881.blog.sohu.com </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">关键字:[/size]<span lang="en-us"><span style="font-family: times new roman;">sso, java, j2ee, jaas</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">单点登录([/size]<span lang="en-us"><span style="font-family: times new roman;">single sign on</span></span><span style="">),简称为</span><span lang="en-us"><span style="font-family: times new roman;"> sso</span></span><span style="">,是目前比较流行的企业业务整合的解决方案之一。</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的定义是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]随着企业的发展,业务系统的数量在不断的增加,老的系统却不能轻易的替换,这会带来很多的开销。其一是管理上的开销,需要维护的系统越来越多。很多系统的数据是相互冗余和重复的,数据的不一致性会给管理工作带来很大的压力。业务和业务之间的相关性也越来越大,例如公司的计费系统和财务系统,财务系统和人事系统之间都不可避免的有着密切的关系。[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]通常来说,每个单独的系统都会有自己的安全体系和身份认证系统。整合以前,进入每个系统都需要进行登录,这样的局面不仅给管理上带来了很大的困难,在安全方面也埋下了重大的隐患。下面是一些著名的调查公司显示的统计数据:[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•频繁的[/size]<span lang="en-us"><span style="font-family: times new roman;"> it </span></span><span style="">用户平均有</span><span lang="en-us"><span style="font-family: times new roman;"> 21 </span></span><span style="">个密码</span><span lang="en-us"><span style="font-family: times new roman;"> - </span></span><span style="">资料来源:</span><span lang="en-us"><span style="font-family: times new roman;"> nta monitor password survey</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•每[/size]<span lang="en-us"><span style="font-family: times new roman;"> 79 </span></span><span style="">秒出现一起身份被窃事件</span><span lang="en-us"><span style="font-family: times new roman;"> - </span></span><span style="">资料来源:</span><span lang="en-us"><span style="font-family: times new roman;">national small business travelassoc</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•到[/size]<span lang="en-us"><span style="font-family: times new roman;"> 2007 </span></span><span style="">年,身份管理市场将成倍增长至</span><span lang="en-us"><span style="font-family: times new roman;">$4.5b - </span></span><span style="">资料来源:</span><span lang="en-us"><span style="font-family: times new roman;">ids </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">•提高</span><span lang="en-us"><span style="font-family: times new roman;"> it </span></span><span style="">效率:对于每</span><span lang="en-us"><span style="font-family: times new roman;"> 1000 </span></span><span style="">个受管用户,每用户可节省</span><span lang="en-us"><span style="font-family: times new roman;">$70k</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•生产力提高:每个新员工可节省[/size]<span lang="en-us"><span style="font-family: times new roman;"> $1k</span></span><span style="">,每个老员工可节省</span><span lang="en-us"><span style="font-family: times new roman;"> $350</span></span><span lang="en-us" style="font-family: tahoma;">�</span><span style="">资料来源:</span><span lang="en-us"><span style="font-family: times new roman;">giga</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">另外,使用“单点登录”还是[/size]<span lang="en-us"><span style="font-family: times new roman;">soa</span></span><span style="">时代的需求之一。在面向服务的架构中,服务和服务之间,程序和程序之间的通讯大量存在,服务之间的安全认证是</span><span lang="en-us"><span style="font-family: times new roman;">soa</span></span><span style="">应用的难点之一,应此建立“单点登录”的系统体系能够大大简化</span><span lang="en-us"><span style="font-family: times new roman;">soa</span></span><span style="">的安全问题,提高服务之间的合作效率。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">随着[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">技术的流行,</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的产品也是满天飞扬。所有著名的软件厂商都提供了相应的解决方案。在这里我并不想介绍自己公司(</span><span lang="en-us"><span style="font-family: times new roman;">sun microsystems</span></span><span style="">)的产品,而是对</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">技术本身进行解析,并且提供自己开发这一类产品的方法和简单演示。有关我写这篇文章的目的,请参考我的博客(</span><span lang="en-us"><span style="font-family: times new roman;">http://yuwang881.blog.sohu.com/3184816.html</span></span><span style="">)。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">单点登录的机制也一样,如下图所示,当用户第一次访问应用系统[/size]<span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">的时候,因为还没有登录,会被引导到认证系统中进行登录(</span><span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">);根据用户提供的登录信息,认证系统进行身份效验,如果通过效验,应该返回给用户一个认证的凭据--</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">(</span><span lang="en-us"><span style="font-family: times new roman;">2</span></span><span style="">);用户再访问别的应用的时候(</span><span lang="en-us"><span style="font-family: times new roman;">3</span></span><span style="">,</span><span lang="en-us"><span style="font-family: times new roman;">5</span></span><span style="">)就会将这个</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">带上,作为自己认证的凭据,应用系统接受到请求之后会把</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">送到认证系统进行效验,检查</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">的合法性(</span><span lang="en-us"><span style="font-family: times new roman;">4</span></span><span style="">,</span><span lang="en-us"><span style="font-family: times new roman;">6</span></span><span style="">)。如果通过效验,用户就可以在不用再次登录的情况下访问应用系统</span><span lang="en-us"><span style="font-family: times new roman;">2</span></span><span style="">和应用系统</span><span lang="en-us"><span style="font-family: times new roman;">3</span></span><span style="">了。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us" style="color: black; font-family: verdana;">[size=small;] [/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">从上面的视图可以看出,要实现[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">,需要以下主要的功能:</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">统一的认证系统是[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的前提之一。认证系统的主要功能是将用户的登录信息和用户信息库相比较,对用户进行登录认证;认证成功后,认证系统应该生成统一的认证标志(</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">),返还给用户。另外,认证系统还应该对</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">进行效验,判断其有效性。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">要实现[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的功能,让用户只登录一次,就必须让应用系统能够识别已经登录过的用户。应用系统应该能对</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">进行识别和提取,通过与认证系统的通讯,能自动判断当前用户是否登录过,从而完成单点登录的功能。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">•单一的用户信息数据库并不是必须的,有许多系统不能将所有的用户信息都集中存储,应该允许用户信息放置在不同的存储中,如下图所示。事实上,只要统一认证系统,统一</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">的产生和效验,无论用户信息存储在什么地方,都能实现单点登录。</span><span lang="en-us"><span style="font-family: times new roman;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">•统一的认证系统并不是说只有单个的认证服务器,如下图所示,整个系统可以存在两个以上的认证服务器,这些服务器甚至可以是不同的产品。认证服务器之间要通过标准的通讯协议,互相交换认证信息,就能完成更高级别的单点登录。如下图,当用户在访问应用系统</span><span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">时,由第一个认证服务器进行认证后,得到由此服务器产生的</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">。当他访问应用系统</span><span lang="en-us"><span style="font-family: times new roman;">4</span></span><span style="">的时候,认证服务器</span><span lang="en-us"><span style="font-family: times new roman;">2</span></span><span style="">能够识别此</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">是由第一个服务器产生的,通过认证服务器之间标准的通讯协议(例如</span><span lang="en-us"><span style="font-family: times new roman;">saml</span></span><span style="">)来交换认证信息,仍然能够完成</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的功能。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span lang="en-us" style="color: black; line-height: 150%; font-family: verdana;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">3 web-sso[/size]</span><span style="">的实现</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">为什么说[/size]<span lang="en-us"><span style="font-family: times new roman;">web-sso</span></span><span style="">比较容易实现呢?这是有</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用自身的特点决定的。</span><span lang="en-us"><span style="font-family: times new roman;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">但是我们通常的应用是有状态的。先不用提不同应用之间的[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">,在同一个应用中也需要保存用户的登录身份信息。例如用户在访问页面</span><span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">的时候进行了登录,但是刚才也提到,客户端的每个请求都是单独的连接,当客户再次访问页面</span><span lang="en-us"><span style="font-family: times new roman;">2</span></span><span style="">的时候,如何才能告诉</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器,客户刚才已经登录过了呢?浏览器和服务器之间有约定:通过使用</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">技术来维护应用的状态。</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">是可以被</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器设置的字符串,并且可以保存在浏览器中。如下图所示,当浏览器访问了页面</span><span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">时,</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器设置了一个</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">,并将这个</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">和页面</span><span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">一起返回给浏览器,浏览器接到</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">之后,就会保存起来,在它访问页面</span><span lang="en-us"><span style="font-family: times new roman;">2</span></span><span style="">的时候会把这个</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">也带上,</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器接到请求时也能读出</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的值,根据</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">值的内容就可以判断和恢复一些用户的信息状态。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">web-sso[/size]</span><span style="">完全可以利用</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">结束来完成用户登录信息的保存,将浏览器中的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">和上文中的</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">结合起来,完成</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的功能。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;"><span style=""> [/size]1.</span></span><span style="">统一的身份认证服务。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">3.1 web sso [/size]</span><span style="">的样例</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]样例下载、安装部署和运行指南:[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•这三个[/size]<span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用完全可以单独部署,它们可以分别部署在不同的机器,不同的操作系统和不同的</span><span lang="en-us"><span style="font-family: times new roman;">j2ee</span></span><span style="">的产品上,它们完全是标准的和平台无关的应用。但是有一个限制,那两台部署应用(</span><span lang="en-us"><span style="font-family: times new roman;">demo1</span></span><span style="">、</span><span lang="en-us"><span style="font-family: times new roman;">demo2</span></span><span style="">)的机器的域名需要相同,这在后面的章节中会解释到</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">domain</span></span><span style="">的关系以及如何制作跨域的</span><span lang="en-us"><span style="font-family: times new roman;">web-sso</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•解压缩[/size]<span lang="en-us"><span style="font-family: times new roman;">ssowebdemo1</span></span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">ssowebdemo2</span></span><span style="">文件,分别在它们</span><span lang="en-us"><span style="font-family: times new roman;">/web-inf/</span></span><span style="">下找到</span><span lang="en-us"><span style="font-family: times new roman;">web.xml</span></span><span style="">文件,请修改其中的几个初始化参数</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"><param-name>ssoserviceurl</param-name></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"></init-param></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"><param-name>ssologinpage</param-name></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"></init-param></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•请输入第一个[/size]<span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用的测试</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">(</span><span lang="en-us"><span style="font-family: times new roman;">test.jsp</span></span><span style="">)</span><span lang="en-us"><span style="font-family: times new roman;">,</span></span><span style="">例如</span><span lang="en-us"><span style="font-family: times new roman;">http://wangyu.prc.sun.com:8080/ ssowebdemo1/test.jsp</span></span><span style="">,如果是第一次访问,便会自动跳转到登录界面,如下图</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us" style="color: black; font-family: verdana;">[size=small;] [/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span lang="en-us" style="color: black; font-family: verdana;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span lang="en-us" style="color: black; line-height: 150%; font-family: verdana;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">3.2.1[/size]</span><span style="">身份认证服务代码解析</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">ssoauth[/size]</span><span style="">的代码如下面的列表显示,结构非常简单,先看看这个</span><span lang="en-us"><span style="font-family: times new roman;">servlet</span></span><span style="">的主体部分:</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import java.io.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">importjava.text.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">importjava.util.concurrent.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">importjavax.servlet.http.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]static private concurrentmap accounts;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]stringcookiename="wangyudesktopssoid";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]public void init(servletconfig config)throws servletexception {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]domainname=config.getinitparameter("domainname");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]ssoids = new concurrenthashmap();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]accounts.put("wangyu","wangyu");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]accounts.put("carol","carol");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]protected voidprocessrequest(httpservletrequest request, httpservletresponse response) throwsservletexception, ioexception {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string action =request.getparameter("action");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">} </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">在主要的请求处理方法[/size]<span lang="en-us"><span style="font-family: times new roman;">processrequest()</span></span><span style="">中,可以很清楚的看到</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">的所有功能</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">2.[/size]</span><span style="">如果用户已经登录过本系统,再访问别的应用的时候,是不需要再次登录的。因为浏览器会将第一次登录时产生的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">和请求一起发送。效验</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的有效性是</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">的主要功能之一。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">4.ssoauth[/size]</span><span style="">还提供</span><span lang="en-us"><span style="font-family: times new roman;">logout</span></span><span style="">服务。</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private void handlerfromlogin(httpservletrequest request,httpservletresponse response) throws servletexception, ioexception {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string username = request.getparameter("username");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string password = request.getparameter("password");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string pass = (string)accounts.get(username);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]if ((pass==null)||(!pass.equals(password))) </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]getservletcontext().getrequestdispatcher("/failed.html").forward(request,response);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]else {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string gotourl = request.getparameter("goto");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string newid = createuid();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]ssoids.put(newid, username);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]cookie wangyu = new cookie(cookiename, newid);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]wangyu.setdomain(domainname);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]wangyu.setmaxage(60000);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]wangyu.setvalue(newid);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]wangyu.setpath("/");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]response.addcookie(wangyu);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]system.out.println("login success, goto back url:" + gotourl);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]if (gotourl != null) {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]printwriter out =response.getwriter();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]response.sendredirect(gotourl);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]out.close();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us">[size=small;]<span style="font-family: times new roman;"><span style=""> [/size]}<span style=""> </span></span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">登录成功后,浏览器会到哪个页面呢?那我们回顾一下我们是如何使用身份认证服务的。一般来说我们不会直接访问身份服务的任何[/size]<span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">,包括</span><span lang="en-us"><span style="font-family: times new roman;">login.jsp</span></span><span style="">。身份服务是用来保护其他应用服务的,用户一般在访问一个受</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">保护的</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用的某个</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">时,当前这个应用会发现当前的用户还没有登录,便强制将也页面转向</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">login.jsp</span></span><span style="">,让用户登录。如果登录成功后,应该自动的将用户的浏览器指向用户最初想访问的那个</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">。在</span><span lang="en-us"><span style="font-family: times new roman;">handlerfromlogin()</span></span><span style="">这个方法中,我们通过接收“</span><span lang="en-us"><span style="font-family: times new roman;">goto</span></span><span style="">”这个参数来保存用户最初访问的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">,成功后便重新定向到这个页面中。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]其他的方法更加简单,这里就不多解释了。[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">要实现[/size]<span lang="en-us"><span style="font-family: times new roman;">web-sso</span></span><span style="">的功能,只有身份认证服务是不够的。这点很显然,要想使多个应用具有单点登录的功能,还需要每个应用本身的配合:将自己的身份认证的服务交给一个统一的身份认证服务-</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">。</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">服务中提供的各个方法就是供每个加入</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用来调用的。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">•</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用中每一个需要安全保护的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">在访问以前,都需要进行安全检查,如果发现没有登录(没有发现认证之后所带的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">),就重新定向到</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">中的</span><span lang="en-us"><span style="font-family: times new roman;">login.jsp</span></span><span style="">进行登录。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•当你再访问这个应用的需要保护的[/size]<span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">的时候,系统还是要进行安全检查的,但是这次系统能够发现相应的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•如果[/size]<span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">效验成功,就允许用户访问当前请求的资源。</span><span lang="en-us"><span style="font-family: times new roman;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]以上这些功能,可以用很多方法来实现:[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•可以通过一个[/size]<span lang="en-us"><span style="font-family: times new roman;">controller</span></span><span style="">,将所有的功能都写到一个</span><span lang="en-us"><span style="font-family: times new roman;">servlet</span></span><span style="">中,然后在</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">映射的时候,映射到所有需要保护的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">集合中(例如</span><span lang="en-us"><span style="font-family: times new roman;">*.jsp</span></span><span style="">,</span><span lang="en-us"><span style="font-family: times new roman;">/security/*</span></span><span style="">等)。这个方法可以使用,不过,它的缺点是不能重用。在每个应用中都要部署一个相同的</span><span lang="en-us"><span style="font-family: times new roman;">servlet</span></span><span style="">。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">package sso;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import java.io.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import java.net.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import java.util.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import java.text.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import javax.servlet.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import javax.servlet.http.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import javax.servlet.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import org.apache.commons.httpclient.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">importorg.apache.commons.httpclient.methods.getmethod;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">public class ssofilter implements filter {</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private filterconfig filterconfig = null;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private string cookiename="wangyudesktopssoid";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private string ssoserviceurl="http://wangyu.prc.sun.com:8080/ssoauth/ssoauth";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private string ssologinpage="http://wangyu.prc.sun.com:8080/ssoauth/login.jsp";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]public void init(filterconfig filterconfig) {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]this.filterconfig = filterconfig;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]if (filterconfig != null) {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]if (debug) {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]log("ssofilter:initializingfilter");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us">[size=small;]<span style="font-family: times new roman;"><span style=""> [/size]}<span style=""> </span></span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]cookiename = filterconfig.getinitparameter("cookiename");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]ssoserviceurl =filterconfig.getinitparameter("ssoserviceurl");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]ssologinpage = filterconfig.getinitparameter("ssologinpage");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">以上的初始化的源代码有两点需要说明:一是有两个需要配置的参数[/size]<span lang="en-us"><span style="font-family: times new roman;">ssoserviceurl</span></span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">ssologinpage</span></span><span style="">。因为当前的</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用很可能和身份认证服务(</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">)不在同一台机器上,所以需要让这个</span><span lang="en-us"><span style="font-family: times new roman;">filter</span></span><span style="">知道身份认证服务部署的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">,这样才能去调用它的服务。另外一点就是由于身份认证的服务调用是要通过</span><span lang="en-us"><span style="font-family: times new roman;">http</span></span><span style="">协议来调用的(在本样例中是这样设计的,读者完全可以设计自己的身份服务,使用别的调用协议,如</span><span lang="en-us"><span style="font-family: times new roman;">rmi</span></span><span style="">或</span><span lang="en-us"><span style="font-family: times new roman;">soap</span></span><span style="">等等),所有笔者引用了</span><span lang="en-us"><span style="font-family: times new roman;">apache</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">commons</span></span><span style="">工具包(详细信息情访问</span><span lang="en-us"><span style="font-family: times new roman;">apache </span></span><span style="">的网站</span><span lang="en-us"><span style="font-family: times new roman;">http://jakarta.apache.org/commons/index.html</span></span><span style="">),其中的“</span><span lang="en-us"><span style="font-family: times new roman;">httpclient</span></span><span style="">”可以大大简化</span><span lang="en-us"><span style="font-family: times new roman;">http</span></span><span style="">调用的编程。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">dofilter()[/size]</span><span style="">方法的逻辑也是非常简单的,在接收到请求的时候,先去查找是否存在期望的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">值,如果找到了,就会调用</span><span lang="en-us"><span style="font-family: times new roman;">ssoservice(cookievalue)</span></span><span style="">去效验这个</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的有效性。如果</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">效验不成功或者</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">根本不存在,就会直接转到登录界面让用户登录;如果</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">效验成功,就不会做任何阻拦,让此请求进行下去。在配置文件中,有下面的一个节点表示了此</span><span lang="en-us"><span style="font-family: times new roman;">filter</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">映射关系:只拦截所有的</span><span lang="en-us"><span style="font-family: times new roman;">jsp</span></span><span style="">请求。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"><filter-name>ssofilter</filter-name></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"></filter-mapping></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private string ssoservice(string cookievalue) throws ioexception {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string authaction = "?action=authcookie&cookiename=";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpclient httpclient = new httpclient();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]getmethod httpget = new getmethod(ssoserviceurl+authaction+cookievalue);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]try { </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpclient.executemethod(httpget);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string result = httpget.getresponsebodyasstring();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]return result;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]} finally {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpget.releaseconnection();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private void logoutservice(string cookievalue) throws ioexception {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string authaction = "?action=logout&cookiename=";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpclient httpclient = new httpclient();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]getmethod httpget = new getmethod(ssoserviceurl+authaction+cookievalue);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]try {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpclient.executemethod(httpget);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpget.getresponsebodyasstring();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]} finally {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpget.releaseconnection();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">其他的函数都很简单,有很多都是我的[/size]<span lang="en-us"><span style="font-family: times new roman;">ide</span></span><span style="">(</span><span lang="en-us"><span style="font-family: times new roman;">netbeans</span></span><span style="">)替我自动生成的。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">当前这个[/size]<span lang="en-us"><span style="font-family: times new roman;">web-sso</span></span><span style="">的方案是一个比较简单的雏形,主要是用来演示</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的概念和说明</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">技术的实现方式。有很多方面还需要完善,其中安全性是非常重要的一个方面。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">•</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的长度和复杂度</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•[/size]<span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的效验和保护</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]•当其中一个应用的安全性不好,其他所有的应用都会受到安全威胁[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">这些安全漏洞在商业的[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">解决方案中都会有所考虑,提供相关的安全措施和保护手段,例如</span><span lang="en-us"><span style="font-family: times new roman;">sun</span></span><span style="">公司的</span><span lang="en-us"><span style="font-family: times new roman;">accessmanager</span></span><span style="">,</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的复杂读和对</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的保护都做得非常好。另外在</span><span lang="en-us"><span style="font-family: times new roman;">opnesso </span></span><span style="">(</span><span lang="en-us"><span style="font-family: times new roman;">https://opensso.dev.java.net/</span></span><span style="">)的架构指南中也给出了部分安全措施的解决方案。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]除了安全性,当前方案在功能和性能上都需要很多的改进:[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•我们编写的[/size]<span lang="en-us"><span style="font-family: times new roman;">filter</span></span><span style="">只能用于</span><span lang="en-us"><span style="font-family: times new roman;">j2ee</span></span><span style="">的应用,而对于大量非</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用,却无法提供</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">服务。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•当前的方案不能支持分别位于不同[/size]<span lang="en-us"><span style="font-family: times new roman;">domain</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用进行</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">。这是因为浏览器在访问</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器的时候,仅仅会带上和当前</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器具有相同</span><span lang="en-us"><span style="font-family: times new roman;">domain</span></span><span style="">名称的那些</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">。要提供跨域的</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的解决方案有很多其他的方法,在这里就不多说了。</span><span lang="en-us"><span style="font-family: times new roman;">sun</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">access manager</span></span><span style="">就具有跨域的</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的功能。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•另外系统还需要很多其他的服务,如在内存中定时删除无用的[/size]<span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">映射等等,都是一个严肃的解决方案需要考虑的问题。</span><span lang="en-us"><span style="font-family: times new roman;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">从[/size]<span lang="en-us"><span style="font-family: times new roman;">web-sso</span></span><span style="">的概念延伸开,我们可以把</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的技术拓展到整个桌面的应用,不仅仅局限在浏览器。</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的概念和原则都没有改变,只需要再做一点点的工作,就可以完成桌面</span><span lang="en-us"><span style="font-family: times new roman;"> sso </span></span><span style="">的应用。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">从网站可以下载一个简单的桌面[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的样例</span><span lang="en-us"><span style="font-family: times new roman;">(http://gceclub.sun.com.cn/wangyu/</span></span><span style="">和全部源码(</span><span lang="en-us"><span style="font-family: times new roman;">http://gceclub.sun.com.cn/wangyu/desktop-sso/desktopsso_src.zip</span></span><span style="">),虽然简单,但是它具有桌面</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">大多数的功能,稍微加以扩充就可以成为自己的解决方案。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;"><span style=""> [/size]1.</span></span><span style="">运行此桌面</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">需要三个前提条件:</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">b) [/size]</span><span style="">当前桌面需要运行</span><span lang="en-us"><span style="font-family: times new roman;">mozilla</span></span><span style="">或</span><span lang="en-us"><span style="font-family: times new roman;">netscape</span></span><span style="">浏览器,因为我们将</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">保存到</span><span lang="en-us"><span style="font-family: times new roman;">mozilla</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">文件中</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">2.[/size]</span><span style="">解开</span><span lang="en-us"><span style="font-family: times new roman;">desktopsso.zip</span></span><span style="">文件,里面有两个目录</span><span lang="en-us"><span style="font-family: times new roman;">bin</span></span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">lib</span></span><span style="">。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">a)ssoserviceurl[/size]</span><span style="">要指向</span><span lang="en-us"><span style="font-family: times new roman;">websso</span></span><span style="">部署的身份认证的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">c)cookiefilepath[/size]</span><span style="">要指向当前用户的</span><span lang="en-us"><span style="font-family: times new roman;">mozilla</span></span><span style="">所存放</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的文件</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">5.[/size]</span><span style="">在</span><span lang="en-us"><span style="font-family: times new roman;">bin</span></span><span style="">下的运行脚本可能需要作相应的修改</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">b) java [/size]</span><span style="">运行程序需要放置在当前运行的路径下,否则需要加上</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">的路径全名。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">样例程序包含三个简单的[/size]<span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">控制台程序,这三个程序单独运行都需要登录。如果运行第一个命叫“</span><span lang="en-us"><span style="font-family: times new roman;">gamesystem</span></span><span style="">”的程序,提示需要输入用户名和密码:</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us" style="color: black; font-family: verdana;">[size=small;] [/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]效验成功以后,便会显示当前登录的用户的基本信息等等。[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us" style="color: black; font-family: verdana;">[size=small;] [/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">这时候再运行第二个桌面</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">应用(</span><span lang="en-us"><span style="font-family: times new roman;">mailsystem</span></span><span style="">)的时候,就不需要再登录了,直接就显示出来刚才登录的用户。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">第三个应用是[/size]<span lang="en-us"><span style="font-family: times new roman;">logout</span></span><span style="">,运行它之后,用户便退出系统。再访问的时候,又需要重新登录了。请读者再制裁执行完</span><span lang="en-us"><span style="font-family: times new roman;">logout</span></span><span style="">之后,重新验证一下前两个应用的</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">:先运行第二个应用,再运行第一个,会看到相同的效果。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">这时候再打开[/size]<span lang="en-us"><span style="font-family: times new roman;">mozilla</span></span><span style="">浏览器,访问以前提到的那两个</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用,会发现只要桌面应用如果登录过,</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用就不用再登录了,而且能显示刚才登录的用户的信息。读者可以在几个桌面和</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用之间进行登录和</span><span lang="en-us"><span style="font-family: times new roman;">logout</span></span><span style="">的试验,看看它们之间的</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">6.3[/size]</span><span style="">桌面样例的源码分析</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]desktopsso {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]desktopsso.share.passwordloginmodule required;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]desktopsso.share.desktopssologinmodule required;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">}; </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;">[size=small;]<span style="">在[/size]<span lang="en-us"><span style="font-family: times new roman;">config.properties</span></span><span style="">的文件中,我们配置了它们的值:</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">ssoserviceurl=http://wangyu.prc.sun.com:8080/ssoauth/ssoauth</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">ssologinpage=http://wangyu.prc.sun.com:8080/ssoauth/login.jsp</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">cookiefilepath=c:\\documents andsettings\\yw137672\\applicationdata\\mozilla\\profiles\\default\\hog6z1ji.slt\\cookies.txt </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;">[size=small;]<span style="">下面是[/size]<span lang="en-us"><span style="font-family: times new roman;">cookielogin()</span></span><span style="">方法的实体,它的逻辑是:先从</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">文件中获得相应的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">值,通过身份效验服务效验</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的有效性。如果</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">有效就算登录成功;如果不成功或</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">不存在,用</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">登录就算失败。</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">用用户名和密码登录的方法要复杂一些,通过[/size]<span lang="en-us"><span style="font-family: times new roman;">callback</span></span><span style="">的机制和屏幕输入输出进行信息交互,完成用户登录信息的获取;获取信息以后通过</span><span lang="en-us"><span style="font-family: times new roman;">userauth</span></span><span style="">方法来调用远端</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">的服务来判定当前登录的有效性。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">cookieauth[/size]</span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">userauth</span></span><span style="">方法都是利用</span><span lang="en-us"><span style="font-family: times new roman;">apahce</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">httpclient</span></span><span style="">工具包和远程的</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">进行</span><span lang="en-us"><span style="font-family: times new roman;">http</span></span><span style="">连接,获取服务。</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">private string userauth(string username,char[] password) throws ioexception{</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string result = "failed";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string passwd= new string(password);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us">[size=small;]<span style="font-family: times new roman;"><span style=""> [/size]httpclient httpclient = new httpclient();<span style=""> </span></span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]getmethod httpget = new getmethod(ssoserviceurl+action2+username+"&password="+passwd);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]passwd = null;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]try {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpclient.executemethod(httpget);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]result = httpget.getresponsebodyasstring();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]} finally {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpget.releaseconnection();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]return result;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">7 [/size]</span><span style="">真正安全的全方位</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">解决方案:</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">事实上有一种全方位的[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">解决方案能够解决这些问题,这就是</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">协议(</span><span lang="en-us"><span style="font-family: times new roman;">rfc 1510</span></span><span style="">)。</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">是网络安全应用标准</span><span lang="en-us"><span style="font-family: times new roman;">(http://web.mit.edu/kerberos/)</span></span><span style="">,由</span><span lang="en-us"><span style="font-family: times new roman;">mit</span></span><span style="">学校发明,被主流的操作系统所采用。在采用</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">的平台中,登录和认证是由操作系统本身来维护,认证的凭证也由操作系统来保存,这样整个桌面都可以处于同一个</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的系统保护中。操作系统中的各个应用(如</span><span lang="en-us"><span style="font-family: times new roman;">ftp,telnet</span></span><span style="">)只需要通过配置就能加入到</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">中。另外使用</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">最大的好处在于它的安全性。通过密钥算法的保证和密钥中心的建立,可以做到用户的密码根本不需要在网络中传输,而传输的信息也会十分的安全。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">目前支持[/size]<span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">的操作系统包括</span><span lang="en-us"><span style="font-family: times new roman;">solaris, windows,linux</span></span><span style="">等等主流的平台。只不过要搭建一个</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">的环境比较复杂,</span><span lang="en-us"><span style="font-family: times new roman;">kdc</span></span><span style="">(密钥分发中心)的建立也需要相当的步骤。</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">拥有非常成熟的</span><span lang="en-us"><span style="font-family: times new roman;">api</span></span><span style="">,包括</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">api</span></span><span style="">。使用</span><span lang="en-us"><span style="font-family: times new roman;">java generic security services(gss) api</span></span><span style="">并且使用</span><span lang="en-us"><span style="font-family: times new roman;">jaas</span></span><span style="">中对</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">的支持(详细信息请参见</span><span lang="en-us"><span style="font-family: times new roman;">sun</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">java&kerberos</span></span><span style="">教程</span><span lang="en-us"><span style="font-family: times new roman;">http://java.sun.com/ j2se/1.5.0/docs/guide/security/jgss/tutorials/index.html</span></span><span style="">),要将我们这个样例改造成对</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">的支持也是不难的。</span><span style="font-family: times new roman;"> </span><span style="">值得一提的是在</span><span lang="en-us"><span style="font-family: times new roman;">jdk6.0 </span></span><span style="">(</span><span lang="en-us"><span style="font-family: times new roman;">http://www.java.net/download/jdk6</span></span><span style="">)当中直接就包含了对</span><span lang="en-us"><span style="font-family: times new roman;">gss</span></span><span style="">的支持,不需要单独下载</span><span lang="en-us"><span style="font-family: times new roman;">gss</span></span><span style="">的包。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">本文的主要目的是阐述[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的基本原理,并提供了一种实现的方式。通过对源代码的分析来掌握开发</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">服务的技术要点和充分理解</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的应用范围。但是,本文仅仅说明了身份认证的服务,而另外一个和身份认证密不可分的服务</span><span lang="en-us"><span style="font-family: times new roman;">----</span></span><span style="">权限效验,却没有提到。要开发出真正的</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的产品,在功能上、性能上和安全上都必须有更加完备的考虑。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">王昱是[/size]<span lang="en-us"><span style="font-family: times new roman;">sun</span></span><span style="">中国工程研究院的</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">工程师,现在的主要负责全球合作伙伴的技术支持。作为一名</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">资深工程师和架构师,王昱在</span><span lang="en-us"><span style="font-family: times new roman;">java </span></span><span style="">的很多领域都有多年的造诣,特别是在</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">虚拟机、</span><span lang="en-us"><span style="font-family: times new roman;">j2ee</span></span><span style="">技术</span><span lang="en-us"><span style="font-family: times new roman;">(</span></span><span style="">包括</span><span lang="en-us"><span style="font-family: times new roman;">ejb, jsp/servlet, jms</span></span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">web services</span></span><span style="">等技术</span><span lang="en-us"><span style="font-family: times new roman;">)</span></span><span style="">、集群技术和</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">应用性能调优上有着较为丰富的经验。曾经多次在重要的</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">会议发表演讲,并在国际著名的</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">技术站</span><span style="font-family: times new roman;"> </span><span style="">点发表文章。</span></span><span style=""></span>
<span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">王昱[/size]<span lang="en-us"><span style="font-family: times new roman;"> yuwang881@gmail.com<span style=""> </span></span></span><span style="">博客地址</span><span lang="en-us"><span style="font-family: times new roman;">http://yuwang881.blog.sohu.com </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">关键字:[/size]<span lang="en-us"><span style="font-family: times new roman;">sso, java, j2ee, jaas</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">单点登录([/size]<span lang="en-us"><span style="font-family: times new roman;">single sign on</span></span><span style="">),简称为</span><span lang="en-us"><span style="font-family: times new roman;"> sso</span></span><span style="">,是目前比较流行的企业业务整合的解决方案之一。</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的定义是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]随着企业的发展,业务系统的数量在不断的增加,老的系统却不能轻易的替换,这会带来很多的开销。其一是管理上的开销,需要维护的系统越来越多。很多系统的数据是相互冗余和重复的,数据的不一致性会给管理工作带来很大的压力。业务和业务之间的相关性也越来越大,例如公司的计费系统和财务系统,财务系统和人事系统之间都不可避免的有着密切的关系。[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]通常来说,每个单独的系统都会有自己的安全体系和身份认证系统。整合以前,进入每个系统都需要进行登录,这样的局面不仅给管理上带来了很大的困难,在安全方面也埋下了重大的隐患。下面是一些著名的调查公司显示的统计数据:[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•频繁的[/size]<span lang="en-us"><span style="font-family: times new roman;"> it </span></span><span style="">用户平均有</span><span lang="en-us"><span style="font-family: times new roman;"> 21 </span></span><span style="">个密码</span><span lang="en-us"><span style="font-family: times new roman;"> - </span></span><span style="">资料来源:</span><span lang="en-us"><span style="font-family: times new roman;"> nta monitor password survey</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•每[/size]<span lang="en-us"><span style="font-family: times new roman;"> 79 </span></span><span style="">秒出现一起身份被窃事件</span><span lang="en-us"><span style="font-family: times new roman;"> - </span></span><span style="">资料来源:</span><span lang="en-us"><span style="font-family: times new roman;">national small business travelassoc</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•到[/size]<span lang="en-us"><span style="font-family: times new roman;"> 2007 </span></span><span style="">年,身份管理市场将成倍增长至</span><span lang="en-us"><span style="font-family: times new roman;">$4.5b - </span></span><span style="">资料来源:</span><span lang="en-us"><span style="font-family: times new roman;">ids </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">•提高</span><span lang="en-us"><span style="font-family: times new roman;"> it </span></span><span style="">效率:对于每</span><span lang="en-us"><span style="font-family: times new roman;"> 1000 </span></span><span style="">个受管用户,每用户可节省</span><span lang="en-us"><span style="font-family: times new roman;">$70k</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•生产力提高:每个新员工可节省[/size]<span lang="en-us"><span style="font-family: times new roman;"> $1k</span></span><span style="">,每个老员工可节省</span><span lang="en-us"><span style="font-family: times new roman;"> $350</span></span><span lang="en-us" style="font-family: tahoma;">�</span><span style="">资料来源:</span><span lang="en-us"><span style="font-family: times new roman;">giga</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">另外,使用“单点登录”还是[/size]<span lang="en-us"><span style="font-family: times new roman;">soa</span></span><span style="">时代的需求之一。在面向服务的架构中,服务和服务之间,程序和程序之间的通讯大量存在,服务之间的安全认证是</span><span lang="en-us"><span style="font-family: times new roman;">soa</span></span><span style="">应用的难点之一,应此建立“单点登录”的系统体系能够大大简化</span><span lang="en-us"><span style="font-family: times new roman;">soa</span></span><span style="">的安全问题,提高服务之间的合作效率。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">随着[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">技术的流行,</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的产品也是满天飞扬。所有著名的软件厂商都提供了相应的解决方案。在这里我并不想介绍自己公司(</span><span lang="en-us"><span style="font-family: times new roman;">sun microsystems</span></span><span style="">)的产品,而是对</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">技术本身进行解析,并且提供自己开发这一类产品的方法和简单演示。有关我写这篇文章的目的,请参考我的博客(</span><span lang="en-us"><span style="font-family: times new roman;">http://yuwang881.blog.sohu.com/3184816.html</span></span><span style="">)。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">单点登录的机制也一样,如下图所示,当用户第一次访问应用系统[/size]<span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">的时候,因为还没有登录,会被引导到认证系统中进行登录(</span><span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">);根据用户提供的登录信息,认证系统进行身份效验,如果通过效验,应该返回给用户一个认证的凭据--</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">(</span><span lang="en-us"><span style="font-family: times new roman;">2</span></span><span style="">);用户再访问别的应用的时候(</span><span lang="en-us"><span style="font-family: times new roman;">3</span></span><span style="">,</span><span lang="en-us"><span style="font-family: times new roman;">5</span></span><span style="">)就会将这个</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">带上,作为自己认证的凭据,应用系统接受到请求之后会把</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">送到认证系统进行效验,检查</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">的合法性(</span><span lang="en-us"><span style="font-family: times new roman;">4</span></span><span style="">,</span><span lang="en-us"><span style="font-family: times new roman;">6</span></span><span style="">)。如果通过效验,用户就可以在不用再次登录的情况下访问应用系统</span><span lang="en-us"><span style="font-family: times new roman;">2</span></span><span style="">和应用系统</span><span lang="en-us"><span style="font-family: times new roman;">3</span></span><span style="">了。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us" style="color: black; font-family: verdana;">[size=small;] [/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">从上面的视图可以看出,要实现[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">,需要以下主要的功能:</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">统一的认证系统是[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的前提之一。认证系统的主要功能是将用户的登录信息和用户信息库相比较,对用户进行登录认证;认证成功后,认证系统应该生成统一的认证标志(</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">),返还给用户。另外,认证系统还应该对</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">进行效验,判断其有效性。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">要实现[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的功能,让用户只登录一次,就必须让应用系统能够识别已经登录过的用户。应用系统应该能对</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">进行识别和提取,通过与认证系统的通讯,能自动判断当前用户是否登录过,从而完成单点登录的功能。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">•单一的用户信息数据库并不是必须的,有许多系统不能将所有的用户信息都集中存储,应该允许用户信息放置在不同的存储中,如下图所示。事实上,只要统一认证系统,统一</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">的产生和效验,无论用户信息存储在什么地方,都能实现单点登录。</span><span lang="en-us"><span style="font-family: times new roman;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">•统一的认证系统并不是说只有单个的认证服务器,如下图所示,整个系统可以存在两个以上的认证服务器,这些服务器甚至可以是不同的产品。认证服务器之间要通过标准的通讯协议,互相交换认证信息,就能完成更高级别的单点登录。如下图,当用户在访问应用系统</span><span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">时,由第一个认证服务器进行认证后,得到由此服务器产生的</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">。当他访问应用系统</span><span lang="en-us"><span style="font-family: times new roman;">4</span></span><span style="">的时候,认证服务器</span><span lang="en-us"><span style="font-family: times new roman;">2</span></span><span style="">能够识别此</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">是由第一个服务器产生的,通过认证服务器之间标准的通讯协议(例如</span><span lang="en-us"><span style="font-family: times new roman;">saml</span></span><span style="">)来交换认证信息,仍然能够完成</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的功能。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span lang="en-us" style="color: black; line-height: 150%; font-family: verdana;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">3 web-sso[/size]</span><span style="">的实现</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">为什么说[/size]<span lang="en-us"><span style="font-family: times new roman;">web-sso</span></span><span style="">比较容易实现呢?这是有</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用自身的特点决定的。</span><span lang="en-us"><span style="font-family: times new roman;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">但是我们通常的应用是有状态的。先不用提不同应用之间的[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">,在同一个应用中也需要保存用户的登录身份信息。例如用户在访问页面</span><span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">的时候进行了登录,但是刚才也提到,客户端的每个请求都是单独的连接,当客户再次访问页面</span><span lang="en-us"><span style="font-family: times new roman;">2</span></span><span style="">的时候,如何才能告诉</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器,客户刚才已经登录过了呢?浏览器和服务器之间有约定:通过使用</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">技术来维护应用的状态。</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">是可以被</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器设置的字符串,并且可以保存在浏览器中。如下图所示,当浏览器访问了页面</span><span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">时,</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器设置了一个</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">,并将这个</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">和页面</span><span lang="en-us"><span style="font-family: times new roman;">1</span></span><span style="">一起返回给浏览器,浏览器接到</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">之后,就会保存起来,在它访问页面</span><span lang="en-us"><span style="font-family: times new roman;">2</span></span><span style="">的时候会把这个</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">也带上,</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器接到请求时也能读出</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的值,根据</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">值的内容就可以判断和恢复一些用户的信息状态。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">web-sso[/size]</span><span style="">完全可以利用</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">结束来完成用户登录信息的保存,将浏览器中的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">和上文中的</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">结合起来,完成</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的功能。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;"><span style=""> [/size]1.</span></span><span style="">统一的身份认证服务。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">3.1 web sso [/size]</span><span style="">的样例</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]样例下载、安装部署和运行指南:[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•这三个[/size]<span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用完全可以单独部署,它们可以分别部署在不同的机器,不同的操作系统和不同的</span><span lang="en-us"><span style="font-family: times new roman;">j2ee</span></span><span style="">的产品上,它们完全是标准的和平台无关的应用。但是有一个限制,那两台部署应用(</span><span lang="en-us"><span style="font-family: times new roman;">demo1</span></span><span style="">、</span><span lang="en-us"><span style="font-family: times new roman;">demo2</span></span><span style="">)的机器的域名需要相同,这在后面的章节中会解释到</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">domain</span></span><span style="">的关系以及如何制作跨域的</span><span lang="en-us"><span style="font-family: times new roman;">web-sso</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•解压缩[/size]<span lang="en-us"><span style="font-family: times new roman;">ssowebdemo1</span></span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">ssowebdemo2</span></span><span style="">文件,分别在它们</span><span lang="en-us"><span style="font-family: times new roman;">/web-inf/</span></span><span style="">下找到</span><span lang="en-us"><span style="font-family: times new roman;">web.xml</span></span><span style="">文件,请修改其中的几个初始化参数</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"><param-name>ssoserviceurl</param-name></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"></init-param></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"><param-name>ssologinpage</param-name></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"></init-param></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•请输入第一个[/size]<span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用的测试</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">(</span><span lang="en-us"><span style="font-family: times new roman;">test.jsp</span></span><span style="">)</span><span lang="en-us"><span style="font-family: times new roman;">,</span></span><span style="">例如</span><span lang="en-us"><span style="font-family: times new roman;">http://wangyu.prc.sun.com:8080/ ssowebdemo1/test.jsp</span></span><span style="">,如果是第一次访问,便会自动跳转到登录界面,如下图</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us" style="color: black; font-family: verdana;">[size=small;] [/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span lang="en-us" style="color: black; font-family: verdana;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span lang="en-us" style="color: black; line-height: 150%; font-family: verdana;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">3.2.1[/size]</span><span style="">身份认证服务代码解析</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">ssoauth[/size]</span><span style="">的代码如下面的列表显示,结构非常简单,先看看这个</span><span lang="en-us"><span style="font-family: times new roman;">servlet</span></span><span style="">的主体部分:</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import java.io.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">importjava.text.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">importjava.util.concurrent.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">importjavax.servlet.http.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]static private concurrentmap accounts;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]stringcookiename="wangyudesktopssoid";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]public void init(servletconfig config)throws servletexception {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]domainname=config.getinitparameter("domainname");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]ssoids = new concurrenthashmap();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]accounts.put("wangyu","wangyu");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]accounts.put("carol","carol");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]protected voidprocessrequest(httpservletrequest request, httpservletresponse response) throwsservletexception, ioexception {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string action =request.getparameter("action");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">} </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">在主要的请求处理方法[/size]<span lang="en-us"><span style="font-family: times new roman;">processrequest()</span></span><span style="">中,可以很清楚的看到</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">的所有功能</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">2.[/size]</span><span style="">如果用户已经登录过本系统,再访问别的应用的时候,是不需要再次登录的。因为浏览器会将第一次登录时产生的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">和请求一起发送。效验</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的有效性是</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">的主要功能之一。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">4.ssoauth[/size]</span><span style="">还提供</span><span lang="en-us"><span style="font-family: times new roman;">logout</span></span><span style="">服务。</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private void handlerfromlogin(httpservletrequest request,httpservletresponse response) throws servletexception, ioexception {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string username = request.getparameter("username");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string password = request.getparameter("password");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string pass = (string)accounts.get(username);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]if ((pass==null)||(!pass.equals(password))) </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]getservletcontext().getrequestdispatcher("/failed.html").forward(request,response);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]else {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string gotourl = request.getparameter("goto");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string newid = createuid();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]ssoids.put(newid, username);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]cookie wangyu = new cookie(cookiename, newid);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]wangyu.setdomain(domainname);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]wangyu.setmaxage(60000);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]wangyu.setvalue(newid);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]wangyu.setpath("/");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]response.addcookie(wangyu);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]system.out.println("login success, goto back url:" + gotourl);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]if (gotourl != null) {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]printwriter out =response.getwriter();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]response.sendredirect(gotourl);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]out.close();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us">[size=small;]<span style="font-family: times new roman;"><span style=""> [/size]}<span style=""> </span></span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">登录成功后,浏览器会到哪个页面呢?那我们回顾一下我们是如何使用身份认证服务的。一般来说我们不会直接访问身份服务的任何[/size]<span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">,包括</span><span lang="en-us"><span style="font-family: times new roman;">login.jsp</span></span><span style="">。身份服务是用来保护其他应用服务的,用户一般在访问一个受</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">保护的</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用的某个</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">时,当前这个应用会发现当前的用户还没有登录,便强制将也页面转向</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">login.jsp</span></span><span style="">,让用户登录。如果登录成功后,应该自动的将用户的浏览器指向用户最初想访问的那个</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">。在</span><span lang="en-us"><span style="font-family: times new roman;">handlerfromlogin()</span></span><span style="">这个方法中,我们通过接收“</span><span lang="en-us"><span style="font-family: times new roman;">goto</span></span><span style="">”这个参数来保存用户最初访问的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">,成功后便重新定向到这个页面中。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]其他的方法更加简单,这里就不多解释了。[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">要实现[/size]<span lang="en-us"><span style="font-family: times new roman;">web-sso</span></span><span style="">的功能,只有身份认证服务是不够的。这点很显然,要想使多个应用具有单点登录的功能,还需要每个应用本身的配合:将自己的身份认证的服务交给一个统一的身份认证服务-</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">。</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">服务中提供的各个方法就是供每个加入</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用来调用的。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">•</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用中每一个需要安全保护的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">在访问以前,都需要进行安全检查,如果发现没有登录(没有发现认证之后所带的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">),就重新定向到</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">中的</span><span lang="en-us"><span style="font-family: times new roman;">login.jsp</span></span><span style="">进行登录。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•当你再访问这个应用的需要保护的[/size]<span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">的时候,系统还是要进行安全检查的,但是这次系统能够发现相应的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•如果[/size]<span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">效验成功,就允许用户访问当前请求的资源。</span><span lang="en-us"><span style="font-family: times new roman;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]以上这些功能,可以用很多方法来实现:[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•可以通过一个[/size]<span lang="en-us"><span style="font-family: times new roman;">controller</span></span><span style="">,将所有的功能都写到一个</span><span lang="en-us"><span style="font-family: times new roman;">servlet</span></span><span style="">中,然后在</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">映射的时候,映射到所有需要保护的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">集合中(例如</span><span lang="en-us"><span style="font-family: times new roman;">*.jsp</span></span><span style="">,</span><span lang="en-us"><span style="font-family: times new roman;">/security/*</span></span><span style="">等)。这个方法可以使用,不过,它的缺点是不能重用。在每个应用中都要部署一个相同的</span><span lang="en-us"><span style="font-family: times new roman;">servlet</span></span><span style="">。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">package sso;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import java.io.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import java.net.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import java.util.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import java.text.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import javax.servlet.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import javax.servlet.http.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import javax.servlet.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">import org.apache.commons.httpclient.*;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">importorg.apache.commons.httpclient.methods.getmethod;</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">public class ssofilter implements filter {</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private filterconfig filterconfig = null;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private string cookiename="wangyudesktopssoid";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private string ssoserviceurl="http://wangyu.prc.sun.com:8080/ssoauth/ssoauth";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private string ssologinpage="http://wangyu.prc.sun.com:8080/ssoauth/login.jsp";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]public void init(filterconfig filterconfig) {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]this.filterconfig = filterconfig;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]if (filterconfig != null) {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]if (debug) {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]log("ssofilter:initializingfilter");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us">[size=small;]<span style="font-family: times new roman;"><span style=""> [/size]}<span style=""> </span></span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]cookiename = filterconfig.getinitparameter("cookiename");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]ssoserviceurl =filterconfig.getinitparameter("ssoserviceurl");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]ssologinpage = filterconfig.getinitparameter("ssologinpage");</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">以上的初始化的源代码有两点需要说明:一是有两个需要配置的参数[/size]<span lang="en-us"><span style="font-family: times new roman;">ssoserviceurl</span></span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">ssologinpage</span></span><span style="">。因为当前的</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用很可能和身份认证服务(</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">)不在同一台机器上,所以需要让这个</span><span lang="en-us"><span style="font-family: times new roman;">filter</span></span><span style="">知道身份认证服务部署的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">,这样才能去调用它的服务。另外一点就是由于身份认证的服务调用是要通过</span><span lang="en-us"><span style="font-family: times new roman;">http</span></span><span style="">协议来调用的(在本样例中是这样设计的,读者完全可以设计自己的身份服务,使用别的调用协议,如</span><span lang="en-us"><span style="font-family: times new roman;">rmi</span></span><span style="">或</span><span lang="en-us"><span style="font-family: times new roman;">soap</span></span><span style="">等等),所有笔者引用了</span><span lang="en-us"><span style="font-family: times new roman;">apache</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">commons</span></span><span style="">工具包(详细信息情访问</span><span lang="en-us"><span style="font-family: times new roman;">apache </span></span><span style="">的网站</span><span lang="en-us"><span style="font-family: times new roman;">http://jakarta.apache.org/commons/index.html</span></span><span style="">),其中的“</span><span lang="en-us"><span style="font-family: times new roman;">httpclient</span></span><span style="">”可以大大简化</span><span lang="en-us"><span style="font-family: times new roman;">http</span></span><span style="">调用的编程。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">dofilter()[/size]</span><span style="">方法的逻辑也是非常简单的,在接收到请求的时候,先去查找是否存在期望的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">值,如果找到了,就会调用</span><span lang="en-us"><span style="font-family: times new roman;">ssoservice(cookievalue)</span></span><span style="">去效验这个</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的有效性。如果</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">效验不成功或者</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">根本不存在,就会直接转到登录界面让用户登录;如果</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">效验成功,就不会做任何阻拦,让此请求进行下去。在配置文件中,有下面的一个节点表示了此</span><span lang="en-us"><span style="font-family: times new roman;">filter</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span><span style="">映射关系:只拦截所有的</span><span lang="en-us"><span style="font-family: times new roman;">jsp</span></span><span style="">请求。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"><filter-name>ssofilter</filter-name></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"></filter-mapping></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private string ssoservice(string cookievalue) throws ioexception {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string authaction = "?action=authcookie&cookiename=";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpclient httpclient = new httpclient();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]getmethod httpget = new getmethod(ssoserviceurl+authaction+cookievalue);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]try { </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpclient.executemethod(httpget);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string result = httpget.getresponsebodyasstring();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]return result;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]} finally {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpget.releaseconnection();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]private void logoutservice(string cookievalue) throws ioexception {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string authaction = "?action=logout&cookiename=";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpclient httpclient = new httpclient();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]getmethod httpget = new getmethod(ssoserviceurl+authaction+cookievalue);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]try {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpclient.executemethod(httpget);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpget.getresponsebodyasstring();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]} finally {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpget.releaseconnection();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">其他的函数都很简单,有很多都是我的[/size]<span lang="en-us"><span style="font-family: times new roman;">ide</span></span><span style="">(</span><span lang="en-us"><span style="font-family: times new roman;">netbeans</span></span><span style="">)替我自动生成的。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">当前这个[/size]<span lang="en-us"><span style="font-family: times new roman;">web-sso</span></span><span style="">的方案是一个比较简单的雏形,主要是用来演示</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的概念和说明</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">技术的实现方式。有很多方面还需要完善,其中安全性是非常重要的一个方面。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">•</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的长度和复杂度</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•[/size]<span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的效验和保护</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]•当其中一个应用的安全性不好,其他所有的应用都会受到安全威胁[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">这些安全漏洞在商业的[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">解决方案中都会有所考虑,提供相关的安全措施和保护手段,例如</span><span lang="en-us"><span style="font-family: times new roman;">sun</span></span><span style="">公司的</span><span lang="en-us"><span style="font-family: times new roman;">accessmanager</span></span><span style="">,</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的复杂读和对</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的保护都做得非常好。另外在</span><span lang="en-us"><span style="font-family: times new roman;">opnesso </span></span><span style="">(</span><span lang="en-us"><span style="font-family: times new roman;">https://opensso.dev.java.net/</span></span><span style="">)的架构指南中也给出了部分安全措施的解决方案。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]除了安全性,当前方案在功能和性能上都需要很多的改进:[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•我们编写的[/size]<span lang="en-us"><span style="font-family: times new roman;">filter</span></span><span style="">只能用于</span><span lang="en-us"><span style="font-family: times new roman;">j2ee</span></span><span style="">的应用,而对于大量非</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用,却无法提供</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">服务。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•当前的方案不能支持分别位于不同[/size]<span lang="en-us"><span style="font-family: times new roman;">domain</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用进行</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">。这是因为浏览器在访问</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器的时候,仅仅会带上和当前</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">服务器具有相同</span><span lang="en-us"><span style="font-family: times new roman;">domain</span></span><span style="">名称的那些</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">。要提供跨域的</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的解决方案有很多其他的方法,在这里就不多说了。</span><span lang="en-us"><span style="font-family: times new roman;">sun</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">access manager</span></span><span style="">就具有跨域的</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的功能。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">•另外系统还需要很多其他的服务,如在内存中定时删除无用的[/size]<span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">映射等等,都是一个严肃的解决方案需要考虑的问题。</span><span lang="en-us"><span style="font-family: times new roman;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">从[/size]<span lang="en-us"><span style="font-family: times new roman;">web-sso</span></span><span style="">的概念延伸开,我们可以把</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的技术拓展到整个桌面的应用,不仅仅局限在浏览器。</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的概念和原则都没有改变,只需要再做一点点的工作,就可以完成桌面</span><span lang="en-us"><span style="font-family: times new roman;"> sso </span></span><span style="">的应用。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">从网站可以下载一个简单的桌面[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的样例</span><span lang="en-us"><span style="font-family: times new roman;">(http://gceclub.sun.com.cn/wangyu/</span></span><span style="">和全部源码(</span><span lang="en-us"><span style="font-family: times new roman;">http://gceclub.sun.com.cn/wangyu/desktop-sso/desktopsso_src.zip</span></span><span style="">),虽然简单,但是它具有桌面</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">大多数的功能,稍微加以扩充就可以成为自己的解决方案。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;"><span style=""> [/size]1.</span></span><span style="">运行此桌面</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">需要三个前提条件:</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">b) [/size]</span><span style="">当前桌面需要运行</span><span lang="en-us"><span style="font-family: times new roman;">mozilla</span></span><span style="">或</span><span lang="en-us"><span style="font-family: times new roman;">netscape</span></span><span style="">浏览器,因为我们将</span><span lang="en-us"><span style="font-family: times new roman;">ticket</span></span><span style="">保存到</span><span lang="en-us"><span style="font-family: times new roman;">mozilla</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">文件中</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">2.[/size]</span><span style="">解开</span><span lang="en-us"><span style="font-family: times new roman;">desktopsso.zip</span></span><span style="">文件,里面有两个目录</span><span lang="en-us"><span style="font-family: times new roman;">bin</span></span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">lib</span></span><span style="">。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">a)ssoserviceurl[/size]</span><span style="">要指向</span><span lang="en-us"><span style="font-family: times new roman;">websso</span></span><span style="">部署的身份认证的</span><span lang="en-us"><span style="font-family: times new roman;">url</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">c)cookiefilepath[/size]</span><span style="">要指向当前用户的</span><span lang="en-us"><span style="font-family: times new roman;">mozilla</span></span><span style="">所存放</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的文件</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">5.[/size]</span><span style="">在</span><span lang="en-us"><span style="font-family: times new roman;">bin</span></span><span style="">下的运行脚本可能需要作相应的修改</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">b) java [/size]</span><span style="">运行程序需要放置在当前运行的路径下,否则需要加上</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">的路径全名。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">样例程序包含三个简单的[/size]<span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">控制台程序,这三个程序单独运行都需要登录。如果运行第一个命叫“</span><span lang="en-us"><span style="font-family: times new roman;">gamesystem</span></span><span style="">”的程序,提示需要输入用户名和密码:</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us" style="color: black; font-family: verdana;">[size=small;] [/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span style="">[size=small;]效验成功以后,便会显示当前登录的用户的基本信息等等。[/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us" style="color: black; font-family: verdana;">[size=small;] [/size]</span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style=""><span style="font-family: times new roman;"> [/size]</span></span><span style="">这时候再运行第二个桌面</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">应用(</span><span lang="en-us"><span style="font-family: times new roman;">mailsystem</span></span><span style="">)的时候,就不需要再登录了,直接就显示出来刚才登录的用户。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">第三个应用是[/size]<span lang="en-us"><span style="font-family: times new roman;">logout</span></span><span style="">,运行它之后,用户便退出系统。再访问的时候,又需要重新登录了。请读者再制裁执行完</span><span lang="en-us"><span style="font-family: times new roman;">logout</span></span><span style="">之后,重新验证一下前两个应用的</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">:先运行第二个应用,再运行第一个,会看到相同的效果。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">这时候再打开[/size]<span lang="en-us"><span style="font-family: times new roman;">mozilla</span></span><span style="">浏览器,访问以前提到的那两个</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用,会发现只要桌面应用如果登录过,</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用就不用再登录了,而且能显示刚才登录的用户的信息。读者可以在几个桌面和</span><span lang="en-us"><span style="font-family: times new roman;">web</span></span><span style="">应用之间进行登录和</span><span lang="en-us"><span style="font-family: times new roman;">logout</span></span><span style="">的试验,看看它们之间的</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">6.3[/size]</span><span style="">桌面样例的源码分析</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]desktopsso {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]desktopsso.share.passwordloginmodule required;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]desktopsso.share.desktopssologinmodule required;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">}; </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;">[size=small;]<span style="">在[/size]<span lang="en-us"><span style="font-family: times new roman;">config.properties</span></span><span style="">的文件中,我们配置了它们的值:</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">ssoserviceurl=http://wangyu.prc.sun.com:8080/ssoauth/ssoauth</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">ssologinpage=http://wangyu.prc.sun.com:8080/ssoauth/login.jsp</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">cookiefilepath=c:\\documents andsettings\\yw137672\\applicationdata\\mozilla\\profiles\\default\\hog6z1ji.slt\\cookies.txt </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;">[size=small;]<span style="">下面是[/size]<span lang="en-us"><span style="font-family: times new roman;">cookielogin()</span></span><span style="">方法的实体,它的逻辑是:先从</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">文件中获得相应的</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">值,通过身份效验服务效验</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">的有效性。如果</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">有效就算登录成功;如果不成功或</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">不存在,用</span><span lang="en-us"><span style="font-family: times new roman;">cookie</span></span><span style="">登录就算失败。</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">用用户名和密码登录的方法要复杂一些,通过[/size]<span lang="en-us"><span style="font-family: times new roman;">callback</span></span><span style="">的机制和屏幕输入输出进行信息交互,完成用户登录信息的获取;获取信息以后通过</span><span lang="en-us"><span style="font-family: times new roman;">userauth</span></span><span style="">方法来调用远端</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">的服务来判定当前登录的有效性。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">cookieauth[/size]</span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">userauth</span></span><span style="">方法都是利用</span><span lang="en-us"><span style="font-family: times new roman;">apahce</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">httpclient</span></span><span style="">工具包和远程的</span><span lang="en-us"><span style="font-family: times new roman;">ssoauth</span></span><span style="">进行</span><span lang="en-us"><span style="font-family: times new roman;">http</span></span><span style="">连接,获取服务。</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;"> </span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman; font-size: small;">private string userauth(string username,char[] password) throws ioexception{</span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string result = "failed";</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]string passwd= new string(password);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us">[size=small;]<span style="font-family: times new roman;"><span style=""> [/size]httpclient httpclient = new httpclient();<span style=""> </span></span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]getmethod httpget = new getmethod(ssoserviceurl+action2+username+"&password="+passwd);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]passwd = null;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]try {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpclient.executemethod(httpget);</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]result = httpget.getresponsebodyasstring();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]} finally {</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]httpget.releaseconnection();</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]return result;</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style=""><span style="font-family: times new roman; font-size: small;"> </span></span></span><span style=""></span>
<p class="msonormal" style="margin: 0cm 0cm 0pt;"><span lang="en-us"><span style="font-family: times new roman;">[size=small;]<span style=""> [/size]}</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span lang="en-us"><span style="font-family: times new roman;">7 [/size]</span><span style="">真正安全的全方位</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">解决方案:</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">事实上有一种全方位的[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">解决方案能够解决这些问题,这就是</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">协议(</span><span lang="en-us"><span style="font-family: times new roman;">rfc 1510</span></span><span style="">)。</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">是网络安全应用标准</span><span lang="en-us"><span style="font-family: times new roman;">(http://web.mit.edu/kerberos/)</span></span><span style="">,由</span><span lang="en-us"><span style="font-family: times new roman;">mit</span></span><span style="">学校发明,被主流的操作系统所采用。在采用</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">的平台中,登录和认证是由操作系统本身来维护,认证的凭证也由操作系统来保存,这样整个桌面都可以处于同一个</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的系统保护中。操作系统中的各个应用(如</span><span lang="en-us"><span style="font-family: times new roman;">ftp,telnet</span></span><span style="">)只需要通过配置就能加入到</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">中。另外使用</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">最大的好处在于它的安全性。通过密钥算法的保证和密钥中心的建立,可以做到用户的密码根本不需要在网络中传输,而传输的信息也会十分的安全。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">目前支持[/size]<span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">的操作系统包括</span><span lang="en-us"><span style="font-family: times new roman;">solaris, windows,linux</span></span><span style="">等等主流的平台。只不过要搭建一个</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">的环境比较复杂,</span><span lang="en-us"><span style="font-family: times new roman;">kdc</span></span><span style="">(密钥分发中心)的建立也需要相当的步骤。</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">拥有非常成熟的</span><span lang="en-us"><span style="font-family: times new roman;">api</span></span><span style="">,包括</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">api</span></span><span style="">。使用</span><span lang="en-us"><span style="font-family: times new roman;">java generic security services(gss) api</span></span><span style="">并且使用</span><span lang="en-us"><span style="font-family: times new roman;">jaas</span></span><span style="">中对</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">的支持(详细信息请参见</span><span lang="en-us"><span style="font-family: times new roman;">sun</span></span><span style="">的</span><span lang="en-us"><span style="font-family: times new roman;">java&kerberos</span></span><span style="">教程</span><span lang="en-us"><span style="font-family: times new roman;">http://java.sun.com/ j2se/1.5.0/docs/guide/security/jgss/tutorials/index.html</span></span><span style="">),要将我们这个样例改造成对</span><span lang="en-us"><span style="font-family: times new roman;">kerberos</span></span><span style="">的支持也是不难的。</span><span style="font-family: times new roman;"> </span><span style="">值得一提的是在</span><span lang="en-us"><span style="font-family: times new roman;">jdk6.0 </span></span><span style="">(</span><span lang="en-us"><span style="font-family: times new roman;">http://www.java.net/download/jdk6</span></span><span style="">)当中直接就包含了对</span><span lang="en-us"><span style="font-family: times new roman;">gss</span></span><span style="">的支持,不需要单独下载</span><span lang="en-us"><span style="font-family: times new roman;">gss</span></span><span style="">的包。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">本文的主要目的是阐述[/size]<span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的基本原理,并提供了一种实现的方式。通过对源代码的分析来掌握开发</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">服务的技术要点和充分理解</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的应用范围。但是,本文仅仅说明了身份认证的服务,而另外一个和身份认证密不可分的服务</span><span lang="en-us"><span style="font-family: times new roman;">----</span></span><span style="">权限效验,却没有提到。要开发出真正的</span><span lang="en-us"><span style="font-family: times new roman;">sso</span></span><span style="">的产品,在功能上、性能上和安全上都必须有更加完备的考虑。</span></span><span style=""></span>
<p class="msonormal" style="margin: 7.8pt 0cm; line-height: 150%;">[size=small;]<span style="">王昱是[/size]<span lang="en-us"><span style="font-family: times new roman;">sun</span></span><span style="">中国工程研究院的</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">工程师,现在的主要负责全球合作伙伴的技术支持。作为一名</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">资深工程师和架构师,王昱在</span><span lang="en-us"><span style="font-family: times new roman;">java </span></span><span style="">的很多领域都有多年的造诣,特别是在</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">虚拟机、</span><span lang="en-us"><span style="font-family: times new roman;">j2ee</span></span><span style="">技术</span><span lang="en-us"><span style="font-family: times new roman;">(</span></span><span style="">包括</span><span lang="en-us"><span style="font-family: times new roman;">ejb, jsp/servlet, jms</span></span><span style="">和</span><span lang="en-us"><span style="font-family: times new roman;">web services</span></span><span style="">等技术</span><span lang="en-us"><span style="font-family: times new roman;">)</span></span><span style="">、集群技术和</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">应用性能调优上有着较为丰富的经验。曾经多次在重要的</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">会议发表演讲,并在国际著名的</span><span lang="en-us"><span style="font-family: times new roman;">java</span></span><span style="">技术站</span><span style="font-family: times new roman;"> </span><span style="">点发表文章。</span></span><span style=""></span>
<span style=""></span>
发表评论
-
LINUX-网卡Bond
2012-02-08 15:22 893网卡bond是通过把多张网卡绑定为一个逻辑网卡,实现本 ... -
Chrome+SwitchySharp+myentunnel+SSH
2012-02-04 17:14 1889? <p style="margin ... -
Java中HashMap排序和遍历 .
2012-02-03 10:29 1953<div id="article_co ... -
/dev/shm放/tmp
2012-02-02 17:14 928呵呵,有时候不懂装懂的人挺搞笑的哈 转http://z ... -
java简单的通用ajax分页方法
2012-02-02 12:44 1799发表一个自己常用的分页的通用代码,实现了ajax分页。 ... -
[转]Cocoa中回调delegate的方法时判断delegate是否已经被释放
2012-01-31 16:58 1098<p>http://pingguohe.n ... -
单一入口应用程序概述
2012-01-11 14:03 683什么是单一入口应用程序? 在解释什么是单一入口应用 ... -
各种常用编译开关位置
2012-01-11 12:54 695vendor\third-party\products ... -
JS合并单元格、JavaScript单元格合并
2011-12-28 14:08 1110<span style="font-f ... -
flex入门
2011-12-28 12:23 875<span style="fon ... -
通过发微博控制电脑的程序源码
2011-12-20 12:29 1287前段时间看群里挺多讨论 微博api,正好前几天看到有个 ... -
由ORM框架设计看到微软与苹果的最大差别
2011-12-20 09:59 1373一不小心加入水 ... -
《南方周末》《南方日报》《新京报》《南方体育》等报纸在线阅读
2011-12-15 11:04 1257我经常到南方报业提供的网址下载他们出版的报纸看,今天突 ... -
java 加密算法 base64
2011-12-14 17:58 900<span style="color: ... -
终于完成一个最重要的任务——找工作
2011-12-14 14:54 630</span></span>& ... -
HTML特殊字符
2011-12-14 10:54 697最近在做某种模拟器上的网页的显示,需要考虑HTML特殊 ... -
01_Android介绍
2011-12-13 10:44 598? <h4 style="margin ... -
2008 ==> 2009
2011-12-13 10:39 600发现时间过的真的很快,这么快,又是新的一年了。特地翻出 ... -
TOMCAT常用优化
2011-12-12 16:04 667<p class="MsoNorm ... -
职场官话
2011-12-12 12:29 562官场充斥着官话,职场也满是官话,可能你没有注意到而已。 ...
相关推荐
总结来说,单点登录(SSO)通过集中式的身份验证服务,为多应用环境提供了便捷的用户登录体验。在Java环境下,借助Spring Security这样的框架,我们可以轻松地构建起自己的SSO系统,为用户提供无缝的跨系统访问。在...
单点登录(Single Sign-On,简称SSO)是一种网络身份验证技术,允许用户在一个系统中登录后,无需再次输入凭证即可访问其他相互信任的系统。这种技术在企业环境中尤其重要,因为它提高了用户体验,减少了安全管理的...
### 编写你自己的单点登录服务 #### 单点登录概述 单点登录(Single Sign-On,简称SSO)是一种认证模式,它允许用户在多个应用系统中仅需完成一次登录过程,即可访问所有相互信任的应用系统。这种模式不仅提高了...
通过这些知识点的学习和实践,你可以创建一个基本的SSO单点登录DEMO,为多应用环境提供便捷的身份验证方案。在实际项目中,你可能还需要根据具体需求进行扩展,比如支持OAuth、OpenID Connect等更现代的认证协议,...
通过理解以上知识点,你可以根据提供的SSO项目源码学习如何在C#环境中实现单点登录功能。该项目可能包括了CAS服务器的实现、子站点的配置以及用户登录、令牌验证的逻辑。通过对这些代码的分析和实践,你将能够掌握...
SSO(Single Sign-On)单点登录是一种身份验证机制,允许用户在一次登录后访问多个应用程序,而无需再次输入凭证。在这个"ssso单点登录demo.zip"压缩包中,包含了一个基于Spring Boot、Spring Data JPA和MySQL实现的...
单点登录(Single Sign-On,简称SSO)是一种网络身份验证机制,允许用户在一个系统上登录后,无需再次验证即可访问多个相互关联的系统。在IT行业中,SSO技术广泛应用于企业级应用,提高用户体验,简化管理并增强安全...
SSO(Single Sign-On)单点登录是一种身份验证机制,允许用户在一次登录后访问多个相互关联的应用系统,而无需再次进行身份验证。在本文中,我们将深入探讨如何使用SSM(Spring MVC、Spring、MyBatis)框架结合Redis...
在本场景中,我们关注的是Jeecg如何配置单点登录(Single Sign-On,简称SSO)以及相关的登录验证代码。单点登录是一种网络应用架构中的安全机制,允许用户在一次登录后,就能访问多个相互关联的应用系统,而无需再次...
SSO(Single Sign-On)单点登录是一种网络应用中用户身份验证的技术,允许用户通过一次登录操作访问多个相互信任的应用系统。在这个实例中,我们将会深入理解SSO的工作原理,并通过提供的项目Demo来实践这一技术。 ...
SSO(Single Sign-On)单点登录是一种身份验证机制,允许用户通过一次登录操作访问多个相互关联的应用系统,而无需多次输入凭证。这种技术在现代企业信息化建设中扮演着重要角色,因为它提高了用户体验,同时也简化...
SSO(Single Sign-On)是单点登录的缩写,是一种网络访问控制方式,它允许用户使用一组凭证(如用户名和密码)登录一次,然后在多个应用系统间自由切换而无需再次验证身份。CAS(Central Authentication Service)是...
单点登录(Single Sign-On,简称SSO)是一种身份验证机制,允许用户在一次登录后访问多个相互关联的应用系统,而无需再次输入凭证。这种技术极大地提升了用户体验,减少了登录过程中的繁琐步骤,同时也能增强安全性...
SSO(Single Sign-On)单点登录是一种身份验证机制,允许用户在一次登录后访问多个相互关联的应用系统,而无需再次进行身份验证。这一技术在现代企业信息化建设中扮演着重要角色,因为它提供了便捷的用户体验,同时...
单点登录(Single Sign-On,简称SSO)是一种网络应用中的身份验证机制,它允许用户在一次登录后,就可以在多个相互独立的应用系统之间自由切换,而无需再次进行身份验证。这种技术极大地提升了用户体验,同时也简化...
SSO(Single Sign-On)单点登录是一种身份验证机制,允许用户在一次登录后访问多个应用系统,而无需再次输入认证信息。在这个基于Spring Boot、Mybatis和Redis的SSO单点登录系统demo中,我们可以深入理解如何将这些...