| | |
| | | import com.tcm.training.admin.common.xss.XssParamInterceptor; |
| | | import com.tcm.training.admin.upload.LocalUploadProperties; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.core.env.Environment; |
| | | 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 java.io.File; |
| | | import java.util.Arrays; |
| | | |
| | | @Configuration |
| | | public class SaTokenWebConfig implements WebMvcConfigurer { |
| | | |
| | | private final XssParamInterceptor xssParamInterceptor; |
| | | private final LocalUploadProperties localUploadProperties; |
| | | private final Environment environment; |
| | | |
| | | public SaTokenWebConfig(XssParamInterceptor xssParamInterceptor, |
| | | LocalUploadProperties localUploadProperties) { |
| | | LocalUploadProperties localUploadProperties, |
| | | Environment environment) { |
| | | this.xssParamInterceptor = xssParamInterceptor; |
| | | this.localUploadProperties = localUploadProperties; |
| | | this.environment = environment; |
| | | } |
| | | |
| | | /** |
| | |
| | | private boolean isPublicAdminApi(String requestPath) { |
| | | return "/api/auth/login".equals(requestPath) |
| | | || "/api/auth/captcha".equals(requestPath) |
| | | || (!isProdProfile() && isJpushManualPushApi(requestPath)) |
| | | || requestPath.startsWith("/api/open/") |
| | | || requestPath.startsWith("/api/v1/open/"); |
| | | } |
| | | |
| | | /** |
| | | * 判断当前后台路由是否属于极光手动推送联调接口。 |
| | | */ |
| | | private boolean isJpushManualPushApi(String requestPath) { |
| | | return "/api/jpush/manual-push".equals(requestPath) |
| | | || "/api/v1/jpush/manual-push".equals(requestPath) |
| | | || requestPath.startsWith("/api/jpush/manual-push/") |
| | | || requestPath.startsWith("/api/v1/jpush/manual-push/"); |
| | | } |
| | | |
| | | /** |
| | | * 判断当前是否为生产环境,生产环境手动推送接口必须校验后台登录态。 |
| | | */ |
| | | private boolean isProdProfile() { |
| | | return Arrays.asList(environment.getActiveProfiles()).contains("prod"); |
| | | } |
| | | |
| | | /** |
| | | * 将本地上传目录映射为静态资源,可通过 /uploads/** 访问。 |
| | | */ |
| | | @Override |