You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.4 KiB
Java
64 lines
2.4 KiB
Java
package com.supervision.config;
|
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Configuration
|
|
public class WebConfig implements WebMvcConfigurer {
|
|
|
|
@Autowired
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
@Override
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
// 添加权限拦截器
|
|
registry.addInterceptor(new JwtInterceptor(redisTemplate))
|
|
.addPathPatterns("/**")
|
|
.excludePathPatterns(ignorePathPatterns());
|
|
}
|
|
|
|
public List<String> ignorePathPatterns() {
|
|
List<String> paths = new ArrayList<>();
|
|
paths.add("/swagger-resources/**");
|
|
paths.add("/webjars/**");
|
|
paths.add("/v2/**");
|
|
paths.add("/swagger-ui.html/**");
|
|
paths.add("/doc.html/**");
|
|
paths.add("/error");
|
|
paths.add("/favicon.ico");
|
|
paths.add("/user/login");
|
|
paths.add("/webSocket/**");
|
|
// 开发环境,放开不校验token.每次修改这里需要重启(热部署不行)
|
|
// paths.add("/**");
|
|
return paths;
|
|
}
|
|
|
|
@Bean
|
|
public ObjectMapper objectMapper() {
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
|
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
|
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
|
objectMapper.registerModule(javaTimeModule);
|
|
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
|
|
|
return objectMapper;
|
|
}
|
|
}
|