policeSecurity/policeSecurityServer/src/main/java/com/changhu/config/WebConfig.java

65 lines
2.3 KiB
Java

package com.changhu.config;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import com.changhu.support.interceptor.JsonBodyInterceptor;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Configuration;
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.util.ArrayList;
import java.util.List;
/**
* author: luozhun
* desc: WebConfig
* createTime: 2023/8/18 10:56
*/
@Configuration
public class WebConfig implements WebMvcConfigurer {
private final List<String> whiteList = new ArrayList<>();
public WebConfig() {
whiteList.add("/common/**");
whiteList.add("/test/**");
whiteList.add("/login");
whiteList.add("/logout");
whiteList.add("/management/getCheckStatus");
whiteList.add("/favicon.ico");
//druid console
whiteList.add("/druid/**");
//knife4j
whiteList.add("/doc.html/**");
whiteList.add("/static/**");
whiteList.add("/swagger-resources");
whiteList.add("/**webjars/**");
whiteList.add("/v3/**");
//平台信息
whiteList.add("/platformSetting/getPlatformInfo");
}
@Override
public void addInterceptors(@NotNull InterceptorRegistry registry) {
// 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
.addPathPatterns("/**")
.excludePathPatterns(whiteList);
// 注册jsonBody 拦截器 用于标识是否需要JsonResult返回
registry.addInterceptor(new JsonBodyInterceptor());
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("doc.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}