mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
refactor: 使用 @ConfigurationProperties
record
This commit is contained in:
parent
8e9f31a240
commit
ac1628aa2a
@ -25,7 +25,7 @@ public class CorsConfig {
|
|||||||
public CorsFilter corsFilter() {
|
public CorsFilter corsFilter() {
|
||||||
CorsConfiguration config = new CorsConfiguration();
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
// 允许的域,不要写*,否则cookie就无法使用了
|
// 允许的域,不要写*,否则cookie就无法使用了
|
||||||
for (String allowOrigin : corsProperties.getAllowOrigins()) {
|
for (String allowOrigin : corsProperties.allowOrigins()) {
|
||||||
config.addAllowedOrigin(allowOrigin);
|
config.addAllowedOrigin(allowOrigin);
|
||||||
}
|
}
|
||||||
// 允许的头信息
|
// 允许的头信息
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package io.github.xxyopen.novel.core.config;
|
package io.github.xxyopen.novel.core.config;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -12,11 +11,6 @@ import java.util.List;
|
|||||||
* @date 2022/5/17
|
* @date 2022/5/17
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "novel.cors")
|
@ConfigurationProperties(prefix = "novel.cors")
|
||||||
@Data
|
public record CorsProperties(List<String> allowOrigins) {
|
||||||
public class CorsProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 允许跨域的域名
|
|
||||||
* */
|
|
||||||
private List<String> allowOrigins;
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package io.github.xxyopen.novel.core.config;
|
package io.github.xxyopen.novel.core.config;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -12,17 +11,6 @@ import java.util.List;
|
|||||||
* @date 2022/5/17
|
* @date 2022/5/17
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "novel.xss")
|
@ConfigurationProperties(prefix = "novel.xss")
|
||||||
@Data
|
public record XssProperties(Boolean enabled,List<String> excludes) {
|
||||||
public class XssProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 过滤开关
|
|
||||||
* */
|
|
||||||
private Boolean enabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 排除链接
|
|
||||||
* */
|
|
||||||
private List<String> excludes;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,11 @@ public class XssFilter implements Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleExcludeUrl(HttpServletRequest request) {
|
private boolean handleExcludeUrl(HttpServletRequest request) {
|
||||||
if (CollectionUtils.isEmpty(xssProperties.getExcludes())) {
|
if (CollectionUtils.isEmpty(xssProperties.excludes())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String url = request.getServletPath();
|
String url = request.getServletPath();
|
||||||
for (String pattern : xssProperties.getExcludes()) {
|
for (String pattern : xssProperties.excludes()) {
|
||||||
Pattern p = Pattern.compile("^" + pattern);
|
Pattern p = Pattern.compile("^" + pattern);
|
||||||
Matcher m = p.matcher(url);
|
Matcher m = p.matcher(url);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user