首页>代码>Spring Boot通过JWT认证协议实现SSO单点登录系统>/springboot-single-sign-on-jwt/auth-service/src/main/java/com/hellokoding/sso/auth/CookieUtil.java
package com.hellokoding.sso.auth;
import org.springframework.web.util.WebUtils;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CookieUtil {
public static void create(HttpServletResponse httpServletResponse, String name, String value, Boolean secure, Integer maxAge, String domain) {
Cookie cookie = new Cookie(name, value);
cookie.setSecure(secure);
cookie.setHttpOnly(true);
cookie.setMaxAge(maxAge);
cookie.setDomain(domain);
cookie.setPath("/");
httpServletResponse.addCookie(cookie);
}
public static void clear(HttpServletResponse httpServletResponse, String name) {
Cookie cookie = new Cookie(name, null);
cookie.setPath("/");
cookie.setHttpOnly(true);
cookie.setMaxAge(0);
httpServletResponse.addCookie(cookie);
}
public static String getValue(HttpServletRequest httpServletRequest, String name) {
Cookie cookie = WebUtils.getCookie(httpServletRequest, name);
return cookie != null ? cookie.getValue() : null;
}
}
最近下载更多
gowangbo1 LV6
2024年6月29日
zackery LV9
2024年1月27日
神剑幽灵 LV11
2022年8月9日
wusiyin LV14
2022年7月18日
1234mama LV19
2022年6月7日
a1677596408 LV23
2022年3月28日
zhaoming200677 LV13
2021年10月21日
天险无涯 LV15
2021年10月14日
C544350851 LV27
2021年6月22日
chenmin77527 LV3
2021年6月19日

最近浏览