Skip to content

Conversation

@CodeCasterX
Copy link
Member

@CodeCasterX CodeCasterX commented Sep 30, 2025

🔗 相关问题 / Related Issue

Issue 链接 / Issue Link: #327 👈👈

  • 我已经创建了相关 Issue 并进行了讨论 / I have created and discussed the related issue
  • 这是一个微小的修改(如错别字),不需要 Issue / This is a trivial change (like typo fix) that doesn't need an issue

📋 变更类型 / Type of Change

  • 🐛 Bug 修复 / Bug fix (non-breaking change which fixes an issue)
  • ✨ 新功能 / New feature (non-breaking change which adds functionality)
  • 💥 破坏性变更 / Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 文档更新 / Documentation update
  • 🔧 重构 / Refactoring (no functional changes)
  • ⚡ 性能优化 / Performance improvement
  • 📦 依赖升级 / Dependency upgrade (update dependencies to newer versions)
  • 🚀 功能增强 / Feature enhancement (improve existing functionality without breaking changes)
  • 🧹 代码清理 / Code cleanup

📝 变更目的 / Purpose of the Change

为 FIT Framework 的 HTTP 客户端添加全面的鉴权支持,通过注解方式提供多种鉴权方式的配置能力。

📋 主要变更 / Brief Changelog

核心功能

  • @requestauth 注解:支持接口、方法、参数三个级别的鉴权配置
  • 多种鉴权类型
    • Bearer Token 鉴权 (JWT等)
    • Basic 认证 (用户名/密码)
    • API Key 鉴权 (Header/Query/Cookie)
    • 自定义鉴权 (通过 AuthProvider)

架构组件

  • AuthType 枚举:定义支持的鉴权类型
  • AuthProvider 接口:支持动态鉴权逻辑
  • RequestAuthResolver:注解解析器
  • AuthDestinationSetter:请求鉴权信息设置器
  • StaticAuthApplier:静态鉴权信息应用器

特性亮点

  • 多级优先级:参数级 > 方法级 > 接口级
  • 静态/动态配置:支持编译时配置和运行时动态获取
  • 灵活位置:API Key 可放置在 Header、Query 参数或 Cookie
  • 无缝集成:与现有 Authorization 系统完全兼容

📋 更新日志

新增

  • HTTP 客户端鉴权注解支持
  • 多种鉴权类型实现
  • 完整的使用文档和测试用例
  • 批量测试脚本

修复

  • 修复 JavaDoc 中未闭合的 HTML <p> 标签

文档

  • AUTH_USAGE_GUIDE.md:完整使用指南
  • CURL_TEST_EXAMPLES.md:详细测试用例
  • run_tests.sh:功能测试脚本

🧪 验证变更 / Verifying this Change

测试步骤 / Test Steps

cd examples/fit-example/07-http-client-proxy
mvn clean install

功能测试

  1. 启动测试服务器
    ./run_tests.sh

  2. 或分类测试
    ./run_tests.sh bearer # Bearer Token 测试
    ./run_tests.sh basic # Basic Auth 测试
    ./run_tests.sh apikey # API Key 测试
    ./run_tests.sh provider # Provider 测试

  3. 验证要点

  • 各种鉴权类型正常工作
  • 多级优先级规则正确
  • 静态和动态配置均可用
  • 错误处理和异常场景
  • 文档示例可执行

测试覆盖 / Test Coverage

  • 我已经添加了单元测试 / I have added unit tests
  • 所有现有测试都通过 / All existing tests pass
  • 我已经进行了手动测试 / I have performed manual testing

📸 截图 / Screenshots

✅ 贡献者检查清单 / Contributor Checklist

请确保你的 Pull Request 符合以下要求 / Please ensure your Pull Request meets the following requirements:

基本要求 / Basic Requirements:

  • 确保有 GitHub Issue 对应这个变更(微小变更如错别字除外)/ Make sure there is a Github issue filed for the change (trivial changes like typos excluded)
  • 你的 Pull Request 只解决一个 Issue,没有包含其他不相关的变更 / Your PR addresses just this issue, without pulling in other changes - one PR resolves one issue
  • PR 中的每个 commit 都有有意义的主题行和描述 / Each commit in the PR has a meaningful subject line and body

代码质量 / Code Quality:

  • 我的代码遵循项目的代码规范 / My code follows the project's coding standards
  • 我已经进行了自我代码审查 / I have performed a self-review of my code
  • 我已经为复杂的代码添加了必要的注释 / I have commented my code, particularly in hard-to-understand areas

