CAS SSO配置(下)

针对上篇所提的问题
1:假设有A、B两个应用程式,现在在浏览器窗口1输入对A应用程式的请求,会跳转到cas login窗口身份验证;身份验证完成后跳转会A应用程式请求页面
2:在窗口2输入对B应用程式请求,还会需要身份验证
3:在窗口1修改URL为对B应用程式的请求,不需求身份验证
首先为什么在同一个窗口修改URL就可以对B应用程式请求而不需要身份验证
通过查看edu.yale.its.tp.cas.client.filter.CASFilter源码可以发现有这么一段
        HttpSession session = ((HttpServletRequest) request).getSession();

        // if our attribute's already present and valid, pass through the filter chain
        CASReceipt receipt = (CASReceipt) session.getAttribute(CAS_FILTER_RECEIPT);
        if (receipt != null && isReceiptAcceptable(receipt)) {
                log.trace("CAS_FILTER_RECEIPT attribute was present and acceptable - passing  request through filter..");
            fc.doFilter(request, response);
            return;
        }就是说如果在session里已存在有效的CASRecipt就不再需要身份验证。
那如何解决不同窗口的问题;通过查看CAS SSO原理可以发现,当CAS SERVER验证通过后向client传递ST的时候也同时向USER浏览器里传递一个TGC cookies;初步判定是因为找不到这个cookies导致的问题。具体SSO原理可看“SSO原理”这篇文章
查找cookies:在cas server的cas-servlet.xml里
    <bean id="ticketGrantingTicketCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
        p:cookieSecure="true"
        p:cookieMaxAge="-1"
        p:cookieName="CASTGC"
        p:cookiePath="/cas" />这是传送cookies到user端的bean,其中cookieMaxAge的意思是:Use the given maximum age (in seconds) for cookies created by this generator. Useful special value: -1 ... not persistent, deleted when client shuts down(没持久化)
cooliePath的意思:Use the given path for cookies created by this generator. The cookie is only visible to URLs in this path and below.
摘至:spring api
因此通过修改cookieMaxAge的值控制cookies在User客户端持久化的存活期如;至此就解决了不同窗口请求需要再次验证的问题了。

猜你喜欢

转载自zhangpurple.iteye.com/blog/1815652