首页>代码>Spring Boot通过JWT认证协议实现SSO单点登录系统>/springboot-single-sign-on-jwt/resources-service/src/main/java/com/hellokoding/sso/resource/CookieUtil.java
package com.hellokoding.sso.resource;

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);
        cookie.setDomain("localhost");
        httpServletResponse.addCookie(cookie);
    }

    public static String getValue(HttpServletRequest httpServletRequest, String name) {
        Cookie cookie = WebUtils.getCookie(httpServletRequest, name);
        return cookie != null ? cookie.getValue() : null;
    }
}

最近下载更多
zackery  LV9 1月27日
神剑幽灵  LV11 2022年8月9日
wusiyin  LV14 2022年7月18日
1234mama  LV19 2022年6月7日
a1677596408  LV23 2022年3月28日
zhaoming200677  LV12 2021年10月21日
天险无涯  LV15 2021年10月14日
C544350851  LV26 2021年6月22日
chenmin77527  LV3 2021年6月19日
000000msj  LV2 2021年6月3日
最近浏览更多
quartz  LV7 3月13日
周宗营  LV1 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日
lxdcode  LV1 2023年5月4日
123xyz  LV2 2023年4月14日
科技家  LV2 2023年4月7日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友