测试要求 / Testing Requirements:

  • 我已经编写了必要的单元测试来验证逻辑正确性 / I have written necessary unit-tests to verify the logic correction
  • 当存在跨模块依赖时,我尽量使用了 mock / I have used mocks when cross-module dependencies exist
  • 基础检查通过:mvn -B clean package -Dmaven.test.skip=true,elsa README 中的编译检查 / Basic checks pass
  • 单元测试通过:mvn clean install / Unit tests pass

文档和兼容性 / Documentation and Compatibility:

  • 我已经更新了相应的文档 / I have made corresponding changes to the documentation
  • 如果有破坏性变更,我已经在 PR 描述中详细说明 / If there are breaking changes, I have documented them in detail
  • 我已经考虑了向后兼容性 / I have considered backward compatibility

📋 附加信息 / Additional Notes


审查者注意事项 / Reviewer Notes:

CodeCasterX and others added 2 commits September 30, 2025 00:27
Implement @requestauth annotation with multi-level authentication support for
HTTP client proxy interfaces. The new authentication system supports Bearer tokens,
Basic auth, API keys, and custom authentication providers.

Key Features:
- @requestauth annotation with support for interface, method, and parameter levels
- Multiple auth types: BEARER, BASIC, API_KEY, CUSTOM
- Static configuration and dynamic AuthProvider support
- Flexible parameter locations: HEADER, QUERY, COOKIE
- Priority system: parameter > method > interface level
- Seamless integration with existing Authorization system

Implementation:
- AuthType enum defining supported authentication types
- AuthProvider interface for dynamic authentication
- RequestAuthResolver for annotation parsing
- AuthDestinationSetter for request building integration
- StaticAuthApplier for class/method level static auth
- Extended AnnotationParser to handle multi-level auth annotations

Examples and Tests:
- TestAuthClient demonstrating various auth scenarios
- AuthProvider examples: DynamicTokenProvider, ApiKeyProvider, CustomSignatureProvider
- Server-side TestAuthServerController for auth validation
- Comprehensive unit tests for resolver and setter components
- Updated TestClientController with auth testing endpoints

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Close all unclosed <p> tags in JavaDoc comments to ensure proper HTML validation
and documentation rendering. This improves code documentation quality and
maintains consistent JavaDoc formatting standards.

Changes:
- Fixed unclosed <p> tags in RequestAuth annotation
- Fixed unclosed <p> tags in AuthType enum
- Fixed unclosed <p> tags in AuthProvider interface
- Fixed unclosed <p> tags in RequestAuthResolver class
- Fixed unclosed <p> tags in StaticAuthApplier class
- Fixed unclosed <p> tags in AuthDestinationSetter class
- Fixed unclosed <p> tags in TestAuthServerController class
- Removed OPTIMIZATION_SUMMARY.md file as requested

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@CodeCasterX CodeCasterX changed the title 增加 Http 客户端调用时鉴权的注解模式 [fit] Add comprehensive HTTP client authentication support Sep 30, 2025
CodeCasterX and others added 2 commits September 30, 2025 11:22
Fix the server connectivity check in run_tests.sh to use an actual existing
endpoint instead of the non-existent root path. The script was trying to
access /http-server/auth which doesn't exist on the server, causing
HttpHandlerNotFoundException errors.

Changes:
- Modified check_server() function to use /bearer-static endpoint for connectivity check
- Added HEAD request (-I flag) to avoid unnecessary response body processing
- Prevents false server connection failures during test execution

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove the complex server connectivity check that was causing HTTP handler
not found errors. The script now directly proceeds to actual testing, which
will naturally fail with clear error messages if the server is not running.

Changes:
- Replaced check_server() with simple show_server_info() function
- Removed all network probing logic (nc, telnet, curl connectivity tests)
- Simplified startup - script now shows server info and proceeds to tests
- Tests themselves will indicate if server is unreachable with clearer errors

This approach is more reliable and avoids accessing non-existent endpoints
that trigger HttpHandlerNotFoundException in the server logs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@CodeCasterX CodeCasterX requested review from a team and desAweis and removed request for a team September 30, 2025 04:29
@CodeCasterX CodeCasterX self-assigned this Sep 30, 2025
@CodeCasterX CodeCasterX added in: fit Issues in FIT modules type: feature A general feature labels Sep 30, 2025
@CodeCasterX CodeCasterX added this to the 3.5.4 milestone Sep 30, 2025
@CodeCasterX CodeCasterX added type: enhancement A general enhancement and removed type: feature A general feature labels Sep 30, 2025
@CodeCasterX CodeCasterX merged commit 356190c into 3.5.x Sep 30, 2025
6 checks passed
@CodeCasterX CodeCasterX deleted the fit-enhancement-http-client2 branch September 30, 2025 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: fit Issues in FIT modules type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[fit] Add comprehensive HTTP client authentication support with @RequestAuth annotation

1 participant