1
This commit is contained in:
parent
c7212662b1
commit
871ba27ca9
@ -6,6 +6,7 @@ import cn.com.tenlion.pojo.dtos.carduser.CardUserDTO;
|
|||||||
import cn.com.tenlion.pojo.vos.carduser.CardUserVO;
|
import cn.com.tenlion.pojo.vos.carduser.CardUserVO;
|
||||||
import cn.com.tenlion.service.carduser.ICardUserService;
|
import cn.com.tenlion.service.carduser.ICardUserService;
|
||||||
import cn.com.tenlion.util.AesUtil;
|
import cn.com.tenlion.util.AesUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.github.pagehelper.util.StringUtil;
|
import com.github.pagehelper.util.StringUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -15,6 +16,7 @@ import org.springframework.web.servlet.ModelAndView;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
@ -23,7 +25,7 @@ import java.io.IOException;
|
|||||||
* @date 2021/1/27 12:20
|
* @date 2021/1/27 12:20
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class CheckAuth implements HandlerInterceptor {
|
public class CheckAuthInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ICardUserService cardUserService;
|
private ICardUserService cardUserService;
|
||||||
@ -38,19 +40,26 @@ public class CheckAuth implements HandlerInterceptor {
|
|||||||
if(path.contains("release")){
|
if(path.contains("release")){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String token = request.getHeader("token");
|
String token = request.getHeader("token");
|
||||||
if(token == null || StringUtil.isEmpty(token)){
|
if(token == null || StringUtil.isEmpty(token)){
|
||||||
// response.setStatus(response.SC_METHOD_NOT_ALLOWED);
|
response.setStatus(response.SC_UNAUTHORIZED);
|
||||||
// response.addHeader("msg","token不合法");
|
response.setCharacterEncoding("UTF-8");
|
||||||
response.sendError(response.SC_METHOD_NOT_ALLOWED,"token不合法");
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardUserDTO tokenManage = AccessTokenManager.getInstance().getKey(token);
|
CardUserDTO tokenManage = AccessTokenManager.getInstance().getKey(token);
|
||||||
if(tokenManage != null) {
|
if(tokenManage != null) {
|
||||||
AccessTokenManager.getInstance().updateLastActivityTime(token);
|
AccessTokenManager.getInstance().updateLastActivityTime(token);
|
||||||
|
response.setStatus(response.SC_OK);
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
String aesDecoderToken = AesUtil.aesCommonDecoder(token,token);
|
String aesDecoderToken = AesUtil.aesCommonDecoder(token,token);
|
||||||
@ -58,9 +67,10 @@ public class CheckAuth implements HandlerInterceptor {
|
|||||||
if(cardUserDTO != null){
|
if(cardUserDTO != null){
|
||||||
AccessTokenManager.getInstance().setKey(token,cardUserDTO);
|
AccessTokenManager.getInstance().setKey(token,cardUserDTO);
|
||||||
AccessTokenManager.getInstance().updateLastActivityTime(token);
|
AccessTokenManager.getInstance().updateLastActivityTime(token);
|
||||||
|
response.setStatus(response.SC_OK);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response.setStatus(response.SC_OK);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user