| | |
| | | package com.tcm.training.admin.config; |
| | | |
| | | import com.tcm.training.admin.app.auth.support.StpAppUserUtil; |
| | | import cn.dev33.satoken.interceptor.SaInterceptor; |
| | | import cn.dev33.satoken.context.SaHolder; |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import com.tcm.training.admin.common.xss.XssParamInterceptor; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import com.tcm.training.admin.upload.LocalUploadProperties; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
| | | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
| | |
| | | public class SaTokenWebConfig implements WebMvcConfigurer { |
| | | |
| | | private final XssParamInterceptor xssParamInterceptor; |
| | | private final LocalUploadProperties localUploadProperties; |
| | | |
| | | @Value("${app.upload.dir:uploads}") |
| | | private String uploadDir; |
| | | |
| | | @Value("${app.upload.path-prefix:/uploads}") |
| | | private String pathPrefix; |
| | | |
| | | public SaTokenWebConfig(XssParamInterceptor xssParamInterceptor) { |
| | | public SaTokenWebConfig(XssParamInterceptor xssParamInterceptor, |
| | | LocalUploadProperties localUploadProperties) { |
| | | this.xssParamInterceptor = xssParamInterceptor; |
| | | this.localUploadProperties = localUploadProperties; |
| | | } |
| | | |
| | | /** |
| | |
| | | registry.addInterceptor(new SaInterceptor(handle -> handleAuth())) |
| | | .addPathPatterns("/api/**", "/api/v1/**") |
| | | .excludePathPatterns( |
| | | pathPrefix + "/**" |
| | | localUploadProperties.getPathPrefix() + "/**" |
| | | ); |
| | | |
| | | registry.addInterceptor(xssParamInterceptor) |
| | |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| | | // 转为绝对路径,确保 file: 协议正确。 |
| | | String absPath = new File(uploadDir).getAbsolutePath(); |
| | | registry.addResourceHandler(pathPrefix + "/**") |
| | | String absPath = new File(localUploadProperties.getDir()).getAbsolutePath(); |
| | | registry.addResourceHandler(localUploadProperties.getPathPrefix() + "/**") |
| | | .addResourceLocations("file:" + absPath + "/"); |
| | | } |
| | | } |