【修改】删除权限,增加白名单,修改mac地址的校验方式
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -263,5 +263,4 @@ justauth:
|
||||
pf4j:
|
||||
# pluginsDir: /tmp/
|
||||
pluginsDir: ../plugins
|
||||
system:
|
||||
allowed-mac: E4-54-E8-25-F6-14
|
||||
|
||||
|
||||
@@ -304,7 +304,6 @@ exam:
|
||||
- exam_knowledge_points
|
||||
- exam_specialty
|
||||
- exam_app_check
|
||||
- exam_white_list
|
||||
- system_tenant
|
||||
- system_tenant_package
|
||||
- system_dict_data
|
||||
|
||||
Reference in New Issue
Block a user