【修改】表格修改项
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package pc.exam.pp.server.config;
|
||||
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import pc.exam.pp.module.system.util.oauth2.MacUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MacValidator {
|
||||
|
||||
private final SystemMacProperties macProperties;
|
||||
|
||||
public MacValidator(SystemMacProperties macProperties) {
|
||||
this.macProperties = macProperties;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void validateMac() {
|
||||
try {
|
||||
String localMac = String.valueOf(MacUtils.getPhysicalMac());
|
||||
if (localMac == null || localMac.isEmpty()) {
|
||||
throw new IllegalStateException("无法获取本机 MAC 地址!");
|
||||
}
|
||||
|
||||
String allowed = macProperties.getAllowedMac();
|
||||
if (allowed == null || allowed.isEmpty()) {
|
||||
throw new IllegalStateException("系统未配置允许的 MAC 地址!");
|
||||
}
|
||||
|
||||
boolean match = normalize(allowed).equals(normalize(localMac));
|
||||
if (!match) {
|
||||
throw new IllegalStateException("该机器 MAC 地址未授权!本机:" + localMac);
|
||||
}
|
||||
|
||||
log.info("✅ MAC 验证通过,本机 MAC: {}", localMac);
|
||||
} catch (Exception e) {
|
||||
log.error("❌ MAC 验证失败: {}", e.getMessage());
|
||||
System.exit(1); // 阻止启动
|
||||
}
|
||||
}
|
||||
|
||||
private String normalize(String mac) {
|
||||
return mac == null ? "" : mac.replaceAll("[-:]", "").toUpperCase();
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package pc.exam.pp.server.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "system") // 对应 application.yml 中的 system: 节点
|
||||
public class SystemMacProperties {
|
||||
|
||||
/**
|
||||
* 允许的 MAC 地址列表
|
||||
*/
|
||||
private String allowedMac;
|
||||
}
|
@@ -73,7 +73,7 @@ spring:
|
||||
redis:
|
||||
host: 115.120.213.238 # 地址
|
||||
port: 6379 # 端口
|
||||
database: 0 # 数据库索引
|
||||
database: 1 # 数据库索引
|
||||
password: sadjklasnfasd # 密码,建议生产环境开启
|
||||
|
||||
--- #################### 定时任务相关配置 ####################
|
||||
@@ -262,4 +262,6 @@ justauth:
|
||||
--- #################### iot相关配置 ####################
|
||||
pf4j:
|
||||
# pluginsDir: /tmp/
|
||||
pluginsDir: ../plugins
|
||||
pluginsDir: ../plugins
|
||||
system:
|
||||
allowed-mac: E4-54-E8-25-F6-14
|
||||
|
Reference in New Issue
Block a user