流程中心-各分页列表调整。

用户token失效返回信息处理。
This commit is contained in:
wangzhijiang
2022-03-08 18:32:07 +08:00
parent 7a87cc72fd
commit eac73fc32c
5 changed files with 109 additions and 39 deletions
@@ -1,6 +1,8 @@
package com.jero.config.shiro;
import cn.hutool.crypto.SecureUtil;
import com.google.gson.Gson;
import com.jero.common.api.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
@@ -18,10 +20,14 @@ import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.RedisUtil;
import com.jero.common.util.SpringContextUtils;
import com.jero.common.util.oConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Set;
/**
@@ -41,6 +47,9 @@ public class ShiroRealm extends AuthorizingRealm {
@Resource
private RedisUtil redisUtil;
@Autowired
private HttpServletResponse response;
/**
* 必须重写此方法,不然Shiro会报错
*/
@@ -124,6 +133,25 @@ public class ShiroRealm extends AuthorizingRealm {
}
// 校验token是否超时失效 & 或者账号密码是否错误
if (!jwtTokenRefresh(token, username, loginUser.getPassword())) {
String reponseJson = new Gson().toJson(Result.error(401,"Token失效,请重新登录!"));
response.setContentType("application/json; charset=utf-8");
response.setCharacterEncoding("utf-8");
OutputStream out = null;
try {
out = response.getOutputStream();
out.write(reponseJson.getBytes());
}catch (IOException ex){
ex.printStackTrace();
}finally {
if(out != null){
try {
out.close();
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
throw new AuthenticationException("Token失效,请重新登录!");
}