单点登出基本上没有啥配置

直接在原来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后,最终会停留在这个页面上

单点登录CAS使用记(六):单点登出、单点注销-LMLPHP

一般这不是我们想要的。

我想要的是,一旦用户登出,重新回到登录页面。

那么重新修改原有项目的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使用记系列:

04-25 07:55