标签:lan 方式 ISE The 个人 lse turn select 朋友
//登录方法中将token存在redis String token = JwtUtil.sign(userName,user.getId()); redisUtil.set(UserConstants.PREFIX_USER_TOKEN + token, token,UserConstants.TOKEN_EXPIRE_TIME); Map map=new HashMap(); map.put("token", token); return Result.success(map);
//在拦截器中获取token,并判断token的有效期 String token = req.getHeader(UserConstants.ACCESS_TOKEN); if (Strings.isNullOrEmpty(token)) { return false; } Object reqToken=redisUtil.get(UserConstants.PREFIX_USER_TOKEN+token); if (ObjectUtils.isEmpty(reqToken)) { return false; } if(redisUtil.getExpire(UserConstants.PREFIX_USER_TOKEN+token) <1){ return false; } redisUtil.set(UserConstants.PREFIX_USER_TOKEN + token, token,UserConstants.TOKEN_EXPIRE_TIME); return true;
// 生成token String token = JwtUtil.sign(userName,user.getId()); //刷新token,免密登陆 String refToken=UUID.randomUUID().toString().replaceAll("-",""); redisUtil.set(UserConstants.PREFIX_USER_TOKEN + token, refToken,UserConstants.TOKEN_EXPIRE_TIME); Map map=new HashMap(); map.put("token", token); map.put("refToken", refToken); return Result.success(map); //这里在拦截其中校验token,如果校验失败,则判断redis的refToken是否过期 if (!JwtUtil.verify(token)) { if(redisUtil.getExpire(UserConstants.PREFIX_USER_TOKEN+token)>=1){ HttpServletResponse httpServletResponse = (HttpServletResponse) response; String newRefToken=UUID.randomUUID().toString().replaceAll("-",""); Integer userId=Integer.parseInt(JwtUtil.getUserId(token)); User user=userService.selectOne(userId); String newToken=JwtUtil.sign(user.getUserName(),user.getId()); httpServletResponse.setHeader("newToken",newToken); httpServletResponse.setHeader("newRefToken",newRefToken); return true; }else{ return false; } }
这里是登录后返回的token和refToken:
这里是登陆成功之后的显示:
这里是token过期后,refToken刷新的token:
这里是设定的refToken过期后在访问的显示:
标签:lan 方式 ISE The 个人 lse turn select 朋友
原文地址:https://www.cnblogs.com/red-star/p/12577077.html