CAS logout的时候,默认是会重定向到cas server端的logout页面。
现在的需求是重定向到登录页面。
在应用中, 我还遇到直接ogout(只做清空session, cookie), 而不去重定向到cas 的logout页面,这种情况下:
如果不关闭浏览器, 直接再次输入Application的URL, 会绕过CAS认证,照常登入。
吃问题困扰了几天,看了一下CASserver端的代码,恍然大悟:
LogoutController有一个开关变量:
- privatebooleanfollowServiceRedirects;
并有一段逻辑:
- if(this.followServiceRedirects && service !=null) {
- returnnewModelAndView(newRedirectView(service));
- }
service是个啥:
- finalString service = request.getParameter("service");
如果在logout的url后面加上你要重定向的那个页面, 就可以自定义登出页面了:
所以,我的方案就出来了:
在cas-servlet.xml中,设置logoutController的followServiceRedirects=true
- <beanid="logoutController"class="org.jasig.cas.web.LogoutController"
- p:centralAuthenticationService-ref="centralAuthenticationService"
- p:logoutView="casLogoutView"
- p:warnCookieGenerator-ref="warnCookieGenerator"
- p:ticketGrantingTicketCookieGenerator-ref="ticketGrantingTicketCookieGenerator"
- p:followServiceRedirects="true"/>
application在登出的时候,除了清空session和cookie外, 重定向的url加上:
- var apphostname = window.location.hostname
- var appport = window.location.port;
- var callbackurl='?service=http%3A%2F%2F'+apphostname +'%3A'+appport +'%2Fapplication'
- window.location = logoutUrl+ callbackurl;
版权声明:本文为haochunting1984原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。