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