We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.40.0
在开启从 Cookie 读取 Token 的开关 (is-read-cookie: true) 后, 后端 jsp 直接访问报错:
is-read-cookie: true
cn.dev33.satoken.exception.NotLoginException: 未按照指定前缀提交 token,prefix=Bearer at cn.dev33.satoken.exception.NotLoginException.newInstance(NotLoginException.java:134) at cn.dev33.satoken.stp.StpLogic.getTokenValue(StpLogic.java:306) at cn.dev33.satoken.stp.StpLogic.getLoginId(StpLogic.java:964) at cn.dev33.satoken.stp.StpLogic.checkLogin(StpLogic.java:948) at cn.dev33.satoken.stp.StpUtil.checkLogin(StpUtil.java:341)
StpLogic.java 第 303 行
if (noPrefixThrowException) { throw NotLoginException.newInstance(loginType, NO_PREFIX, NO_PREFIX_MESSAGE + ",prefix=" + tokenPrefix, null).setCode(SaErrorCode.CODE_11017); } else { tokenValue = null; }
修改为
if (noPrefixThrowException) { // 从 cookie 获取的值是不带前缀的,不需要抛异常 if (!getConfigOrGlobal().getIsReadCookie()) { throw NotLoginException.newInstance(loginType, NO_PREFIX, NO_PREFIX_MESSAGE + ",prefix=" + tokenPrefix, null).setCode(SaErrorCode.CODE_11017); } } else { tokenValue = null; }
sa-token: token-prefix: Bearer token-name: Authorization is-read-cookie: true
public void setTokenValueToCookie(String tokenValue, int cookieTimeout){ SaCookieConfig cfg = getConfigOrGlobal().getCookie(); String tokenPrefix = getConfigOrGlobal().getTokenPrefix(); String cookieValue; if(SaFoxUtil.isEmpty(tokenPrefix) ) { // - 如果没有配置前缀模式,直接保存 cookieValue = tokenValue; } else { // - 如果配置了前缀模式,则拼接上前缀保存 cookieValue = tokenPrefix + SaTokenConsts.TOKEN_CONNECTOR_CHAT + tokenValue; } SaCookie cookie = new SaCookie() .setName(getTokenName()) .setValue(cookieValue) .setMaxAge(cookieTimeout) .setDomain(cfg.getDomain()) .setPath(cfg.getPath()) .setSecure(cfg.getSecure()) .setHttpOnly(cfg.getHttpOnly()) .setSameSite(cfg.getSameSite()) .setExtraAttrs(cfg.getExtraAttrs()) ; SaHolder.getResponse().addCookie(cookie); }
request.getCookies()
Authorization
request.getHeader("Cookie")
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getCookies();
The text was updated successfully, but these errors were encountered:
参考:
Sorry, something went wrong.
No branches or pull requests
使用版本:
1.40.0
报错信息:
在开启从 Cookie 读取 Token 的开关 (
is-read-cookie: true
) 后, 后端 jsp 直接访问报错:希望结果:
StpLogic.java 第 303 行
修改为
复现步骤:
request.getCookies()
无法获取名称为Authorization
的 Cookie,但是request.getHeader("Cookie")
中有The text was updated successfully, but these errors were encountered: