|
|
|
|
@ -1,16 +1,16 @@
|
|
|
|
|
package cn.iocoder.mall.user.application.config;
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.common.framework.config.GlobalExceptionHandler;
|
|
|
|
|
import cn.iocoder.common.framework.servlet.CorsFilter;
|
|
|
|
|
import cn.iocoder.mall.admin.sdk.interceptor.AdminSecurityInterceptor;
|
|
|
|
|
import cn.iocoder.mall.user.sdk.interceptor.UserAccessLogInterceptor;
|
|
|
|
|
import cn.iocoder.mall.user.sdk.interceptor.UserSecurityInterceptor;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.context.annotation.Import;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.*;
|
|
|
|
|
|
|
|
|
|
@EnableWebMvc
|
|
|
|
|
@Configuration
|
|
|
|
|
@ -27,6 +27,7 @@ public class MVCConfiguration implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
|
|
// CORS
|
|
|
|
|
// 用户
|
|
|
|
|
registry.addInterceptor(userAccessLogInterceptor).addPathPatterns("/users/**");
|
|
|
|
|
registry.addInterceptor(userSecurityInterceptor).addPathPatterns("/users/**"); // 只拦截我们定义的接口
|
|
|
|
|
@ -41,4 +42,21 @@ public class MVCConfiguration implements WebMvcConfigurer {
|
|
|
|
|
registry.addResourceHandler("webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO 芋艿,允许跨域
|
|
|
|
|
// @Override
|
|
|
|
|
// public void addCorsMappings(CorsRegistry registry) {
|
|
|
|
|
// registry.addMapping("/**")
|
|
|
|
|
// .allowedHeaders("*")
|
|
|
|
|
// .allowedMethods("*")
|
|
|
|
|
// .allowedOrigins("*");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public FilterRegistrationBean<CorsFilter> corsFilter() {
|
|
|
|
|
FilterRegistrationBean<CorsFilter> registrationBean = new FilterRegistrationBean<>();
|
|
|
|
|
registrationBean.setFilter(new CorsFilter());
|
|
|
|
|
registrationBean.addUrlPatterns("/*");
|
|
|
|
|
return registrationBean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|