feat: login history and lockout rule in services-system

LoginSecurityService derives the admin lock from login_audit and the
ADMIN_LOGIN_BLOCK settings; /loginSecurity exposes lock check, record,
history, locked list, unlock, lockout settings and password rules. The
gateway routes /loginSecurity/** and lets the lock check and record
through without a user token for the sign-in path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-11-30 13:26:20 +08:00
1 parent a0146be325
commit f7ec74c7f0
11 files changed
+1074 -2

No files matched your search

@@ -133,6 +133,9 @@ public class JWTAuthFilter implements GlobalFilter, Ordered {
|| url.contains("/member/forgetPassword")
// Co-Lite admin forgot password (public; answers the same whether or not details match)
|| url.equals("/user/resetAdminPassword")
// Co-Lite admin sign-in: lock check and its recording run before the user has a token
|| (url.matches("/loginSecurity/isLocked/[^/]+") && !url.contains(".."))
|| url.equals("/loginSecurity/record")
|| url.contains("/geoLocationHierarchy/findByFirstLevelLocation")
|| url.contains("/geoLocationHierarchy/findAllByParentId")
// public content - no JWT required
@@ -148,6 +148,10 @@ spring:
uri: http://${app.services.name.system}
predicates:
- Path=/blockLoginPeriod/**
- id: loginSecurity
uri: http://${app.services.name.system}
predicates:
- Path=/loginSecurity/**
- id: passwordAging
uri: http://${app.services.name.system}
predicates:
@@ -0,0 +1,82 @@
package com.solvway.gateway.filter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.solvway.gateway.model.AuthAppKey;
import com.solvway.gateway.model.AuthAppKeyMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.http.HttpStatus;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange;
import org.springframework.test.util.ReflectionTestUtils;
import reactor.core.publisher.Mono;
import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.assertj.core.api.Assertions.assertThat;
/** The admin sign-in lock check and its recording run before the user has a token; the rest of /loginSecurity needs one. */
class JWTAuthFilterLoginSecurityPathTest {
private static final String KEY = "gateway-test-key";
private JWTAuthFilter filter;
@BeforeEach
void setUp() throws Exception {
// Built the way AuthAppKeyConfig loads appkeys.json (the constructor is not public).
AuthAppKey key = new ObjectMapper().readValue(
"{\"key\":\"" + KEY + "\",\"type\":\"BO\",\"ipList\":[\"0.0.0.0/0\"],\"allowList\":[\"/\"]}",
AuthAppKey.class);
AuthAppKeyMap map = new AuthAppKeyMap();
map.add(KEY, key);
filter = new JWTAuthFilter();
ReflectionTestUtils.setField(filter, "authAppKeyMap", map);
}
private MockServerWebExchange post(String path) {
return MockServerWebExchange.from(MockServerHttpRequest.post(path)
.header("api-key", KEY)
.remoteAddress(new InetSocketAddress("127.0.0.1", 40000)));
}
private MockServerWebExchange get(String path) {
return MockServerWebExchange.from(MockServerHttpRequest.get(path)
.header("api-key", KEY)
.remoteAddress(new InetSocketAddress("127.0.0.1", 40000)));
}
private boolean passes(MockServerWebExchange exchange) {
AtomicBoolean called = new AtomicBoolean(false);
GatewayFilterChain chain = ex -> {
called.set(true);
return Mono.empty();
};
filter.filter(exchange, chain).block();
return called.get();
}
@Test
void lockCheckNeedsNoUserToken() {
assertThat(passes(get("/loginSecurity/isLocked/sales1"))).isTrue();
}
@Test
void recordNeedsNoUserToken() {
assertThat(passes(post("/loginSecurity/record"))).isTrue();
}
@Test
void otherLoginSecurityEndpointsStillNeedAToken() {
for (MockServerWebExchange exchange : new MockServerWebExchange[] {
post("/loginSecurity/unlock"), get("/loginSecurity/locked"), post("/loginSecurity/config"),
post("/loginSecurity/audit"), post("/loginSecurity/passwordRules"),
post("/loginSecurity/record/../unlock"), get("/x/loginSecurity/isLocked/a"), get("/loginSecurity/isLocked/../locked"),
get("/loginSecurity/isLocked/a/b") }) {
assertThat(passes(exchange)).isFalse();
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
}
}