暂存提交

This commit is contained in:
2026-08-19 16:24:02 +08:00
parent f5c4bf130a
commit 6acb6178da
354 changed files with 25000 additions and 198 deletions
@@ -0,0 +1,26 @@
package com.baiyue.warehouse.security;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ResponseStatusException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
@Component
public class InternalServiceTokenGuard {
private final byte[] expected;
public InternalServiceTokenGuard(
@Value("${baiyue.internal-service.token:phase1-local-internal-token-at-least-32-bytes}") String token) {
this.expected = token.getBytes(StandardCharsets.UTF_8);
}
public void verify(String provided) {
byte[] actual = provided == null ? new byte[0] : provided.getBytes(StandardCharsets.UTF_8);
if (!MessageDigest.isEqual(expected, actual)) {
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Invalid internal service token");
}
}
}