package com.qianwen.core.boot.request;
|
|
import java.io.IOException;
|
import javax.servlet.Filter;
|
import javax.servlet.FilterChain;
|
import javax.servlet.FilterConfig;
|
import javax.servlet.ServletException;
|
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletResponse;
|
import javax.servlet.http.HttpServletRequest;
|
import org.springframework.util.AntPathMatcher;
|
|
/* loaded from: blade-core-boot-9.3.0.0-SNAPSHOT.jar:org/springblade/core/boot/request/BladeRequestFilter.class */
|
public class BladeRequestFilter implements Filter {
|
private final RequestProperties requestProperties;
|
private final XssProperties xssProperties;
|
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
|
|
public BladeRequestFilter(final RequestProperties requestProperties, final XssProperties xssProperties) {
|
this.requestProperties = requestProperties;
|
this.xssProperties = xssProperties;
|
}
|
|
public void init(FilterConfig config) {
|
}
|
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
String path = ((HttpServletRequest) request).getServletPath();
|
if (!this.requestProperties.getEnabled().booleanValue() || isRequestSkip(path)) {
|
chain.doFilter(request, response);
|
} else if (!this.xssProperties.getEnabled().booleanValue() || isXssSkip(path)) {
|
BladeHttpServletRequestWrapper bladeRequest = new BladeHttpServletRequestWrapper((HttpServletRequest) request);
|
chain.doFilter(bladeRequest, response);
|
} else {
|
XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper((HttpServletRequest) request);
|
chain.doFilter(xssRequest, response);
|
}
|
}
|
|
private boolean isRequestSkip(String path) {
|
return this.requestProperties.getSkipUrl().stream().anyMatch(pattern -> {
|
return this.antPathMatcher.match(pattern, path);
|
});
|
}
|
|
private boolean isXssSkip(String path) {
|
return this.xssProperties.getSkipUrl().stream().anyMatch(pattern -> {
|
return this.antPathMatcher.match(pattern, path);
|
});
|
}
|
|
public void destroy() {
|
}
|
}
|