parent
4ea837da0a
commit
6d17e72cc0
@ -1,126 +0,0 @@
|
||||
package com.dsideal.resource.Util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jfinal.kit.HttpKit;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class SsoUtil {
|
||||
|
||||
public static String getSessionIdByCookie(HttpServletRequest request, String sessionid) {
|
||||
String cookieSessionId = getCookieValue(request, sessionid);
|
||||
return cookieSessionId;
|
||||
}
|
||||
|
||||
public static Map loginCheck(String sessionId, String ssoServerAddr) {
|
||||
if (sessionId != null) {
|
||||
return getLoginMap(sessionId, ssoServerAddr);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除dss_sso_sessionid的cookie
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
public static void removeSessionIdInCookie(HttpServletRequest request, HttpServletResponse response) {
|
||||
Cookie[] arrCookie = request.getCookies();
|
||||
if (arrCookie != null && arrCookie.length > 0) {
|
||||
for (Cookie cookie : arrCookie) {
|
||||
removeCookie(request, response, cookie.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 将map写入cookie
|
||||
*
|
||||
* @param response
|
||||
* @param map
|
||||
*/
|
||||
public static void setCookieMap(HttpServletResponse response, Map map) {
|
||||
Iterator iter = map.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) iter.next();
|
||||
String key = entry.getKey().toString();
|
||||
String val = entry.getValue().toString();
|
||||
setCookie(response, key, val, null, "/", -1, true);
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeCookie(HttpServletRequest request, HttpServletResponse response, String key) {
|
||||
Cookie cookie = getCookie(request, key);
|
||||
if (cookie != null) {
|
||||
setCookie(response, key, "", null, "/", 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setCookie(HttpServletResponse response, String key, String value, String domain, String path, int maxAge, boolean isHttpOnly) {
|
||||
Cookie cookie = new Cookie(key, value);
|
||||
if (domain != null) {
|
||||
cookie.setDomain(domain);
|
||||
}
|
||||
cookie.setPath(path);
|
||||
cookie.setMaxAge(maxAge);
|
||||
//cookie.setHttpOnly(isHttpOnly);
|
||||
response.addCookie(cookie);
|
||||
}
|
||||
|
||||
public static String getCookieValue(HttpServletRequest request, String key) {
|
||||
Cookie cookie = getCookie(request, key);
|
||||
if (cookie != null) {
|
||||
return cookie.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Cookie getCookie(HttpServletRequest request, String key) {
|
||||
Cookie[] arr_cookie = request.getCookies();
|
||||
if (arr_cookie != null && arr_cookie.length > 0) {
|
||||
for (Cookie cookie : arr_cookie) {
|
||||
if (cookie.getName().equals(key)) {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Map getLoginMap(String sessionId, String ssoServerAddr) {
|
||||
|
||||
Map loginMap = new HashMap();
|
||||
try {
|
||||
String ssoServerUrl = ssoServerAddr + "/app/loginCheck";
|
||||
Map ssoServerUrlParams = new HashMap();
|
||||
ssoServerUrlParams.put("sessionId", sessionId);
|
||||
String strJson = HttpKit.get(ssoServerUrl, ssoServerUrlParams);
|
||||
JSONObject objJson = JSONObject.parseObject(strJson);
|
||||
if (objJson.getBoolean("success")) {
|
||||
loginMap.put("person_id", objJson.getString("personId"));
|
||||
loginMap.put("bureau_id", objJson.getString("bureauId"));
|
||||
loginMap.put("identity_id", objJson.getString("identityId"));
|
||||
loginMap.put("city_id", objJson.getString("city_id"));
|
||||
loginMap.put("area_id", objJson.getString("area_id"));
|
||||
loginMap.put("main_person_id", objJson.getString("mainPersonId"));
|
||||
} else {
|
||||
loginMap = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
loginMap = null;
|
||||
e.printStackTrace();
|
||||
}
|
||||
return loginMap;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
31916
|
||||
23588
|
||||
|
Loading…
Reference in new issue