Skip to content

fix: maven构建失败#5872

Merged
KouShenhai merged 1 commit intomasterfrom
dev
Mar 15, 2026
Merged

fix: maven构建失败#5872
KouShenhai merged 1 commit intomasterfrom
dev

Conversation

@KouShenhai
Copy link
Owner

@KouShenhai KouShenhai commented Mar 15, 2026

Summary by Sourcery

为授权码认证流程添加验证码校验支持,并修复相关的 Maven 构建问题。

新功能:

  • 在授权码认证请求和验证逻辑中加入验证码信息。

缺陷修复:

  • 确保授权码认证测试覆盖验证码校验和必需参数检查,以防止构建/测试失败。
  • mybatis-plus-boot-starter 中排除有冲突的 mybatis-spring 依赖,以解决 Maven 构建错误。

改进:

  • 优化授权码认证测试的描述,使其更加清晰。
  • 在授权码认证参数处理中复用现有的验证码提取逻辑。
Original summary in English

Summary by Sourcery

Add captcha validation support to authorization code authentication flow and fix related Maven build issues.

New Features:

  • Include captcha information in authorization code authentication requests and validation logic.

Bug Fixes:

  • Ensure authorization code authentication test covers captcha validation and required parameter checks to prevent build/test failures.
  • Exclude conflicting mybatis-spring dependency from the mybatis-plus-boot-starter to resolve Maven build errors.

Enhancements:

  • Refine authorization code authentication test descriptions for clarity.
  • Reuse existing captcha extraction logic for authorization code authentication parameters.

Summary by CodeRabbit

  • New Features
    • Enhanced authorization code authentication with mandatory CAPTCHA verification to improve security by validating UUID and CAPTCHA parameters during login.

@netlify
Copy link

netlify bot commented Mar 15, 2026

Deploy Preview for kcloud-platform-iot ready!

Name Link
🔨 Latest commit c70a68a
🔍 Latest deploy log https://app.netlify.com/projects/kcloud-platform-iot/deploys/69b69a0a41d3470008ca240a
😎 Deploy Preview https://deploy-preview-5872--kcloud-platform-iot.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 15, 2026

审阅者指南

为 authorization-code(授权码)认证流程及其测试添加验证码校验支持,将 CaptchaV 接入该授权方式对应的 AuthA 中,更新 authorization-code 认证的测试夹具和模拟对象以包含 UUID/captcha,并通过在 mybatis-plus-boot-starter 依赖中排除 mybatis-spring 来修复 Maven 构建问题。

带验证码校验的 authorization-code 认证时序图

sequenceDiagram
  actor Client
  participant AuthService
  participant AuthA
  participant AuthParamValidator as AuthorizationCodeAuthParamValidator
  participant ParamValidator
  participant OAuth2ParamValidator

  Client->>AuthService: send authorization_code auth request
  AuthService->>AuthA: createAuthorizationCodeAuth()
  activate AuthA
  AuthA->>AuthA: getCaptchaVByAuthorizationCodeAuth()
  AuthA->>AuthA: getCaptchaVByUsernamePasswordAuth()
  AuthA->>AuthA: getParameterValue(Constants.UUID)
  AuthA-->>AuthA: uuid
  AuthA->>AuthA: getParameterValue(Constants.CAPTCHA)
  AuthA-->>AuthA: captcha
  AuthA-->>AuthService: AuthA with grantType AUTHORIZATION_CODE, userV, captchaV
  deactivate AuthA

  AuthService->>AuthParamValidator: validateAuth(authA)
  activate AuthParamValidator
  AuthParamValidator->>AuthA: getUserV()
  AuthA-->>AuthParamValidator: userV
  AuthParamValidator->>AuthA: getCaptchaV()
  AuthA-->>AuthParamValidator: captchaV

  AuthParamValidator->>ParamValidator: validate(validateName, ...validators)
  activate ParamValidator
  ParamValidator->>OAuth2ParamValidator: validateTenantCode(userV.tenantCode())
  OAuth2ParamValidator-->>ParamValidator: tenantCodeValid
  ParamValidator->>OAuth2ParamValidator: validateUuid(captchaV.uuid())
  OAuth2ParamValidator-->>ParamValidator: uuidValid
  ParamValidator->>OAuth2ParamValidator: validateCaptcha(captchaV.captcha())
  OAuth2ParamValidator-->>ParamValidator: captchaValid
  ParamValidator->>OAuth2ParamValidator: validateUsername(userV.username())
  OAuth2ParamValidator-->>ParamValidator: usernameValid
  ParamValidator->>OAuth2ParamValidator: validatePassword(userV.password())
  OAuth2ParamValidator-->>ParamValidator: passwordValid
  ParamValidator-->>AuthParamValidator: validationResult
  deactivate ParamValidator

  AuthParamValidator-->>AuthService: success or error
  deactivate AuthParamValidator
  AuthService-->>Client: auth success or failure
