Skip to content

Commit 6ea1993

Browse files
committed
Merge branch '3.5.x'
2 parents ebc9066 + c7f623a commit 6ea1993

File tree

20 files changed

+2713
-372
lines changed

20 files changed

+2713
-372
lines changed

examples/fit-example/07-http-client-proxy/plugin-http-client/src/main/java/modelengine/fit/example/client/TestAuthClient.java

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,86 +27,105 @@
2727
@HttpProxy
2828
@RequestAddress(protocol = "http", host = "localhost", port = "8080")
2929
@RequestMapping(path = "/http-server/auth")
30-
/**
31-
* 接口级别的默认鉴权:API Key
32-
*/
3330
@RequestAuth(type = AuthType.API_KEY, name = "X-Service-Key", value = "service-default-key")
3431
public interface TestAuthClient extends TestAuthInterface {
35-
@Override
36-
@GetMapping(path = "/bearer-static")
3732
/**
3833
* 方法级别覆盖:使用 Bearer Token
3934
*/
35+
@Override
36+
@GetMapping(path = "/bearer-static")
4037
@RequestAuth(type = AuthType.BEARER, value = "static-bearer-token-12345")
4138
String testBearerStatic();
4239

43-
@Override
44-
@GetMapping(path = "/bearer-dynamic")
4540
/**
4641
* 方法级别覆盖:使用参数驱动的 Bearer Token
4742
*/
43+
@Override
44+
@GetMapping(path = "/bearer-dynamic")
4845
String testBearerDynamic(@RequestAuth(type = AuthType.BEARER) String token);
4946

50-
@Override
51-
@GetMapping(path = "/basic-static")
5247
/**
5348
* 方法级别覆盖:使用 Basic Auth
5449
*/
50+
@Override
51+
@GetMapping(path = "/basic-static")
5552
@RequestAuth(type = AuthType.BASIC, username = "admin", password = "secret123")
5653
String testBasicStatic();
5754

58-
@Override
59-
@GetMapping(path = "/apikey-header-static")
6055
/**
6156
* 方法级别覆盖:API Key 在 Header 中
6257
*/
58+
@Override
59+
@GetMapping(path = "/apikey-header-static")
6360
@RequestAuth(type = AuthType.API_KEY, name = "X-API-Key", value = "static-api-key-67890")
6461
String testApiKeyHeaderStatic();
6562

66-
@Override
67-
@GetMapping(path = "/apikey-query-static")
6863
/**
6964
* 方法级别覆盖:API Key 在 Query 参数中
7065
*/
66+
67+
@Override
68+
@GetMapping(path = "/apikey-query-static")
7169
@RequestAuth(type = AuthType.API_KEY, name = "api_key", value = "query-api-key-111", location = Source.QUERY)
7270
String testApiKeyQueryStatic();
7371

74-
@Override
75-
@GetMapping(path = "/apikey-dynamic")
7672
/**
7773
* 参数驱动的 API Key
7874
*/
75+
@Override
76+
@GetMapping(path = "/apikey-dynamic")
7977
String testApiKeyDynamic(@RequestAuth(type = AuthType.API_KEY, name = "X-Dynamic-Key") String apiKey);
8078

81-
@Override
82-
@GetMapping(path = "/dynamic-provider")
8379
/**
8480
* 方法级别覆盖:使用动态 Token Provider
8581
*/
82+
@Override
83+
@GetMapping(path = "/dynamic-provider")
8684
@RequestAuth(type = AuthType.BEARER, provider = DynamicTokenProvider.class)
8785
String testDynamicProvider();
8886

89-
@Override
90-
@GetMapping(path = "/custom-provider")
9187
/**
9288
* 方法级别覆盖:使用自定义签名 Provider
9389
*/
90+
@Override
91+
@GetMapping(path = "/custom-provider")
9492
@RequestAuth(type = AuthType.CUSTOM, provider = CustomSignatureProvider.class)
9593
String testCustomProvider();
9694

97-
@Override
98-
@GetMapping(path = "/method-override")
9995
/**
10096
* 方法级别覆盖:使用 API Key Provider
10197
*/
98+
@Override
99+
@GetMapping(path = "/method-override")
102100
@RequestAuth(type = AuthType.API_KEY, provider = ApiKeyProvider.class)
103101
String testMethodOverride();
104102

105-
@Override
106-
@GetMapping(path = "/combined-auth")
107103
/**
108104
* 组合鉴权:服务级 API Key + 用户 Token
109105
*/
106+
@Override
107+
@GetMapping(path = "/combined-auth")
110108
@RequestAuth(type = AuthType.BEARER, provider = DynamicTokenProvider.class)
111109
String testCombinedAuth(@RequestAuth(type = AuthType.API_KEY, name = "X-User-Context") String userToken);
110+
111+
/**
112+
* 参数级别的 Basic Auth - 使用参数覆盖静态配置的 username
113+
* <p>演示:方法级别提供完整的 BASIC 认证(username + password),
114+
* 参数级别动态覆盖 username 字段(不指定 name 时默认更新 username)</p>
115+
*/
116+
@Override
117+
@GetMapping(path = "/basic-dynamic-username")
118+
@RequestAuth(type = AuthType.BASIC, username = "static-user", password = "static-password")
119+
String testBasicDynamicUsername(@RequestAuth(type = AuthType.BASIC) String username);
120+
121+
/**
122+
* 参数级别的 Basic Auth - 使用参数分别覆盖 username 和 password
123+
* <p>演示:方法级别提供完整的 BASIC 认证作为基础,
124+
* 参数级别使用 name 属性明确指定要覆盖的字段(username 或 password)</p>
125+
*/
126+
@Override
127+
@GetMapping(path = "/basic-dynamic-both")
128+
@RequestAuth(type = AuthType.BASIC, username = "base-user", password = "base-password")
129+
String testBasicDynamicBoth(@RequestAuth(type = AuthType.BASIC, name = "username") String username,
130+
@RequestAuth(type = AuthType.BASIC, name = "password") String password);
112131
}

