1
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package com.agileboot.common.json.xss;
|
||||
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 直接将html标签去掉
|
||||
* @author valarchie
|
||||
*/
|
||||
public class JsonHtmlXssTrimSerializer extends JsonDeserializer<String> {
|
||||
|
||||
public JsonHtmlXssTrimSerializer() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String deserialize(JsonParser p, DeserializationContext context) throws IOException {
|
||||
String value = p.getValueAsString();
|
||||
if( value != null) {
|
||||
// 去除掉html标签 如果想要转义的话 可使用 HtmlUtil.escape()
|
||||
return HtmlUtil.cleanHtmlTag(value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<String> handledType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@AutoConfiguration
|
||||
@MapperScan("${mybatis-plus.mapperPackage}")
|
||||
@MapperScan(value = "${mybatis-plus.mapperPackage}", markerInterface = com.baomidou.mybatisplus.core.mapper.BaseMapper.class)
|
||||
@PropertySource(value = "classpath:common-mybatis.yml", factory = YmlPropertySourceFactory.class)
|
||||
public class MybatisPlusConfiguration {
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.agileboot.common.web.config;
|
||||
|
||||
import com.agileboot.common.web.filter.TraceIdFilter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
@AutoConfiguration
|
||||
public class FilterConfig {
|
||||
|
||||
@Value("${agileboot.traceRequestIdKey:WOl-RequestId}")
|
||||
private String requestIdKey;
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<TraceIdFilter> traceIdFilterRegistrationBean() {
|
||||
FilterRegistrationBean<TraceIdFilter> registration = new FilterRegistrationBean<>();
|
||||
registration.setFilter(new TraceIdFilter(requestIdKey));
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("traceIdFilter");
|
||||
registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
||||
return registration;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowCredentials(true);
|
||||
// 设置访问源地址
|
||||
config.addAllowedOriginPattern("*");
|
||||
// 设置访问源请求头
|
||||
config.addAllowedHeader("*");
|
||||
// 设置访问源请求方法
|
||||
config.addAllowedMethod("*");
|
||||
// 有效期 1800秒
|
||||
config.setMaxAge(1800L);
|
||||
// 添加映射路径,拦截一切请求
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
// 返回新的CorsFilter
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.agileboot.infrastructure.filter;
|
||||
package com.agileboot.common.web.filter;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import java.io.IOException;
|
||||
@@ -1 +1,2 @@
|
||||
com.agileboot.common.web.config.ResourcesConfig
|
||||
com.agileboot.common.web.config.FilterConfig
|
||||
Reference in New Issue
Block a user