提交Salon旧接口清理与安全配置基线
This commit is contained in:
+12
-2
@@ -6,7 +6,7 @@ import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.reactive.CorsWebFilter;
|
||||
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Gateway CORS 配置
|
||||
@@ -17,11 +17,21 @@ import java.util.Arrays;
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
private final CorsProperties corsProperties;
|
||||
|
||||
public CorsConfig(CorsProperties corsProperties) {
|
||||
this.corsProperties = corsProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsWebFilter corsWebFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
|
||||
config.addAllowedOriginPattern("*");
|
||||
List<String> allowedOrigins = corsProperties.getAllowedOrigins();
|
||||
if (allowedOrigins == null || allowedOrigins.isEmpty()) {
|
||||
throw new IllegalStateException("jayucloud-salon.security.cors.allowed-origins 未配置,拒绝启动以避免开放跨域");
|
||||
}
|
||||
allowedOrigins.forEach(config::addAllowedOrigin);
|
||||
config.addAllowedMethod("*");
|
||||
config.addAllowedHeader("*");
|
||||
config.setAllowCredentials(true);
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.xiaowang.jayucloud.salon.gateway.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "jayucloud-salon.security.cors")
|
||||
public class CorsProperties {
|
||||
private List<String> allowedOrigins = new ArrayList<>();
|
||||
}
|
||||
+10
-1
@@ -4,6 +4,8 @@ import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* Gateway JWT 校验配置。
|
||||
*/
|
||||
@@ -12,9 +14,16 @@ import org.springframework.context.annotation.Configuration;
|
||||
@ConfigurationProperties(prefix = "jayucloud-salon.security.jwt")
|
||||
public class JwtProperties {
|
||||
|
||||
private String secret = "jayucloud-salon-secret-key-for-jwt-token-generation-2026-must-be-at-least-512-bits-long-for-hs512-algorithm-security-requirements";
|
||||
private String secret;
|
||||
|
||||
private String issuer = "jayucloud-salon";
|
||||
|
||||
private long clockSkewSeconds = 30;
|
||||
|
||||
@PostConstruct
|
||||
public void validate() {
|
||||
if (secret == null || secret.trim().length() < 64) {
|
||||
throw new IllegalStateException("jayucloud-salon.security.jwt.secret 未配置或长度不足 64 位");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ spring:
|
||||
# 注册到 Nacos 的服务名。
|
||||
service: jc-salon-gateway
|
||||
# Nacos 认证信息可由运行环境覆盖。
|
||||
username: ${NACOS_USERNAME:jayucloud}
|
||||
password: ${NACOS_PASSWORD:122503wcy....}
|
||||
username: ${NACOS_USERNAME:}
|
||||
password: ${NACOS_PASSWORD:}
|
||||
config:
|
||||
# Nacos 配置中心与服务发现使用同一运行环境参数。
|
||||
server-addr: ${NACOS_SERVER_ADDR:192.168.5.15:8848}
|
||||
@@ -28,8 +28,8 @@ spring:
|
||||
# 所有 Nacos 配置均使用 YAML。
|
||||
file-extension: yaml
|
||||
# Nacos 认证信息可由运行环境覆盖。
|
||||
username: ${NACOS_USERNAME:jayucloud}
|
||||
password: ${NACOS_PASSWORD:122503wcy....}
|
||||
username: ${NACOS_USERNAME:}
|
||||
password: ${NACOS_PASSWORD:}
|
||||
# Core 与 Gateway 共享的公共配置文件。
|
||||
shared-configs:
|
||||
- data-id: infra.yaml
|
||||
|
||||
Reference in New Issue
Block a user