fix: wire lingxing auth components for spring

This commit is contained in:
2026-09-21 22:12:37 +08:00
parent 03374c83f6
commit 8d66610964
3 changed files with 6 additions and 2 deletions
@@ -7,6 +7,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.function.Function;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/** 领星登录态缓存:按 providerKey 隔离、提前过期、single-flight 和二次验证冷却。 */
@@ -20,6 +21,7 @@ public class LingxingAuthManager {
private final Map<String, Long> cooldownUntil = new ConcurrentHashMap<>();
private volatile Function<LingxingProviderConfig, LingxingAuthState> passwordLogin;
@Autowired
public LingxingAuthManager(LingxingBrowserSessionReader browser) {
this(browser, Clock.systemUTC(), Executors.newCachedThreadPool(r -> {
Thread thread = new Thread(r, "lingxing-auth-refresh"); thread.setDaemon(true); return thread;
@@ -17,6 +17,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/** 通过 Chrome DevTools Protocol 读取人工登录的持久化 OMS 页面。 */
@@ -26,6 +27,7 @@ public class LingxingBrowserSessionReader {
private final HttpClient http;
private final Duration timeout;
@Autowired
public LingxingBrowserSessionReader(ObjectMapper mapper) {
this(mapper, HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build(), Duration.ofSeconds(5));
}
@@ -47,8 +47,8 @@ class LingxingAuthManagerTest {
@Test
void jwtExpiryUsesSafetyWindow() {
String token = "eyJhbGciOiJub25lIn0.eyJleHAiOjE3OTAwMDAwMDB9.signature";
long expected = 1790000000000L - 300_000L;
String token = "eyJhbGciOiJub25lIn0.eyJleHAiOjE4OTAwMDAwMDB9.signature";
long expected = 1890000000000L - 300_000L;
assertThat(LingxingBrowserSessionReader.expiresAt(token, config)).isEqualTo(expected);
}
}