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