examples/fit-example/07-http-client-proxy/plugin-http-client/src/main/java/modelengine/fit/example/client/TestAuthInterface.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,21 @@ public interface TestAuthInterface {
8686
* @return 鉴权测试结果
8787
*/
8888
String testCombinedAuth(String userToken);
89+
90+
/**
91+
* 测试参数级别的 Basic Auth - 单参数更新 username(向后兼容)。
92+
*
93+
* @param username 用户名
94+
* @return 鉴权测试结果
95+
*/
96+
String testBasicDynamicUsername(String username);
97+
98+
/**
99+
* 测试参数级别的 Basic Auth - 双参数分别更新 username 和 password。
100+
*
101+
* @param username 用户名
102+
* @param password 密码
103+
* @return 鉴权测试结果
104+
*/
105+
String testBasicDynamicBoth(String username, String password);
89106
}

examples/fit-example/07-http-client-proxy/plugin-http-client/src/main/java/modelengine/fit/example/controller/TestClientController.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,21 @@ public Object test(@RequestQuery("type") String type, @RequestQuery("method") St
104104
*/
105105
@GetMapping(path = "/auth-test")
106106
public Object authTest(@RequestQuery("method") String method,
107-
@RequestQuery(value = "token", required = false) String token) {
107+
@RequestQuery(value = "token", required = false) String token,
108+
@RequestQuery(value = "username", required = false) String username,
109+
@RequestQuery(value = "password", required = false) String password) {
108110
switch (method) {
109111
case "bearerStatic":
110112
return authClient.testBearerStatic();
111113
case "bearerDynamic":
112114
return authClient.testBearerDynamic(token != null ? token : "dynamic-test-token");
113115
case "basicStatic":
114116
return authClient.testBasicStatic();
117+
case "basicDynamicUsername":
118+
return authClient.testBasicDynamicUsername(username != null ? username : "testuser");
119+
case "basicDynamicBoth":
120+
return authClient.testBasicDynamicBoth(username != null ? username : "testuser",
121+
password != null ? password : "testpass");
115122
case "apiKeyHeaderStatic":
116123
return authClient.testApiKeyHeaderStatic();
117124
case "apiKeyQueryStatic":

examples/fit-example/07-http-client-proxy/plugin-http-server/src/main/java/modelengine/fit/example/controller/TestAuthServerController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,14 @@ public String testCombinedAuth(@RequestHeader(name = "Authorization") String aut
106106
}
107107
return result;
108108
}
109+
110+
@GetMapping(path = "/basic-dynamic-username")
111+
public String testBasicDynamicUsername(@RequestHeader(name = "Authorization") String authorization) {
112+
return "Basic Dynamic Username: " + authorization;
113+
}
114+
115+
@GetMapping(path = "/basic-dynamic-both")
116+
public String testBasicDynamicBoth(@RequestHeader(name = "Authorization") String authorization) {
117+
return "Basic Dynamic Both: " + authorization;
118+
}
109119
}

examples/fit-example/07-http-client-proxy/run_tests.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ run_basic_tests() {
174174
run_test "Basic Static Auth" \
175175
"curl -s --max-time $TIMEOUT -X GET \"$BASE_URL/basic-static\" -H \"Authorization: Basic YWRtaW46c2VjcmV0MTIz\" -H \"X-Service-Key: service-default-key\"" \
176176
"Basic Static Auth: Basic YWRtaW46c2VjcmV0MTIz"
177+
178+
# testuser:static-password 的 base64 编码 (dGVzdHVzZXI6c3RhdGljLXBhc3N3b3Jk)
179+
# 参数覆盖 username: testuser,保留方法级别的 password: static-password
180+
run_test "Basic Dynamic Username" \
181+
"curl -s --max-time $TIMEOUT -X GET \"$BASE_URL/basic-dynamic-username\" -H \"Authorization: Basic dGVzdHVzZXI6c3RhdGljLXBhc3N3b3Jk\"" \
182+
"Basic Dynamic Username: Basic dGVzdHVzZXI6c3RhdGljLXBhc3N3b3Jk"
183+
184+
# testuser:testpass 的 base64 编码 (dGVzdHVzZXI6dGVzdHBhc3M=)
185+
# 参数分别覆盖 username 和 password
186+
run_test "Basic Dynamic Both" \
187+
"curl -s --max-time $TIMEOUT -X GET \"$BASE_URL/basic-dynamic-both\" -H \"Authorization: Basic dGVzdHVzZXI6dGVzdHBhc3M=\"" \
188+
"Basic Dynamic Both: Basic dGVzdHVzZXI6dGVzdHBhc3M="
177189
}
178190

179191
# API Key 测试

framework/fit/java/fit-builtin/plugins/fit-client-http/src/main/java/modelengine/fit/client/http/support/HttpProxyCreator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void onBeanContainerInitialized(BeanContainer container) {
6767
}
6868
List<Class<?>> classes = this.scan(container, packages);
6969
for (Class<?> clazz : classes) {
70-
AnnotationParser annotationParser = new AnnotationParser(this.valueFetcher);
70+
AnnotationParser annotationParser = new AnnotationParser(this.valueFetcher, container);
7171
Map<Method, HttpInfo> httpInfoMap = annotationParser.parseInterface(clazz);
7272
// Scan all interfaces, create proxy objects for each, and register them in the container.
7373
container.registry()

0 commit comments

Comments
 (0)