Commit c3a5aa34 authored by zengtianlai3's avatar zengtianlai3

token失效

parent 5543af64
......@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
......@@ -71,7 +72,7 @@ public class LoginController {
@GetMapping("fail")
@ApiIgnore
public ResResult fail() {
return ResResult.fail().msg("认证信息非法");
public ResResult fail(HttpServletRequest request) {
return ResResult.fail().msg(request.getAttribute("msg").toString());
}
}
......@@ -55,27 +55,25 @@ public class JwtFilter implements Filter {
}
if (token == null) {
String resultStr = JSON.toJSONString(ResResult.fail().msg("认证信息不能为空"));
response.getWriter().write(resultStr);
request.setAttribute("msg","认证信息不能为空");
request.getRequestDispatcher("/fail").forward(request, response);
return;
} else {
DecodedJWT jwt = JwtUtil.verifyToken(token);
if (jwt == null) {
request.setAttribute("msg","认证信息非法");
request.getRequestDispatcher("/fail").forward(request, response);
return;
} else {
Map<String, Claim> userData = jwt.getClaims();
if (userData == null) {
String resultStr = JSON.toJSONString(ResResult.fail().msg("认证信息非法"));
response.getWriter().write(resultStr);
request.setAttribute("msg","认证信息非法");
request.getRequestDispatcher("/fail").forward(request, response);
return;
}
String userId = userData.get("userId").asString();
String userName = userData.get("userName").asString();
String password = userData.get("password").asString();
// //拦截器 拿到用户信息,放到request中
// request.setAttribute("userName", userName);
// request.setAttribute("password", password);
LoginUser loginUser = new LoginUser(userId, userName, password);
UserUtils.setLoginUser(loginUser);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment