針對上篇所提的問題
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客戶端持久化的存活期如;至此就解決了不同窗口請求需要再次驗證的問題了。
posted on 2007-11-19 12:58
扭曲的鉛筆 閱讀(2811)
評論(0) 編輯 收藏 所屬分類:
J2EE