最新产品
This commit is contained in:
		
							
								
								
									
										41
									
								
								src/main/java/com/yj/earth/common/config/SaTokenConfig.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/main/java/com/yj/earth/common/config/SaTokenConfig.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | ||||
| 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/**"); | ||||
|         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); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 ZZX9599
					ZZX9599