Loading

更新后的 AuthA 在 authorization-code 场景下处理验证码的类图

classDiagram
  class AuthA {
    +GrantType grantType
    +UserV userV
    +CaptchaV captchaV
    +AuthA createAuthorizationCodeAuth()
    -CaptchaV getCaptchaVByAuthorizationCodeAuth()
    -CaptchaV getCaptchaVByUsernamePasswordAuth()
  }

  class UserV {
    +String tenantCode()
    +String username()
    +String password()
  }

  class CaptchaV {
    +String uuid()
    +String captcha()
  }

  class AuthorizationCodeAuthParamValidator {
    +void validateAuth(AuthA authA)
  }

  class ParamValidator {
    +void validate(String validateName, Object validator1, Object validator2, Object validator3, Object validator4, Object validator5)
  }

  class OAuth2ParamValidator {
    +Object validateTenantCode(String tenantCode)
    +Object validateUuid(String uuid)
    +Object validateCaptcha(String captcha)
    +Object validateUsername(String username)
    +Object validatePassword(String password)
  }

  AuthA *-- UserV
  AuthA *-- CaptchaV

  AuthorizationCodeAuthParamValidator ..> AuthA
  AuthorizationCodeAuthParamValidator ..> ParamValidator
  AuthorizationCodeAuthParamValidator ..> OAuth2ParamValidator
Loading

文件级变更

变更 详情 文件
扩展 authorization-code 认证参数及领域模型以包含 captcha/UUID,并对其进行校验。
  • 更新 AuthorizationCodAuthParam 记录,在现有 username/password/tenantCode/grantType 字段基础上新增 uuid 和 captcha 字段
  • 调整构造 AuthorizationCodAuthParam 的工厂方法,在调用时传入新的 uuid 和 captcha 参数或使用 null 占位符
  • 在 AuthA 中创建 authorization-code 认证时,通过复用用户名/密码场景的验证码提取逻辑来设置 captchaV
  • 在 AuthA 中新增辅助方法,通过共享的参数提取代码获取 authorization-code 授权方式的 CaptchaV
laokou-service/laokou-auth/laokou-auth-domain/src/test/java/org/laokou/auth/model/DomainServiceTest.java
laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java
增强 authorization-code 认证的校验与测试,覆盖 captcha/UUID,并与 HTTP 参数映射保持一致。
  • 更新 AuthorizationCodeAuthParamValidator,从 AuthA 中读取 CaptchaV,并使用 OAuth2ParamValidator 校验 UUID 和 captcha
  • 在 DomainServiceTest 的 mock 设置中,为 authorization-code 认证将 UUID 和 CAPTCHA 参数填充到 HTTP 请求参数 Map 中
  • 扩展 authorizationCodeAuthParamValidator 的测试替身,使其同时校验 CaptchaV 字段,并在 uuid/captcha 为空时抛出异常
  • 对 captchaValidator.validateCaptcha 进行存根以保证其校验成功,并在 authorization-code 认证成功测试中校验它是以预期的 Redis key 和 captcha 被调用的
  • 调整相关测试上的 @DisplayName,使其表述通用的 authorization-code 认证,而不是密码特定的措辞
laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/service/validator/AuthorizationCodeAuthParamValidator.java
laokou-service/laokou-auth/laokou-auth-domain/src/test/java/org/laokou/auth/model/DomainServiceTest.java
通过在 mybatis-plus-boot-starter 依赖中排除 mybatis-spring,解决 Maven 构建冲突。
  • 在 mybatis-plus 模块的 POM 中,为 mybatis-plus-boot-starter 依赖添加 org.mybatis:mybatis-spring 的排除配置,以避免版本冲突或类重复
laokou-common/laokou-common-mybatis-plus/pom.xml

技巧与命令

与 Sourcery 交互

  • 触发新评审: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的评审评论。
  • 从评审评论生成 GitHub Issue: 在评审评论下回复,请求 Sourcery 从该评论创建 Issue。你也可以直接回复 @sourcery-ai issue 来从该评论创建 Issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中任意位置写上 @sourcery-ai,可随时生成标题。你也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 正文任意位置写上 @sourcery-ai summary,即可在该位置生成 PR 摘要。你也可以在 Pull Request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide,可随时(重新)生成审阅者指南。
  • 一键解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,将所有 Sourcery 评论标记为已解决。如果你已经处理完所有评论且不想再看到它们,这会非常有用。
  • 清除所有 Sourcery 评审: 在 Pull Request 中评论 @sourcery-ai dismiss,清除所有已有的 Sourcery 评审。若你想从一次全新的评审开始,尤其适合;别忘了再评论 @sourcery-ai review 触发新评审!

自定义你的体验

打开你的 控制面板 以:

  • 启用或禁用评审功能,例如 Sourcery 自动生成的 Pull Request 摘要、审阅者指南等。
  • 更改评审语言。
  • 添加、删除或编辑自定义评审说明。
  • 调整其他评审设置。

获取帮助

Original review guide in English

Reviewer's Guide

Adds captcha validation support to authorization-code authentication flow and its tests, wires CaptchaV into AuthA for this grant type, updates the authorization-code auth test fixtures and mocks to include UUID/captcha, and fixes a Maven build issue by excluding mybatis-spring from the mybatis-plus-boot-starter dependency.

Sequence diagram for authorization-code auth with captcha validation

sequenceDiagram
  actor Client
  participant AuthService
  participant AuthA
  participant AuthParamValidator as AuthorizationCodeAuthParamValidator
  participant ParamValidator
  participant OAuth2ParamValidator

  Client->>AuthService: send authorization_code auth request
  AuthService->>AuthA: createAuthorizationCodeAuth()
  activate AuthA
  AuthA->>AuthA: getCaptchaVByAuthorizationCodeAuth()
  AuthA->>AuthA: getCaptchaVByUsernamePasswordAuth()
  AuthA->>AuthA: getParameterValue(Constants.UUID)
  AuthA-->>AuthA: uuid
  AuthA->>AuthA: getParameterValue(Constants.CAPTCHA)
  AuthA-->>AuthA: captcha
  AuthA-->>AuthService: AuthA with grantType AUTHORIZATION_CODE, userV, captchaV
  deactivate AuthA

  AuthService->>AuthParamValidator: validateAuth(authA)
  activate AuthParamValidator
  AuthParamValidator->>AuthA: getUserV()
  AuthA-->>AuthParamValidator: userV
  AuthParamValidator->>AuthA: getCaptchaV()
  AuthA-->>AuthParamValidator: captchaV

  AuthParamValidator->>ParamValidator: validate(validateName, ...validators)
  activate ParamValidator
  ParamValidator->>OAuth2ParamValidator: validateTenantCode(userV.tenantCode())
  OAuth2ParamValidator-->>ParamValidator: tenantCodeValid
  ParamValidator->>OAuth2ParamValidator: validateUuid(captchaV.uuid())
  OAuth2ParamValidator-->>ParamValidator: uuidValid
  ParamValidator->>OAuth2ParamValidator: validateCaptcha(captchaV.captcha())
  OAuth2ParamValidator-->>ParamValidator: captchaValid
  ParamValidator->>OAuth2ParamValidator: validateUsername(userV.username())
  OAuth2ParamValidator-->>ParamValidator: usernameValid
  ParamValidator->>OAuth2ParamValidator: validatePassword(userV.password())
  OAuth2ParamValidator-->>ParamValidator: passwordValid
  ParamValidator-->>AuthParamValidator: validationResult
  deactivate ParamValidator

  AuthParamValidator-->>AuthService: success or error
  deactivate AuthParamValidator
  AuthService-->>Client: auth success or failure
