feat: 拦截器测试成功
This commit is contained in:
@@ -41,6 +41,6 @@ public class GlobalConfig extends WebMvcConfigurationSupport {
|
||||
@Override
|
||||
protected void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new LoginInterceptor())
|
||||
.addPathPatterns("/**");
|
||||
.addPathPatterns("/**").excludePathPatterns("/oauth/**","/system/getConfigByKey","/user/**");
|
||||
}
|
||||
}
|
||||
|
@@ -13,10 +13,10 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @Description: TODO
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class FeignConfiguration {
|
||||
@Bean
|
||||
public RequestInterceptor requestInterceptor(){
|
||||
return new FeignRequestInterceptor();
|
||||
}
|
||||
}
|
||||
//@Configuration
|
||||
//public class FeignConfiguration {
|
||||
// @Bean
|
||||
// public RequestInterceptor requestInterceptor(){
|
||||
// return new FeignRequestInterceptor();
|
||||
// }
|
||||
//}
|
||||
|
@@ -19,16 +19,16 @@ import java.util.Objects;
|
||||
* @Description: Feign请求拦截器
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
public class FeignRequestInterceptor implements RequestInterceptor {
|
||||
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = requestAttributes.getRequest();
|
||||
String userId = request.getHeader("userId");
|
||||
if (StringUtils.isNotBlank(userId)) {
|
||||
requestTemplate.header("userId", userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
//@Component
|
||||
//public class FeignRequestInterceptor implements RequestInterceptor {
|
||||
//
|
||||
// @Override
|
||||
// public void apply(RequestTemplate requestTemplate) {
|
||||
// ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
// HttpServletRequest request = requestAttributes.getRequest();
|
||||
// String userId = request.getHeader("userId");
|
||||
// if (StringUtils.isNotBlank(userId)) {
|
||||
// requestTemplate.header("userId", userId);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@@ -31,11 +31,12 @@ public class LoginFilter implements GlobalFilter {
|
||||
ServerHttpRequest.Builder mutate = request.mutate();
|
||||
String url = request.getURI().getPath();
|
||||
log.info("LoginFilter.filter.url:{}", url);
|
||||
if (url.equals("/auth/render/") || url.equals("/auth/callback/") || url.equals("/auth/user/register") || url.equals("/auth/user/login") || url.equals("/system/getConfigByKey")) {
|
||||
if (url.equals("/oauth/render/gitee") || url.equals("/oauth/callback/gitee") || url.equals("/auth/user/register") || url.equals("/auth/user/login") || url.equals("/system/getConfigByKey")) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
||||
String userId = (String) tokenInfo.getLoginId();
|
||||
System.out.println("userId:" + userId);
|
||||
if (StringUtils.isEmpty(userId)) {
|
||||
throw new Exception("未获取到用户信息");
|
||||
}
|
||||
|
Reference in New Issue
Block a user