| 
									
										
										
										
											2025-09-08 17:01:50 +08:00
										 |  |  | package com.yj.earth.common.config;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import cn.dev33.satoken.interceptor.SaInterceptor;
 | 
					
						
							|  |  |  | import cn.dev33.satoken.stp.StpUtil;
 | 
					
						
							|  |  |  | import com.yj.earth.common.exception.UnAuthException;
 | 
					
						
							|  |  |  | import org.springframework.context.annotation.Configuration;
 | 
					
						
							|  |  |  | import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 | 
					
						
							|  |  |  | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import java.util.ArrayList;
 | 
					
						
							|  |  |  | import java.util.List;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Configuration
 | 
					
						
							|  |  |  | public class SaTokenConfig implements WebMvcConfigurer {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @Override
 | 
					
						
							|  |  |  |     public void addInterceptors(InterceptorRegistry registry) {
 | 
					
						
							|  |  |  |         List<String> excludePathPatterns = new ArrayList<>();
 | 
					
						
							|  |  |  |         excludePathPatterns.add("/user/login");
 | 
					
						
							|  |  |  |         excludePathPatterns.add("/user/add");
 | 
					
						
							|  |  |  |         excludePathPatterns.add("/doc.html");
 | 
					
						
							|  |  |  |         excludePathPatterns.add("/webjars/**");
 | 
					
						
							|  |  |  |         excludePathPatterns.add("/v3/api-docs/**");
 | 
					
						
							|  |  |  |         excludePathPatterns.add("/fileInfo/download/**");
 | 
					
						
							|  |  |  |         excludePathPatterns.add("/fileInfo/preview/**");
 | 
					
						
							| 
									
										
										
										
											2025-09-22 17:13:22 +08:00
										 |  |  |         excludePathPatterns.add("/fileInfo/previewLocal/**");
 | 
					
						
							| 
									
										
										
										
											2025-09-08 17:01:50 +08:00
										 |  |  |         excludePathPatterns.add("/data/clt/**");
 | 
					
						
							|  |  |  |         excludePathPatterns.add("/data/mbtiles/**");
 | 
					
						
							|  |  |  |         excludePathPatterns.add("/data/pak/**");
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // 注册 Sa-Token 拦截器
 | 
					
						
							|  |  |  |         registry.addInterceptor(new SaInterceptor(handle -> {
 | 
					
						
							|  |  |  |                     // 登录校验
 | 
					
						
							|  |  |  |                     try {
 | 
					
						
							|  |  |  |                         StpUtil.checkLogin();
 | 
					
						
							|  |  |  |                     } catch (Exception e) {
 | 
					
						
							|  |  |  |                         throw new UnAuthException("未携带登录凭证");
 | 
					
						
							|  |  |  |                     }
 | 
					
						
							|  |  |  |                 })).addPathPatterns("/**")
 | 
					
						
							|  |  |  |                 .excludePathPatterns(excludePathPatterns);
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | }
 |