Loading

Class diagram for updated AuthA authorization-code captcha handling

classDiagram
  class AuthA {
    +GrantType grantType
    +UserV userV
    +CaptchaV captchaV
    +AuthA createAuthorizationCodeAuth()
    -CaptchaV getCaptchaVByAuthorizationCodeAuth()
    -CaptchaV getCaptchaVByUsernamePasswordAuth()
  }

  class UserV {
    +String tenantCode()
    +String username()
    +String password()
  }

  class CaptchaV {
    +String uuid()
    +String captcha()
  }

  class AuthorizationCodeAuthParamValidator {
    +void validateAuth(AuthA authA)
  }

  class ParamValidator {
    +void validate(String validateName, Object validator1, Object validator2, Object validator3, Object validator4, Object validator5)
  }

  class OAuth2ParamValidator {
    +Object validateTenantCode(String tenantCode)
    +Object validateUuid(String uuid)
    +Object validateCaptcha(String captcha)
    +Object validateUsername(String username)
    +Object validatePassword(String password)
  }

  AuthA *-- UserV
  AuthA *-- CaptchaV

  AuthorizationCodeAuthParamValidator ..> AuthA
  AuthorizationCodeAuthParamValidator ..> ParamValidator
  AuthorizationCodeAuthParamValidator ..> OAuth2ParamValidator
Loading

File-Level Changes

Change Details Files
Extend authorization-code auth parameter and domain model to include captcha/UUID and validate them.
  • Update AuthorizationCodAuthParam record to carry uuid and captcha fields in addition to existing username/password/tenantCode/grantType
  • Adjust factory methods that construct AuthorizationCodAuthParam to pass new uuid and captcha arguments or null placeholders
  • In AuthA, set captchaV when creating authorization-code authentication by reusing the username/password captcha extraction logic
  • Introduce a helper in AuthA to get CaptchaV for authorization-code grant using shared parameter-extraction code
laokou-service/laokou-auth/laokou-auth-domain/src/test/java/org/laokou/auth/model/DomainServiceTest.java
laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java
Strengthen validation and tests for authorization-code auth to cover captcha/UUID and align HTTP parameter mapping.
  • Update AuthorizationCodeAuthParamValidator to read CaptchaV from AuthA and validate UUID and captcha using OAuth2ParamValidator
  • Expand mock setup in DomainServiceTest to populate UUID and CAPTCHA parameters into the HTTP request parameter map for authorization-code auth
  • Extend authorizationCodeAuthParamValidator test double to also validate CaptchaV fields and throw on empty uuid/captcha
  • Stub captchaValidator.validateCaptcha to succeed and verify it is invoked with the expected Redis key and captcha in the authorization-code auth success test
  • Adjust @DisplayName in the relevant test to reflect generic authorization-code auth rather than password-specific wording
laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/service/validator/AuthorizationCodeAuthParamValidator.java
laokou-service/laokou-auth/laokou-auth-domain/src/test/java/org/laokou/auth/model/DomainServiceTest.java
Resolve Maven build conflict by excluding mybatis-spring from the mybatis-plus-boot-starter dependency.
  • Add an exclusion for the org.mybatis:mybatis-spring artifact under the mybatis-plus-boot-starter dependency in the mybatis-plus module POM to avoid conflicting versions or duplicate classes
laokou-common/laokou-common-mybatis-plus/pom.xml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@KouShenhai KouShenhai merged commit 02da966 into master Mar 15, 2026
12 of 16 checks passed
@qodo-code-review
Copy link

Review Summary by Qodo

Add captcha validation to authorization code auth and fix Maven build

🐞 Bug fix 🧪 Tests

Grey Divider

Walkthroughs

Description
• Add captcha validation to authorization code auth flow
  - Import CaptchaV and extract captcha from auth parameters
  - Validate UUID and captcha in AuthorizationCodeAuthParamValidator
  - Initialize captcha in createAuthorizationCodeAuth() method
• Fix Maven build by excluding mybatis-spring dependency conflict
  - Add exclusion for org.mybatis:mybatis-spring in dynamic-datasource dependency
• Update test cases to verify captcha validation
  - Add captcha validator mock verification in authorization code auth test
  - Update AuthorizationCodAuthParam record to include UUID and captcha fields
Diagram
flowchart LR
  A["Authorization Code Auth"] -->|Extract| B["CaptchaV"]
  B -->|Validate| C["UUID & Captcha"]
  C -->|Pass| D["Auth Success"]
  E["Maven Dependency"] -->|Exclude| F["mybatis-spring"]
  F -->|Resolve| G["Build Success"]
Loading

Grey Divider

File Changes

1. laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/service/validator/AuthorizationCodeAuthParamValidator.java ✨ Enhancement +6/-0

Add captcha validation to authorization code auth

• Import CaptchaV value object
• Extract captcha from auth parameters in validateAuth() method
• Add validation for UUID and captcha fields alongside existing tenant code validation

laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/service/validator/AuthorizationCodeAuthParamValidator.java


2. laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java ✨ Enhancement +5/-0

Initialize captcha for authorization code auth

• Initialize captchaV in createAuthorizationCodeAuth() method
• Add new private method getCaptchaVByAuthorizationCodeAuth() that delegates to username-password
 auth captcha extraction

laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java


3. laokou-service/laokou-auth/laokou-auth-domain/src/test/java/org/laokou/auth/model/DomainServiceTest.java 🧪 Tests +18/-4

Update tests for captcha validation in authorization code auth

• Update test display name from "password auth" to "auth"
• Add captcha validator mock verification in authorization code auth test
• Update AuthorizationCodAuthParam record constructor to include UUID and captcha parameters
• Add UUID and captcha to mock parameter map in createAuthorizationCodeAuthInfo()
• Add captcha validator mock setup to return true
• Update empty auth parameter test to include null UUID and captcha

laokou-service/laokou-auth/laokou-auth-domain/src/test/java/org/laokou/auth/model/DomainServiceTest.java


View more (1)
4. laokou-common/laokou-common-mybatis-plus/pom.xml 🐞 Bug fix +4/-0

Exclude mybatis-spring dependency to fix Maven build

• Add exclusion for org.mybatis:mybatis-spring in dynamic-datasource-spring-boot4-starter
 dependency
• Resolves Maven build failure caused by dependency conflict

laokou-common/laokou-common-mybatis-plus/pom.xml


Grey Divider

Qodo Logo

@qodo-code-review
Copy link

qodo-code-review bot commented Mar 15, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Captcha endpoint mismatch 🐞 Bug ✓ Correctness
Description
Authorization-code login now validates captcha using the AUTHORIZATION_CODE captcha cache key, but
the /login page still fetches captcha images from the username-password captcha endpoint/key, so the
user-entered captcha will not match the key checked during authentication and login will fail.
Code

laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/service/validator/AuthorizationCodeAuthParamValidator.java[R41-48]

