SSO学习笔记

参考构建和实现单点登录解决方案

安全的CAS验证过程

1、用户通过应用系统A的URL访问应用系统A。

2、应用系统A发现此用户尚未登录,于是重定向至认证服务器CAS,此次连接采用HTTPS。

3、用户在该页面上输入用户名和密码,发送至认证服务器CAS。

4、如果用户名及密码正确,认证服务器CAS会生成一个内存cookie(ticket-granting cookie,简称TGC)。该cookie在浏览器关闭之后就会失效。

5、认证服务器CAS会重定向至应用系统A,并在URL中附加一个称为 ticket (service ticket,简称ST)的参数。

6、应用系统A接收到此ticket参数之后,向认证服务器CAS发送一个请求,要求验证此ticket是否有效。

7、认证服务器CAS接收到应用系统A的请求之后,如果发现该ticket有效,则将用户信息返回给应用系统A。并将此ticket失效。

8、应用系统A接收到认证服务器CAS返回的用户信息之后允许用户访问该系统,并将用户信息保存在session中。


用户再访问应用系统A的其他功能时,由于应用系统A中已经有该用户的登录信息,不需要再访问认证服务器CAS。

如果用户访问应用系统B的话,由于系统B中没有该用户的登录信息,于是重定向认证服务器CAS,

由于浏览器中已经有ticket-granting cookie,所以不需要重新输入用户名和密码。

然后重复上述第5步至第8步


由于TGC的传输采用HTTPS,所以基本上不用考虑TGC在网络上传输时被泄漏的问题。

而ST,虽然使用HTTP传输,但是仅一次有效,除非黑客能在窃取到此ST之后,能抢在用户之前,用该ST访问应用系统A,否则也是安全的。


How to configure Tomcat to always require HTTPS

First, make sure that you have configured and enabled both the HTTP and HTTPS elements in your conf/server.xml file:

    <Connector port="8080" protocol="HTTP/1.1" 
               redirectPort="443"/>

    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               keystoreFile="conf/keystore" keystorePass="s00perSeeekrit"/>


For details on how to prepare your conf/keystore file, see http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html


Restart Tomcat and test both of these connectors, making sure that you can access your web application via either connector before you proceed. Next, edit your webapp's WEB-INF/web.xml file and add the following inside of your container element:


    <!-- Require HTTPS for everything except /img (favicon) and /css. -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>HTTPSOnly</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>HTTPSOrHTTP</web-resource-name>
            <url-pattern>*.ico</url-pattern>
            <url-pattern>/img/*</url-pattern>
            <url-pattern>/css/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
    </security-constraint>


This configuration declares that the entire webapp is meant to be HTTPS only, and the container should intercept HTTP requests for it and redirect those to the equivalent "https://" URL. The exception is certain requests having URL patterns that match the "HTTPSOrHTTP" web resource collection, in which case the requests will be served through the protocol the request came in on, either HTTP or HTTPS.


Lastly, restart your webapp (or Tomcat). It should now redirect HTTP requests to HTTPS, and it should serve the webapp via HTTPS only.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值