JWT的TOKEN续期功能

更新时间:2023-06-25 18:40:22 阅读: 评论:0

JWT的TOKEN续期功能
JWT⾥有⼀个关键的东东,就是续期TOKEN,即TOKEN快过期时,刷新⼀个新的TOKEN给客户端.
办法如下:
1.后端⽣成TOKEN
import del.SecurityUr;
import del.UrLoginToken;
import shiro.util.JWTUtil;
import s.lang3.BooleanUtils;
import s.lang3.StringUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
import org.apache.shiro.web.util.WebUtils;
import org.slf4j.Logger;
cf特殊符号import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.rvlet.ServletRequest;
import javax.rvlet.ServletRespon;
陆机文赋
import javax.rvlet.http.HttpServletRequest;
import javax.rvlet.http.HttpServletRespon;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.Objects;
public class JwtAuthFilter extends AuthenticatingFilter {
private final Logger log = Logger(JwtAuthFilter.class);
//10分钟后刷新token
private static final int tokenRefreshInterval = 60 * 10;
@Override
protected boolean preHandle(ServletRequest request, ServletRespon respon) throws Exception {
HttpServletRequest httpServletRequest = Http(request);
if (Method().equals(RequestMethod.OPTIONS.name())) //对于OPTION请求做拦截,不做token校验            return fal;
return super.preHandle(request, respon);
}
@Override
protected void postHandle(ServletRequest request, ServletRespon respon) {
request.tAttribute("jwtShiroFilter.FILTERED", true);
}
云天海温泉@Override
protected boolean isAccessAllowed(ServletRequest request, ServletRespon respon, Object mappedValue) {
if (this.isLoginRequest(request, respon)) {
return true;
}
Boolean afterFiltered = (Boolean) (Attribute("jwtShiroFilter.FILTERED"));
if (BooleanUtils.isTrue(afterFiltered))
return true;
boolean allowed = fal;
try {
温州旅游景点哪里好玩allowed = executeLogin(request, respon);
} catch (IllegalStateException e) { //not found any token
<("Not found any token");
} catch (Exception e) {
<("Error occurs when login", e);
}
return allowed || super.isPermissive(mappedValue);
}
@Override
// 拦截响应respon,并做⼀些错误处理
spon.u((respon) => {
if(respon.status ===200 && respon.data && de === 401) {英语自荐信
//console.log(igin);
window.location.href=igin+window.location.pathname+'#/login';
}
//获取返回的TOKEN
const token=respon.headers['x-auth-token'];
if(token) {
//将续期的TOKEN存起来
localStorage.tItem("token",token) ;
}
// 这⾥是填写处理信息
return respon;
}, (err) => { // 这⾥是返回状态码不为200时候的错误处理
console.log(err);
if(err && spon) {
de) {
ca 400:
break;
ca 401:
break;
ca 403:
break;
ca 404:
break;
ca 408:
break;
古代爱国人士s开头的形容词
ca 500:
break;
ca 501:
break;
ca 502:
十以内的加减法
break;
ca 503:
break;
ca 504:
break;
ca 505:
break;
default:
}
}
Vue.prototype.$(spon.data.msg!=spon.data.ssage);    ject(err)
});

本文发布于:2023-06-25 18:40:22,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1054650.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:请求   续期   服务
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图