+		CaptchaV captchaV = authA.getCaptchaV();
		ParamValidator.validate(authA.getValidateName(),
				// 校验租户编码
				OAuth2ParamValidator.validateTenantCode(userV.tenantCode()),
+				// 校验UUID
+				OAuth2ParamValidator.validateUuid(captchaV.uuid()),
+				// 校验验证码
+				OAuth2ParamValidator.validateCaptcha(captchaV.captcha()),
Evidence
The PR makes authorization-code authentication require UUID+captcha (new param validation) and the
backend verifies captcha using the authorization-code Redis key. However, the login UI still
requests the captcha from the username-password endpoint which uses a different Redis key prefix, so
the captcha retrieved/shown to the user will be stored under a different key than the one used for
authorization-code validation, causing consistent captcha validation failures.

laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/service/validator/AuthorizationCodeAuthParamValidator.java[39-52]
laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java[324-334]
laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java[393-400]
laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/web/CaptchasController.java[49-65]
laokou-common/laokou-common-i18n/src/main/java/org/laokou/common/i18n/util/RedisKeyUtils.java[32-42]
laokou-service/laokou-auth/laokou-auth-start/src/main/resources/templates/login.html[181-190]
laokou-service/laokou-auth/laokou-auth-start/src/main/resources/templates/login.html[257-267]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Authorization-code login now validates captcha against `auth:authorization-code:captcha:<uuid>`, but the login page loads captcha images from `/api/v1/username-password/captchas/{uuid}` (key `auth:username-password:captcha:<uuid>`). This key mismatch causes captcha validation failures and blocks `/login`.

## Issue Context
Backend:
- `AuthA.getCaptchaCacheKeyByAuth()` uses `RedisKeyUtils.getAuthorizationCodeAuthCaptchaKey` for `GrantType.AUTHORIZATION_CODE`.
- `CaptchasController` exposes `/v1/authorization-code/captchas/{uuid}` that reads the same key.

Frontend (login template):
- Still calls `/api/v1/username-password/captchas/{uuid}` in both the fallback form image and Vue refresh logic.

## Fix Focus Areas
- laokou-service/laokou-auth/laokou-auth-start/src/main/resources/templates/login.html[181-193]
- laokou-service/laokou-auth/laokou-auth-start/src/main/resources/templates/login.html[257-271]

## Expected change
- Replace `/api/v1/username-password/captchas/` with `/api/v1/authorization-code/captchas/` in:
 - the `<img th:src=...>` and its `onclick` handler
 - the Vue `refreshCaptcha()` fetch URL
- (Optional) Update any UI labels/help text if they refer specifically to “username-password captcha”.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 774f18c8-f732-4c60-a6d7-423d06346dcc

📥 Commits

Reviewing files that changed from the base of the PR and between f85141f and c70a68a.

📒 Files selected for processing (4)
  • laokou-common/laokou-common-mybatis-plus/pom.xml
  • laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/service/validator/AuthorizationCodeAuthParamValidator.java
  • laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java
  • laokou-service/laokou-auth/laokou-auth-domain/src/test/java/org/laokou/auth/model/DomainServiceTest.java

Walkthrough

This pull request adds captcha validation support to the authorization code authentication flow. Changes include a pom.xml exclusion to prevent transitive mybatis-spring dependency, updates to the validator and domain model to retrieve and validate captcha/UUID during authorization code authentication, and corresponding test updates with a modified constructor signature.

Changes

Cohort / File(s) Summary
Dependency Configuration
laokou-common/laokou-common-mybatis-plus/pom.xml
Adds exclusion for org.mybatis:mybatis-spring in dynamic-datasource-spring-boot4-starter dependency to prevent transitive import.
Captcha Validation Integration
laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/service/validator/AuthorizationCodeAuthParamValidator.java
Adds captcha validation by retrieving CaptchaV from AuthA and invoking OAuth2ParamValidator for UUID and CAPTCHA validation in authorization code flow.
Domain Model Enhancement
laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java
Adds new private helper method getCaptchaVByAuthorizationCodeAuth() and initializes captchaV in createAuthorizationCodeAuth() to support captcha retrieval for authorization code authentication.
Test Updates
laokou-service/laokou-auth/laokou-auth-domain/src/test/java/org/laokou/auth/model/DomainServiceTest.java
Updates authorization code flow tests to include UUID and captcha validation; modifies AuthorizationCodAuthParam constructor signature from (username, password, tenantCode, grantType) to (uuid, captcha, username, password, tenantCode, grantType).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Review effort 2/5

Poem

🐰 A captcha guard now stands so tall,
In auth flows, protecting all,
UUID and codes now dance in tune,
The security spring arrives quite soon! 🌱

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.16.4)
laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/service/validator/AuthorizationCodeAuthParamValidator.java

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m

laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m

laokou-service/laokou-auth/laokou-auth-domain/src/test/java/org/laokou/auth/model/DomainServiceTest.java

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出了一些总体反馈:

  • AuthA 中新的 getCaptchaVByAuthorizationCodeAuth 方法只是简单地代理到 getCaptchaVByUsernamePasswordAuth;建议内联这次调用,直接使用已有方法,以避免额外的一层间接调用。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- The new `getCaptchaVByAuthorizationCodeAuth` method in `AuthA` is just delegating to `getCaptchaVByUsernamePasswordAuth`; consider inlining this call and using the existing method directly to avoid an extra indirection.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享给更多人 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • The new getCaptchaVByAuthorizationCodeAuth method in AuthA is just delegating to getCaptchaVByUsernamePasswordAuth; consider inlining this call and using the existing method directly to avoid an extra indirection.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `getCaptchaVByAuthorizationCodeAuth` method in `AuthA` is just delegating to `getCaptchaVByUsernamePasswordAuth`; consider inlining this call and using the existing method directly to avoid an extra indirection.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sonarqubecloud
Copy link

Comment on lines +41 to +48
CaptchaV captchaV = authA.getCaptchaV();
ParamValidator.validate(authA.getValidateName(),
// 校验租户编码
OAuth2ParamValidator.validateTenantCode(userV.tenantCode()),
// 校验UUID
OAuth2ParamValidator.validateUuid(captchaV.uuid()),
// 校验验证码
OAuth2ParamValidator.validateCaptcha(captchaV.captcha()),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Captcha endpoint mismatch 🐞 Bug ✓ Correctness

Authorization-code login now validates captcha using the AUTHORIZATION_CODE captcha cache key, but
the /login page still fetches captcha images from the username-password captcha endpoint/key, so the
user-entered captcha will not match the key checked during authentication and login will fail.
Agent Prompt
## Issue description
Authorization-code login now validates captcha against `auth:authorization-code:captcha:<uuid>`, but the login page loads captcha images from `/api/v1/username-password/captchas/{uuid}` (key `auth:username-password:captcha:<uuid>`). This key mismatch causes captcha validation failures and blocks `/login`.

## Issue Context
Backend:
- `AuthA.getCaptchaCacheKeyByAuth()` uses `RedisKeyUtils.getAuthorizationCodeAuthCaptchaKey` for `GrantType.AUTHORIZATION_CODE`.
- `CaptchasController` exposes `/v1/authorization-code/captchas/{uuid}` that reads the same key.

Frontend (login template):
- Still calls `/api/v1/username-password/captchas/{uuid}` in both the fallback form image and Vue refresh logic.

## Fix Focus Areas
- laokou-service/laokou-auth/laokou-auth-start/src/main/resources/templates/login.html[181-193]
- laokou-service/laokou-auth/laokou-auth-start/src/main/resources/templates/login.html[257-271]

## Expected change
- Replace `/api/v1/username-password/captchas/` with `/api/v1/authorization-code/captchas/` in:
  - the `<img th:src=...>` and its `onclick` handler
  - the Vue `refreshCaptcha()` fetch URL
- (Optional) Update any UI labels/help text if they refer specifically to “username-password captcha”.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.33%. Comparing base (77e4324) to head (c70a68a).
⚠️ Report is 22 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5872      +/-   ##
============================================
+ Coverage     58.26%   58.33%   +0.06%     
- Complexity     1144     1146       +2     
============================================
  Files           270      270              
  Lines          5358     5364       +6     
  Branches        339      339              
============================================
+ Hits           3122     3129       +7     
+ Misses         2060     2059       -1     
  Partials        176      176              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant