|
|
@@ -1,10 +1,12 @@
|
|
|
package com.uas.sso.controller;
|
|
|
|
|
|
+import com.uas.sso.SSOConfig;
|
|
|
import com.uas.sso.SSOHelper;
|
|
|
import com.uas.sso.SSOToken;
|
|
|
import com.uas.sso.common.util.HttpUtil;
|
|
|
import com.uas.sso.entity.App;
|
|
|
import com.uas.sso.service.AppService;
|
|
|
+import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
@@ -13,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.servlet.http.Cookie;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
@@ -71,6 +75,14 @@ public class LogoutController extends BaseController {
|
|
|
modelMap.addAttribute("appId", appId);
|
|
|
modelMap.addAttribute("logoutUrls", getOtherLogoutUrls(baseUrl));
|
|
|
|
|
|
+ // 账号服务退出
|
|
|
+ String ssoToken = getToken(request, "token");
|
|
|
+ Cookie ssoTokenCookie = new Cookie("token", ssoToken);
|
|
|
+ ssoTokenCookie.setPath("/");
|
|
|
+ ssoTokenCookie.setMaxAge(0);
|
|
|
+ ssoTokenCookie.setDomain(SSOConfig.getInstance().getCookieDomain());
|
|
|
+ response.addCookie(ssoTokenCookie);
|
|
|
+
|
|
|
if (token != null) {
|
|
|
SSOHelper.clearLogin(request, response);
|
|
|
}
|
|
|
@@ -88,4 +100,18 @@ public class LogoutController extends BaseController {
|
|
|
logoutUrls.add(baseUrl);
|
|
|
return logoutUrls;
|
|
|
}
|
|
|
+
|
|
|
+ private String getToken(HttpServletRequest request, String tokenName) {
|
|
|
+ Cookie[] cookies = request.getCookies();
|
|
|
+ String token = "";
|
|
|
+ if (ArrayUtils.isNotEmpty(cookies)) {
|
|
|
+ for (Cookie cookie : cookies) {
|
|
|
+ if (cookie.getName().equals(tokenName)) {
|
|
|
+ token = cookie.getValue();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return token;
|
|
|
+ }
|
|
|
}
|