|
|
@@ -27,23 +27,27 @@ public class AuthRestInterceptor extends HandlerInterceptorAdapter {
|
|
|
|
|
|
@Override
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
|
- HandlerMethod handlerMethod = (HandlerMethod) handler;
|
|
|
- // 配置该注解,说明不进行用户拦截
|
|
|
- IgnoreAuth annotation = handlerMethod.getBeanType().getAnnotation(IgnoreAuth.class);
|
|
|
- if (annotation == null) {
|
|
|
- annotation = handlerMethod.getMethodAnnotation(IgnoreAuth.class);
|
|
|
- }
|
|
|
- if (annotation != null) {
|
|
|
- return super.preHandle(request, response, handler);
|
|
|
- }
|
|
|
- String token = request.getHeader(authConfig.getAuthHeader());
|
|
|
- if (null != token) {
|
|
|
- JwtInfo infoFromToken = JwtHelper.getInfoFromToken(token, authConfig.getPublicKey());
|
|
|
- BaseContextHolder.setAppId(infoFromToken.getAppId());
|
|
|
- BaseContextHolder.setUserId(infoFromToken.getUserId());
|
|
|
- BaseContextHolder.setCompanyId(infoFromToken.getCompanyId());
|
|
|
- BaseContextHolder.setToken(token);
|
|
|
- log.info("token={} \\r\\n userName={}", token, infoFromToken.getUserName());
|
|
|
+ if (handler instanceof HandlerMethod) {
|
|
|
+ HandlerMethod handlerMethod = (HandlerMethod) handler;
|
|
|
+ // 配置该注解,说明不进行用户拦截
|
|
|
+ IgnoreAuth annotation = handlerMethod.getBeanType().getAnnotation(IgnoreAuth.class);
|
|
|
+ if (annotation == null) {
|
|
|
+ annotation = handlerMethod.getMethodAnnotation(IgnoreAuth.class);
|
|
|
+ }
|
|
|
+ if (annotation != null) {
|
|
|
+ return super.preHandle(request, response, handler);
|
|
|
+ }
|
|
|
+ String token = request.getHeader(authConfig.getAuthHeader());
|
|
|
+ if (null != token) {
|
|
|
+ JwtInfo infoFromToken = JwtHelper.getInfoFromToken(token, authConfig.getPublicKey());
|
|
|
+ BaseContextHolder.setAppId(infoFromToken.getAppId());
|
|
|
+ BaseContextHolder.setUserId(infoFromToken.getUserId());
|
|
|
+ BaseContextHolder.setCompanyId(infoFromToken.getCompanyId());
|
|
|
+ BaseContextHolder.setToken(token);
|
|
|
+ log.info("token={} \\r\\n userName={}", token, infoFromToken.getUserName());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // no mapping
|
|
|
}
|
|
|
return super.preHandle(request, response, handler);
|
|
|
}
|