|
|
@ -10,11 +10,14 @@ import com.tduck.cloud.common.vo.LoginUserVO; |
|
|
|
import io.jsonwebtoken.Claims; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.web.method.HandlerMethod; |
|
|
|
import org.springframework.util.AntPathMatcher; |
|
|
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author qing |
|
|
@ -23,6 +26,15 @@ import javax.servlet.http.HttpServletResponse; |
|
|
|
public class AuthorizationInterceptor extends HandlerInterceptorAdapter { |
|
|
|
public static final String USER_KEY = "userId"; |
|
|
|
private final JwtUtils jwtUtils; |
|
|
|
private static List<String> skipUrlList; |
|
|
|
private final AntPathMatcher antPathMatcher = new AntPathMatcher(); |
|
|
|
@PostConstruct |
|
|
|
private void init(){ |
|
|
|
skipUrlList = new ArrayList<>(); |
|
|
|
skipUrlList.add("/tduck-api/captcha/get"); |
|
|
|
skipUrlList.add("/tduck-api/captcha/check*"); |
|
|
|
skipUrlList.add("/tduck-api/login/account*"); |
|
|
|
} |
|
|
|
|
|
|
|
public AuthorizationInterceptor(JwtUtils jwtUtils) { |
|
|
|
this.jwtUtils = jwtUtils; |
|
|
@ -31,7 +43,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { |
|
|
|
@Override |
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
|
|
|
Login annotation; |
|
|
|
if (handler instanceof HandlerMethod) { |
|
|
|
/*if (handler instanceof HandlerMethod) { |
|
|
|
annotation = ((HandlerMethod) handler).getMethodAnnotation(Login.class); |
|
|
|
} else { |
|
|
|
return true; |
|
|
@ -39,8 +51,15 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { |
|
|
|
|
|
|
|
if (annotation == null) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
}*/ |
|
|
|
String requestURI = request.getRequestURI(); |
|
|
|
|
|
|
|
if (isSkip(requestURI)){ |
|
|
|
System.out.println("=====skip=====url"+requestURI); |
|
|
|
return true; |
|
|
|
}else { |
|
|
|
System.out.println("==========url"+requestURI); |
|
|
|
} |
|
|
|
//获取用户凭证
|
|
|
|
String token = request.getHeader(jwtUtils.getHeader()); |
|
|
|
String customerId = request.getHeader(CommonConstants.KEY_CUSTOMER_ID); |
|
|
@ -79,4 +98,14 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { |
|
|
|
//清空threadLocal
|
|
|
|
LoginUserUtil.remove(); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean isSkip(String url){ |
|
|
|
for (String skipurl : skipUrlList) { |
|
|
|
System.out.println(antPathMatcher.match(skipurl, url)+",path"+url+",skipurl:"+skipurl); |
|
|
|
if (antPathMatcher.match(skipurl, url)){ |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|