ソースを参照

ServletUtil 更新获取 cookie 和 bearer token 的方法

reghao 2 年 前
コミット
6adc458268
1 ファイル変更17 行追加1 行削除
  1. 17 1
      web/src/main/java/cn/reghao/jutil/web/ServletUtil.java

+ 17 - 1
web/src/main/java/cn/reghao/jutil/web/ServletUtil.java

@@ -5,18 +5,34 @@ import org.springframework.util.StringUtils;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
+import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @author reghao
  * @date 2021-06-02 13:16:58
  */
 public class ServletUtil {
-    public static String getJwtToken() {
+    public static Map<String, String> getCookies(HttpServletRequest request) {
+        Cookie[] cookies = request.getCookies();
+        Map<String, String> map = new HashMap<>();
+        if (cookies != null) {
+            for (Cookie cookie : cookies) {
+                String name = cookie.getName();
+                String value = cookie.getValue();
+                map.put(name, value);
+            }
+        }
+        return map;
+    }
+
+    public static String getBearerToken() {
         String auth = getRequest().getHeader("Authorization");
         if (auth == null) {
             return null;