首页>代码>spring boot整合freemaker开发医院管理系统>/hospital/src/main/java/com/gbq/hospital/config/shiro/MySessionManager.java
package com.gbq.hospital.config.shiro;

import com.github.pagehelper.util.StringUtil;
import org.apache.shiro.web.servlet.ShiroHttpServletRequest;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * @author Morty
 */
public class MySessionManager extends DefaultWebSessionManager {

    public static final String AUTHORIZATION = "token";

    public static final String REFERENCED_SESSION_ID_SOURCE = "Stateless request";

    public MySessionManager() {
        super();
    }

    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        String sessionId = httpServletRequest.getHeader(AUTHORIZATION);
        //如果请求头中有 Authorization 则其值为sessionId
        if (StringUtil.isNotEmpty(sessionId)) {
            request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE, REFERENCED_SESSION_ID_SOURCE);
            request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID, sessionId);
            request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_IS_VALID, Boolean.TRUE);
            return sessionId;
        } else {
            //否则按默认规则从cookie取sessionId
            return super.getSessionId(request, response);
        }

    }
}
最近下载更多
zjjhzjb  LV15 4月16日
微信网友_7134912998903808  LV15 2024年9月11日
jiyun2021  LV9 2024年7月15日
FF加菲猫  LV4 2024年2月15日
woshiwo  LV3 2024年1月17日
xuyang1991  LV2 2023年12月26日
adaddad  LV2 2023年11月11日
skook7  LV2 2023年8月31日
LYLHYC  LV5 2023年8月2日
五折也挺好的  LV13 2023年7月10日
最近浏览更多
denliv_hui  LV14 8月7日
zjb243665659  LV7 4月16日
zjjhzjb  LV15 4月16日
TaoTaot 4月7日
暂无贡献等级
blanknb 3月18日
暂无贡献等级
abdkfksdkf  LV16 2月23日
zhihou  LV2 2月6日
2602275348  LV12 1月6日
暂无贡献等级
WHY-small  LV15 2024年12月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友