From 4aa826bc46a36528efceceab5c5a2ccb76c7cc15 Mon Sep 17 00:00:00 2001 From: jiangjiazhi Date: Tue, 11 Apr 2017 09:51:47 +0800 Subject: [PATCH] add token inteceptor --- .../hospital/inteceptor/TokenValidateInteceptor.java | 17 ++++++++++++++++- .../session/strategy/LocalRedisSessionStrategy.java | 2 -- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/parent/hospital.web/src/main/java/com/lyms/hospital/inteceptor/TokenValidateInteceptor.java b/parent/hospital.web/src/main/java/com/lyms/hospital/inteceptor/TokenValidateInteceptor.java index dc25068..107d47f 100644 --- a/parent/hospital.web/src/main/java/com/lyms/hospital/inteceptor/TokenValidateInteceptor.java +++ b/parent/hospital.web/src/main/java/com/lyms/hospital/inteceptor/TokenValidateInteceptor.java @@ -49,6 +49,14 @@ public class TokenValidateInteceptor extends HandlerInterceptorAdapter return validateToken(request, response); } + /** + * 获取注解 + * + * @param handler HandlerMethod + * @param annotationType annotationType + * @param + * @return annotation + */ private T findAnnotation(HandlerMethod handler, Class annotationType) { T annotation = handler.getBeanType().getAnnotation(annotationType); if (annotation != null) @@ -56,6 +64,13 @@ public class TokenValidateInteceptor extends HandlerInterceptorAdapter return handler.getMethodAnnotation(annotationType); } + /** + * 验证token + * + * @param httpServletRequest + * @param httpServletResponse + * @return + */ public boolean validateToken(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { String token = httpServletRequest.getHeader(Constants.AUTH_HEADER); if (StringUtils.isEmpty(token)) { @@ -66,7 +81,7 @@ public class TokenValidateInteceptor extends HandlerInterceptorAdapter } /** - * This implementation is empty. + * 清空threadlocal的信息. */ @Override public void afterCompletion( diff --git a/parent/hospital.web/src/main/java/com/lyms/hospital/session/strategy/LocalRedisSessionStrategy.java b/parent/hospital.web/src/main/java/com/lyms/hospital/session/strategy/LocalRedisSessionStrategy.java index 919d41a..50f158e 100644 --- a/parent/hospital.web/src/main/java/com/lyms/hospital/session/strategy/LocalRedisSessionStrategy.java +++ b/parent/hospital.web/src/main/java/com/lyms/hospital/session/strategy/LocalRedisSessionStrategy.java @@ -39,8 +39,6 @@ public class LocalRedisSessionStrategy implements ISessionProvider @Autowired private TokenService tokenService; - @Autowired - private UsersService userService; @Override public boolean checkSession(HttpServletRequest request, HttpServletResponse response, String token) -- 1.8.3.1