| | |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.config.properties.SecurityProperties; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.cors.CorsConfiguration; |
| | |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 通用配置 |
| | |
| | | @Configuration |
| | | public class ResourcesConfig implements WebMvcConfigurer { |
| | | |
| | | @Autowired |
| | | private SecurityProperties securityProperties; |
| | | |
| | | // 注册sa-token的拦截器 |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) { |
| | | List<String> urlPath = Arrays.asList( |
| | | "/login", |
| | | "/logout", |
| | | "/captchaImage", |
| | | "/*.html", |
| | | "/**/*.html", |
| | | "/**/*.css", |
| | | "/**/*.js", |
| | | "/profile/**", |
| | | "/common/download**", |
| | | "/common/download/resource**", |
| | | "/swagger-ui.html", |
| | | "/swagger-resources/**", |
| | | "/webjars/**", |
| | | "/*/api-docs", |
| | | "/druid/**", |
| | | "/actuator", |
| | | "/actuator/**" |
| | | ); |
| | | // 注册路由拦截器,自定义验证规则 |
| | | registry.addInterceptor(new SaRouteInterceptor((request, response, handler) -> { |
| | | // 登录验证 -- 排除多个路径 |
| | |
| | | //获取所有的 |
| | | Collections.singletonList("/**"), |
| | | //排除下不需要拦截的 |
| | | urlPath, |
| | | Arrays.asList(securityProperties.getExcludes()), |
| | | () -> { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if(StringUtils.isNotNull(userId) ) { |