优化
This commit is contained in:
+8
-2
@@ -12,13 +12,19 @@ import java.security.MessageDigest;
|
||||
|
||||
@Component
|
||||
public class InternalServiceTokenGuard {
|
||||
private static final String INSECURE_PLACEHOLDER =
|
||||
"change-me-to-an-internal-token-at-least-32-bytes-long";
|
||||
|
||||
@Value("${baiyue.security.internal-service-token}") private String token;
|
||||
private byte[] expectedToken;
|
||||
|
||||
@PostConstruct
|
||||
void initializeToken() {
|
||||
if (token == null || token.getBytes(StandardCharsets.UTF_8).length < 32) {
|
||||
throw new IllegalStateException("INTERNAL_SERVICE_TOKEN 至少需要 32 字节");
|
||||
if (token == null
|
||||
|| token.isBlank()
|
||||
|| INSECURE_PLACEHOLDER.equals(token)
|
||||
|| token.getBytes(StandardCharsets.UTF_8).length < 32) {
|
||||
throw new IllegalStateException("INTERNAL_SERVICE_TOKEN 必须配置为至少 32 字节的安全令牌");
|
||||
}
|
||||
this.expectedToken = token.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user