This commit is contained in:
ly19960718 2021-01-28 17:31:15 +08:00
parent c7212662b1
commit 871ba27ca9

View File

@ -6,6 +6,7 @@ import cn.com.tenlion.pojo.dtos.carduser.CardUserDTO;
import cn.com.tenlion.pojo.vos.carduser.CardUserVO;
import cn.com.tenlion.service.carduser.ICardUserService;
import cn.com.tenlion.util.AesUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -15,6 +16,7 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
* TODO
@ -23,7 +25,7 @@ import java.io.IOException;
* @date 2021/1/27 12:20
*/
@Component
public class CheckAuth implements HandlerInterceptor {
public class CheckAuthInterceptor implements HandlerInterceptor {
@Autowired
private ICardUserService cardUserService;
@ -38,19 +40,26 @@ public class CheckAuth implements HandlerInterceptor {
if(path.contains("release")){
return true;
}
String token = request.getHeader("token");
if(token == null || StringUtil.isEmpty(token)){
// response.setStatus(response.SC_METHOD_NOT_ALLOWED);
// response.addHeader("msg","token不合法");
response.sendError(response.SC_METHOD_NOT_ALLOWED,"token不合法");
response.setStatus(response.SC_UNAUTHORIZED);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
JSONObject res = new JSONObject();
res.put("status","401");
res.put("msg","token不合法");
PrintWriter out = null ;
out = response.getWriter();
out.write(res.toString());
out.flush();
out.close();
return false;
}
CardUserDTO tokenManage = AccessTokenManager.getInstance().getKey(token);
if(tokenManage != null) {
AccessTokenManager.getInstance().updateLastActivityTime(token);
response.setStatus(response.SC_OK);
return true;
}else{
String aesDecoderToken = AesUtil.aesCommonDecoder(token,token);
@ -58,9 +67,10 @@ public class CheckAuth implements HandlerInterceptor {
if(cardUserDTO != null){
AccessTokenManager.getInstance().setKey(token,cardUserDTO);
AccessTokenManager.getInstance().updateLastActivityTime(token);
}
}
response.setStatus(response.SC_OK);
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
}