|
|
|
@ -1,6 +1,10 @@
|
|
|
|
|
package com.supervision.config;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.supervision.police.dto.user.UserInfoDTO;
|
|
|
|
|
import com.supervision.police.service.SystemUserService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
|
@ -8,16 +12,31 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Configuration
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class WebConfig implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
|
|
private final Environment environment;
|
|
|
|
|
|
|
|
|
|
private final SystemUserService systemUserService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
|
|
// 添加权限拦截器
|
|
|
|
|
registry.addInterceptor(new JwtInterceptor())
|
|
|
|
|
JwtInterceptor interceptor = new JwtInterceptor();
|
|
|
|
|
// ***切记**** 此属性仅可以通过idea设置环境变量,千万不要写入配置文件中.....
|
|
|
|
|
String userAccount = environment.getProperty("fu-hsi-config.local.user.forgery");
|
|
|
|
|
if (StrUtil.isNotEmpty(userAccount)){
|
|
|
|
|
log.info("已配置本地模拟用户:{}",userAccount);
|
|
|
|
|
UserInfoDTO userInfo = systemUserService.getUserInfo(userAccount);
|
|
|
|
|
if (null == userInfo){
|
|
|
|
|
log.warn("本地模拟用户不存在:{}",userAccount);
|
|
|
|
|
}else {
|
|
|
|
|
interceptor.setForgeryUser(userInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
registry.addInterceptor(interceptor)
|
|
|
|
|
.addPathPatterns("/**")
|
|
|
|
|
.excludePathPatterns(ignorePathPatterns());
|
|
|
|
|
}
|
|
|
|
|