單點登陸CAS使用記(六):單點登出、單點註銷

單點登出基本上沒有啥配置html

直接在原來logout的時候,重定向到Cas-Server的logout方法web

    @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後,最終會停留在這個頁面上服務器

通常這不是咱們想要的。session

我想要的是,一旦用戶登出,從新回到登陸頁面。app

那麼從新修改原有項目的logout方法,以下:maven

    @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後,想要回到哪一個頁面。spa

而後,在Cas-Server項目的cas-servlet.xml中,找到code

    <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"server

意思是:成功Logout後,若是包含Service參數,則重定向到Service指定的網址。xml

 

 


單點登陸CAS使用記系列:

相關文章
相關標籤/搜索