單點登出基本上沒有啥配置
直接在原來logout的時候,重定向到Cas-Server的logout方法
@RequestSecurity @RequestMapping(value = "loginout", method = { RequestMethod.GET, RequestMethod.POST }) public String loginout(HttpSession session) { session.invalidate(); return "redirect:https://demo.testcas.com/cas-server/logout"; }
但是這樣的話,logout后,最終會停留在這個頁面上
一般這不是我們想要的。
我想要的是,一旦用戶登出,重新回到登錄頁面。
那么重新修改原有項目的logout方法,如下:
@RequestSecurity @RequestMapping(value = "loginout", method = { RequestMethod.GET, RequestMethod.POST }) public String loginout(HttpSession session) { session.invalidate(); return "redirect:https://demo.testcas.com/cas-server/logout?service=https://demo.testcas.com/cas-server/login"; }
加上了一個Service后綴,並且指定了一個URL,意思是成功logout后,想要回到哪個頁面。
然后,在Cas-Server項目的cas-servlet.xml中,找到
<bean id="logoutController" class="org.jasig.cas.web.LogoutController" p:centralAuthenticationService-ref="centralAuthenticationService" p:logoutView="casLogoutView" p:followServiceRedirects="true" p:warnCookieGenerator-ref="warnCookieGenerator" p:ticketGrantingTicketCookieGenerator-ref="ticketGrantingTicketCookieGenerator" />
加上這么一個屬性: p:followServiceRedirects="true"
意思是:成功Logout后,如果包含Service參數,則重定向到Service指定的網址。
單點登錄CAS使用記系列:
-
單點登錄CAS使用記(一):前期准備以及為CAS-Server配置SSL協議
-
單點登錄CAS使用記(二):部署CAS服務器以及客戶端
-
單點登錄CAS使用記(三):實現自定義驗證用戶登錄
-
單點登錄CAS使用記(四):為登錄頁面加上驗證碼
-
單點登錄CAS使用記(五):cas-client不攔截靜態資源以及無需登錄的請求。
-
單點登錄CAS使用記(六):單點登出、單點注銷
-
單點登錄CAS使用記(七):關於服務器超時以及客戶端超時的分析
-
單點登錄CAS使用記(八):使用maven的overlay實現無侵入的改造CAS