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