首页>代码>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  LV26 2021年6月22日
chenmin77527  LV3 2021年6月19日
最近浏览更多
dapeng0011  LV15 2024年7月13日
gowangbo1  LV6 2024年6月29日
计科一班  LV7 2024年6月19日
quartz  LV8 2024年3月13日
周宗营  LV1 2024年2月29日
云淡风轻jh  LV10 2023年9月3日
shaoqi 2023年7月26日
暂无贡献等级
240598911  LV10 2023年7月6日
szf123  LV12 2023年6月5日
yzshabzbbdvw  LV4 2023年6月3日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友