##### Coverage Report - com.ctrip.framework.apollo.portal.auth.CtripLogoutHandler

Classes in this File | Line Coverage | Branch Coverage | Complexity
CtripLogoutHandler |
0% | 0/13
N/A | N/A
| 3.0;3

1 |  |
     package com.ctrip.framework.apollo.portal.auth;
2 |  |
3 |  |
     import com.ctrip.framework.apollo.portal.repository.ServerConfigRepository;
4 |  |
5 |  |
     import org.springframework.beans.factory.annotation.Autowired;
6 |  |
7 |  |
     import java.io.IOException;
8 |  |
9 |  |
     import javax.servlet.http.Cookie;
10 |  |
     import javax.servlet.http.HttpServletRequest;
11 |  |
     import javax.servlet.http.HttpServletResponse;
12 |  |
13 | 0 |
     public class CtripLogoutHandler implements LogoutHandler{
14 |  |
15 |  |
       @Autowired
16 |  |
       private ServerConfigRepository serverConfigRepository;
17 |  |
18 |  |
       @Override
19 |  |
       public void logout(HttpServletRequest request, HttpServletResponse response) {
20 |  |
         //将session销毁
21 | 0 |
         request.getSession().invalidate();
22 |  |
23 | 0 |
         Cookie cookie = new Cookie("memCacheAssertionID", null);
24 |  |
         //将cookie的有效期设置为0，命令浏览器删除该cookie
25 | 0 |
         cookie.setMaxAge(0);
26 | 0 |
         cookie.setPath(request.getContextPath() + "/");
27 | 0 |
         response.addCookie(cookie);
28 |  |
29 |  |
         //重定向到SSO的logout地址
30 | 0 |
         String casServerUrl = serverConfigRepository.findByKey("casServerUrlPrefix").getValue();
31 | 0 |
         String serverName = serverConfigRepository.findByKey("serverName").getValue();
32 |  |
33 |  |
         try {
34 | 0 |
           response.sendRedirect(casServerUrl + "/logout?service=" + serverName);
35 | 0 |
         } catch (IOException e) {
36 | 0 |
           throw new RuntimeException(e);
37 | 0 |
         }
38 | 0 |
       }
39 |  |
     }