feat: overnight-runner 入 SDD、dev-build 全栈编排,并落地 ACC-account
将 overnight-runner skill 无前缀并入套件;dev-build 编排自测/UI/代码评审;指南左侧导航;example 实现账号能力与 progress。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Consultation Platform API (skeleton)
|
||||
version: 0.0.0
|
||||
title: Consultation Platform API
|
||||
version: 0.1.0
|
||||
description: |
|
||||
业务 API 尚未实现。目标需求见 docs/features/iteration1/。
|
||||
当前仅保留健康探针。
|
||||
咨询预约平台 API。当前已实现 ACC(账号与个人中心)。
|
||||
需求来源:docs/features/iteration1/ACC-account/spec.md
|
||||
技术方案:docs/features/iteration1/ACC-account/plan.md
|
||||
paths:
|
||||
/api/v1/health:
|
||||
get:
|
||||
@@ -20,3 +21,280 @@ paths:
|
||||
status:
|
||||
type: string
|
||||
example: UP
|
||||
/api/v1/auth/sms/send:
|
||||
post:
|
||||
summary: 发送登录 / 注册验证码
|
||||
security: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [phone]
|
||||
properties:
|
||||
phone: { type: string, example: '13800138000' }
|
||||
responses:
|
||||
'204': { description: 已接受(不区分新老号,防枚举) }
|
||||
'400': { description: 手机号非法 / 参数校验失败 }
|
||||
'409': { description: 发送过于频繁 }
|
||||
/api/v1/auth/sms/login:
|
||||
post:
|
||||
summary: 验证码登录或注册(默认 USER 角色)
|
||||
security: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [phone, code]
|
||||
properties:
|
||||
phone: { type: string }
|
||||
code: { type: string }
|
||||
nickname: { type: string, description: 新号可选,缺省生成 }
|
||||
responses:
|
||||
'200':
|
||||
description: token + account + profile
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/AuthLoginResponse' }
|
||||
'400': { description: 验证码错误 / 过期 / 手机号非法 }
|
||||
'409': { description: 账号不可用(已禁用) }
|
||||
/api/v1/auth/admin/login:
|
||||
post:
|
||||
summary: 管理员密码登录
|
||||
security: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [phone, password]
|
||||
properties:
|
||||
phone: { type: string }
|
||||
password: { type: string }
|
||||
responses:
|
||||
'200':
|
||||
description: token + account
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/AuthLoginResponse' }
|
||||
'400': { description: 账号或密码不正确 }
|
||||
'409': { description: 账号不可用(已禁用) }
|
||||
/api/v1/me:
|
||||
get:
|
||||
summary: 当前账号与资料
|
||||
security: [{ bearerAuth: [] }]
|
||||
responses:
|
||||
'200':
|
||||
description: MeResponse
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/MeResponse' }
|
||||
'401': { description: 未登录 / 登录失效 / 账号不可用 }
|
||||
/api/v1/me/profile:
|
||||
put:
|
||||
summary: 更新本人资料
|
||||
security: [{ bearerAuth: [] }]
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
nickname: { type: string, minLength: 2, maxLength: 30 }
|
||||
avatarUrl: { type: string, maxLength: 500 }
|
||||
email: { type: string, maxLength: 254 }
|
||||
cityCode: { type: string, maxLength: 20 }
|
||||
locale: { type: string, maxLength: 16, example: zh-CN }
|
||||
responses:
|
||||
'200':
|
||||
description: UserProfileResponse
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/ProfileResponse' }
|
||||
'400': { description: 参数校验失败 }
|
||||
'401': { description: 未登录 / 登录失效 }
|
||||
/api/v1/me/favorites:
|
||||
get:
|
||||
summary: 收藏列表
|
||||
security: [{ bearerAuth: [] }]
|
||||
responses:
|
||||
'200':
|
||||
description: 收藏列表
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items: { $ref: '#/components/schemas/FavoriteResponse' }
|
||||
'401': { description: 未登录 / 登录失效 }
|
||||
post:
|
||||
summary: 收藏咨询师(幂等)
|
||||
security: [{ bearerAuth: [] }]
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [consultantId]
|
||||
properties:
|
||||
consultantId: { type: string }
|
||||
responses:
|
||||
'200':
|
||||
description: 收藏记录(重复收藏返回同一条)
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/FavoriteResponse' }
|
||||
'400': { description: 咨询师不存在或不可展示 }
|
||||
'401': { description: 未登录 / 登录失效 }
|
||||
/api/v1/me/favorites/{consultantId}:
|
||||
delete:
|
||||
summary: 取消收藏(幂等)
|
||||
security: [{ bearerAuth: [] }]
|
||||
parameters:
|
||||
- name: consultantId
|
||||
in: path
|
||||
required: true
|
||||
schema: { type: string }
|
||||
responses:
|
||||
'204': { description: OK(未收藏也返回成功) }
|
||||
'401': { description: 未登录 / 登录失效 }
|
||||
/api/v1/me/agreements:
|
||||
get:
|
||||
summary: 查询本人协议同意记录
|
||||
security: [{ bearerAuth: [] }]
|
||||
responses:
|
||||
'200':
|
||||
description: 同意记录
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items: { $ref: '#/components/schemas/AgreementConsentResponse' }
|
||||
'401': { description: 未登录 / 登录失效 }
|
||||
post:
|
||||
summary: 记录协议同意(按类型 + 版本幂等)
|
||||
security: [{ bearerAuth: [] }]
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [agreementType, agreementVersion]
|
||||
properties:
|
||||
agreementType: { type: string, enum: [service, privacy] }
|
||||
agreementVersion: { type: string, maxLength: 20 }
|
||||
responses:
|
||||
'200':
|
||||
description: 同意记录
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/AgreementConsentResponse' }
|
||||
'400': { description: 协议类型 / 版本不合法 }
|
||||
'401': { description: 未登录 / 登录失效 }
|
||||
/api/v1/admin/accounts/{id}/disable:
|
||||
post:
|
||||
summary: 禁用账号(使现有会话失效)
|
||||
security: [{ bearerAuth: [] }]
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema: { type: string }
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [reason]
|
||||
properties:
|
||||
reason: { type: string, maxLength: 200 }
|
||||
responses:
|
||||
'200':
|
||||
description: 账号视图(手机号脱敏)
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/AccountResponse' }
|
||||
'400': { description: 账号不存在 / 原因缺失 }
|
||||
'401': { description: 未登录 / 登录失效 }
|
||||
'403': { description: 非管理员 }
|
||||
/api/v1/admin/accounts/{id}/enable:
|
||||
post:
|
||||
summary: 启用账号
|
||||
security: [{ bearerAuth: [] }]
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema: { type: string }
|
||||
responses:
|
||||
'200':
|
||||
description: 账号视图(手机号脱敏)
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/AccountResponse' }
|
||||
'400': { description: 账号不存在 }
|
||||
'401': { description: 未登录 / 登录失效 }
|
||||
'403': { description: 非管理员 }
|
||||
components:
|
||||
securitySchemes:
|
||||
bearerAuth:
|
||||
type: http
|
||||
scheme: bearer
|
||||
bearerFormat: JWT
|
||||
schemas:
|
||||
AuthLoginResponse:
|
||||
type: object
|
||||
properties:
|
||||
token: { type: string }
|
||||
account: { $ref: '#/components/schemas/AccountResponse' }
|
||||
profile: { $ref: '#/components/schemas/ProfileResponse' }
|
||||
MeResponse:
|
||||
type: object
|
||||
properties:
|
||||
account: { $ref: '#/components/schemas/AccountResponse' }
|
||||
profile: { $ref: '#/components/schemas/ProfileResponse' }
|
||||
AccountResponse:
|
||||
type: object
|
||||
properties:
|
||||
id: { type: string }
|
||||
roles:
|
||||
type: array
|
||||
items: { type: string, enum: [USER, CONSULTANT, ADMIN] }
|
||||
status: { type: string, enum: [ACTIVE, DISABLED] }
|
||||
phone: { type: string, nullable: true, description: 本人明文,其他视角脱敏 }
|
||||
phoneVerifiedAt: { type: string, format: date-time }
|
||||
lastLoginAt: { type: string, format: date-time, nullable: true }
|
||||
disabledReason: { type: string, nullable: true }
|
||||
createdAt: { type: string, format: date-time }
|
||||
updatedAt: { type: string, format: date-time }
|
||||
ProfileResponse:
|
||||
type: object
|
||||
properties:
|
||||
accountId: { type: string }
|
||||
nickname: { type: string }
|
||||
avatarUrl: { type: string, nullable: true }
|
||||
email: { type: string, nullable: true }
|
||||
cityCode: { type: string, nullable: true }
|
||||
locale: { type: string, example: zh-CN }
|
||||
updatedAt: { type: string, format: date-time }
|
||||
FavoriteResponse:
|
||||
type: object
|
||||
properties:
|
||||
id: { type: string }
|
||||
consultantId: { type: string }
|
||||
createdAt: { type: string, format: date-time }
|
||||
AgreementConsentResponse:
|
||||
type: object
|
||||
properties:
|
||||
id: { type: string }
|
||||
agreementType: { type: string, enum: [service, privacy] }
|
||||
agreementVersion: { type: string }
|
||||
consentedAt: { type: string, format: date-time }
|
||||
sourceIp: { type: string }
|
||||
|
||||
@@ -1,9 +1,84 @@
|
||||
# 数据库规格
|
||||
|
||||
> 当前为工程空壳:**无业务表**。
|
||||
> 目标需求:`docs/features/iteration1/`。实现各 feature 时通过 Flyway 新增表,并同步本文档。
|
||||
> 当前已实现 ACC(账号与个人中心)的业务表。
|
||||
> 其余 feature 按 `docs/features/iteration1/` 继续通过 Flyway 新增表,并同步本文档。
|
||||
|
||||
## 迁移
|
||||
|
||||
- 目录:`containers/backend/src/main/resources/db/migration/`
|
||||
- 现状:无 migration 脚本(仅占位)
|
||||
- 回滚脚本目录:`containers/backend/src/main/resources/db/rollback/`(Flyway 不自动执行,人工按需回滚)
|
||||
|
||||
| 版本 | 脚本 | 说明 |
|
||||
|---|---|---|
|
||||
| 20261117 | `V20261117__acc_account.sql` | ACC 账号与个人中心(5 张表) |
|
||||
|
||||
## 表清单
|
||||
|
||||
### account(账号)
|
||||
|
||||
| 字段 | 类型 | 约束 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | VARCHAR(64) | PK | UUID 字符串 |
|
||||
| phone_hash | VARCHAR(64) | NOT NULL,UNIQUE(`uk_account_phone_hash`) | 手机号摘要(HMAC-SHA256,带密钥),唯一登录标识 |
|
||||
| phone_cipher | VARCHAR(512) | NOT NULL | 手机号密文(AES-256-GCM),仅本人可解密展示 |
|
||||
| roles_json | VARCHAR(128) | NOT NULL | 角色 JSON 数组,如 `["USER"]` |
|
||||
| status | VARCHAR(32) | NOT NULL | `ACTIVE` / `DISABLED` |
|
||||
| phone_verified_at | DATETIME(3) | NOT NULL | 最近一次手机号验证时间 |
|
||||
| last_login_at | DATETIME(3) | NULL | 最近登录时间 |
|
||||
| disabled_reason | VARCHAR(200) | NULL | 禁用原因(禁用时必填) |
|
||||
| token_version | INT | NOT NULL DEFAULT 0 | 会话版本,禁用/启用时 +1,使旧 JWT 失效 |
|
||||
| password_hash | VARCHAR(255) | NULL | 仅 ADMIN 账号使用(BCrypt) |
|
||||
| created_at / updated_at | DATETIME(3) | NOT NULL | 创建/更新时间 |
|
||||
|
||||
### user_profile(用户资料)
|
||||
|
||||
| 字段 | 类型 | 约束 | 说明 |
|
||||
|---|---|---|---|
|
||||
| account_id | VARCHAR(64) | PK,FK→account(id) | 账号 ID |
|
||||
| nickname | VARCHAR(30) | NOT NULL | 昵称(2~30 字符) |
|
||||
| avatar_url | VARCHAR(500) | NULL | 头像地址 |
|
||||
| email | VARCHAR(254) | NULL | 邮箱 |
|
||||
| city_code | VARCHAR(20) | NULL | 城市编码 |
|
||||
| locale | VARCHAR(16) | NOT NULL DEFAULT 'zh-CN' | 语言 |
|
||||
| updated_at | DATETIME(3) | NOT NULL | 资料更新时间 |
|
||||
|
||||
### favorite_consultant(收藏咨询师)
|
||||
|
||||
| 字段 | 类型 | 约束 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | VARCHAR(64) | PK | 收藏记录 ID |
|
||||
| account_id | VARCHAR(64) | NOT NULL,FK→account(id),索引 `idx_fav_account` | 收藏人 |
|
||||
| consultant_id | VARCHAR(64) | NOT NULL | 被收藏咨询师(与 account_id 组成唯一键 `uk_fav_account_consultant`) |
|
||||
| created_at | DATETIME(3) | NOT NULL | 收藏时间 |
|
||||
|
||||
### agreement_consent(协议同意记录)
|
||||
|
||||
| 字段 | 类型 | 约束 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | VARCHAR(64) | PK | 记录 ID(不可变、不可物理删除) |
|
||||
| account_id | VARCHAR(64) | NOT NULL,FK→account(id),索引 `idx_consent_account` | 同意人 |
|
||||
| agreement_type | VARCHAR(32) | NOT NULL | `SERVICE` / `PRIVACY`(对外小写 `service` / `privacy`) |
|
||||
| agreement_version | VARCHAR(20) | NOT NULL | 协议版本 |
|
||||
| consented_at | DATETIME(3) | NOT NULL | 同意时间 |
|
||||
| source_ip | VARCHAR(45) | NOT NULL | 来源 IP |
|
||||
|
||||
唯一键 `uk_consent_account_type_ver(account_id, agreement_type, agreement_version)` 保证同版本幂等。
|
||||
|
||||
### sms_verification_code(短信验证码)
|
||||
|
||||
| 字段 | 类型 | 约束 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | VARCHAR(64) | PK | 记录 ID |
|
||||
| phone_hash | VARCHAR(64) | NOT NULL,索引 `idx_sms_phone_created(phone_hash, created_at)` | 手机号摘要 |
|
||||
| code_hash | VARCHAR(64) | NOT NULL | 验证码摘要(不存明文) |
|
||||
| expires_at | DATETIME(3) | NOT NULL | 过期时间(默认 5 分钟) |
|
||||
| fail_count | INT | NOT NULL DEFAULT 0 | 连续失败次数(达 5 次作废) |
|
||||
| used_at | DATETIME(3) | NULL | 使用 / 作废时间 |
|
||||
| created_at | DATETIME(3) | NOT NULL | 创建时间(重发间隔按此判断) |
|
||||
|
||||
## 约定
|
||||
|
||||
- 字符集 `utf8mb4` / 排序 `utf8mb4_bin`,引擎 InnoDB,表名单数小写下划线。
|
||||
- 时间统一按 `Asia/Shanghai` 存储(`DATETIME(3)`),领域层用 `Instant`,转换见 `TimeConverter`。
|
||||
- 测试库不用 Flyway:改用 `src/test/resources/schema.sql`(结构)与 `data.sql`(种子)。
|
||||
管理员种子账号由 `AccountSeedInitializer` 在运行时创建(密文与部署环境密钥相关)。
|
||||
|
||||
@@ -1,13 +1,88 @@
|
||||
# 领域模型
|
||||
|
||||
> 当前为工程空壳:**无业务聚合**。
|
||||
> 目标需求:`docs/features/iteration1/`(ACC~PLT)。按 feature plan 落地后回写本文档。
|
||||
> 当前已实现 ACC(账号与个人中心)。
|
||||
> 其余 feature 按 `docs/features/iteration1/`(COB~PLT)继续落地后回写本文档。
|
||||
|
||||
## 聚合根
|
||||
|
||||
### Account(账号)
|
||||
|
||||
统一账号:终端用户 / 咨询师 / 管理员共用一套账号体系。
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| id | String | UUID 字符串主键 |
|
||||
| phoneHash | String | 手机号摘要,唯一登录标识 |
|
||||
| phoneCipher | String | 手机号密文,仅本人可解密展示 |
|
||||
| roles | Set\<AccountRole\> | 角色集合:`USER` / `CONSULTANT` / `ADMIN` |
|
||||
| status | AccountStatus | `ACTIVE` / `DISABLED` |
|
||||
| phoneVerifiedAt / lastLoginAt | Instant | 验证时间 / 最近登录时间 |
|
||||
| disabledReason | String | 禁用原因 |
|
||||
| tokenVersion | int | 会话版本;禁用/启用时 +1,令旧 JWT 立即失效 |
|
||||
| passwordHash | String | 仅 ADMIN 使用(BCrypt) |
|
||||
|
||||
行为:
|
||||
|
||||
| 方法 | 说明 |
|
||||
|---|---|
|
||||
| `registerByPhone(...)` | 手机号注册,默认授予 `USER` 角色 |
|
||||
| `createAdmin(...)` | 平台分配管理员(R-COMMON-001,不开放自助注册) |
|
||||
| `grantConsultantRole()` | 幂等授予 `CONSULTANT`(供 COB 审核通过后调用) |
|
||||
| `disable(reason)` / `enable()` | 状态流转 + 抬升 `tokenVersion`;重复调用幂等 |
|
||||
| `touchLogin(now)` | 记录最近登录时间 |
|
||||
| `assertUsable()` | 账号禁用时抛 `IllegalStateException`(提示不可用原因) |
|
||||
|
||||
状态机:
|
||||
|
||||
```
|
||||
ACTIVE --disable(reason)--> DISABLED (tokenVersion +1)
|
||||
DISABLED --enable()------> ACTIVE (tokenVersion +1)
|
||||
```
|
||||
|
||||
### UserProfile(用户资料)
|
||||
|
||||
`accountId` / `nickname` / `avatarUrl` / `email` / `cityCode` / `locale` / `updatedAt`。
|
||||
昵称 2~30 字符、邮箱格式与长度、城市编码长度在领域层校验。
|
||||
|
||||
### FavoriteConsultant(收藏咨询师)
|
||||
|
||||
`id` / `accountId` / `consultantId` / `createdAt`;(accountId, consultantId) 唯一。
|
||||
|
||||
### AgreementConsent(协议同意记录)
|
||||
|
||||
`id` / `accountId` / `agreementType` / `agreementVersion` / `consentedAt` / `sourceIp`;
|
||||
不可变、不可物理删除;(accountId, type, version) 唯一。
|
||||
|
||||
### SmsVerificationCode(短信验证码)
|
||||
|
||||
`id` / `phoneHash` / `codeHash` / `expiresAt` / `failCount` / `usedAt` / `createdAt`;
|
||||
连续失败 5 次作废。
|
||||
|
||||
## 领域服务与端口
|
||||
|
||||
| 组件 | 层 | 说明 |
|
||||
|---|---|---|
|
||||
| `SmsCodeService` | domain/service | 验证码签发 / 校验 / TTL / 失败次数作废 / 重发限流(纯 Java,由 `DomainServiceConfig` 注册) |
|
||||
| `PhoneCrypto` | domain/service | 手机号摘要与加解密端口(实现 `AesPhoneCrypto`:HMAC-SHA256 摘要 + AES-256-GCM 密文) |
|
||||
| `SmsSender` | domain/service | 短信发送端口(实现 `MockSmsSender`,真通道归 PLT) |
|
||||
| `DisplayableConsultantPort` | domain/service | 咨询师「可展示」判定端口(实现 `StubDisplayableConsultantPort`,CDC/COB 落地后替换) |
|
||||
| `TokenIssuer` | domain/service | 令牌签发端口(实现 `JwtTokenProvider`) |
|
||||
| `PasswordService` | domain/service | 密码编码端口(实现 `PasswordServiceImpl`,BCrypt) |
|
||||
|
||||
## 值对象与枚举(domain/vo)
|
||||
|
||||
| 类型 | 取值 | 说明 |
|
||||
|---|---|---|
|
||||
| `AccountRole` | USER / CONSULTANT / ADMIN | 角色,JWT authority = `ROLE_<name>` |
|
||||
| `AccountStatus` | ACTIVE / DISABLED | 账号状态 |
|
||||
| `AgreementType` | SERVICE(`service`) / PRIVACY(`privacy`) | 协议类型,对外用小写码 |
|
||||
| `PhoneNumber` | — | 手机号规范化(去空格/横线)与格式校验 |
|
||||
|
||||
## 平台骨架(非业务聚合)
|
||||
|
||||
| 组件 | 说明 |
|
||||
|------|------|
|
||||
| JWT / UserContext | 无状态鉴权骨架,待 ACC 接入登录签发 |
|
||||
| JWT / UserContext | 无状态鉴权:Claims `sub` / `roles` / `tokenVersion`;过滤器校验账号状态与版本 |
|
||||
| IBusinessRule / BusinessRuleConfig | 业务规则框架空注册 |
|
||||
| DataDictionary* | 数据字典框架类型,暂无注册枚举 |
|
||||
| DataDictionary* | 数据字典框架类型,已注册 `AccDataDictionaryType`(账号状态 / 角色 / 协议类型) |
|
||||
| PasswordService | 密码编码接口(BCrypt 实现) |
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# ADR-004: 采用 JWT HMAC-SHA256 无状态鉴权
|
||||
|
||||
- **状态**: 已接受
|
||||
- **状态**: 已接受(2026-11-17 扩展 Claims,方案本身不变)
|
||||
- **日期**: 2026-06-19
|
||||
- **扩展记录**: 2026-11-17 · ACC(账号与个人中心)落地,Claims 扩展为多角色 + 会话版本
|
||||
|
||||
## 上下文
|
||||
|
||||
@@ -11,10 +12,24 @@
|
||||
|
||||
后端自行签发与校验 JWT(HMAC-SHA256,24h 过期),无状态鉴权。
|
||||
|
||||
JWT Payload:
|
||||
- `sub`: userId
|
||||
- `email`: 用户邮箱
|
||||
- `role`: ROLE_USER / ROLE_ADMIN
|
||||
JWT Payload(as-built):
|
||||
|
||||
- `sub`: 账号 ID(`account.id`)
|
||||
- `roles`: 角色数组,如 `["USER","CONSULTANT","ADMIN"]`(authority = `ROLE_<name>`)
|
||||
- `tokenVersion`: 会话版本,与 `account.token_version` 比对
|
||||
- `iat` / `exp`: 签发 / 过期时间
|
||||
|
||||
### Claims 扩展(2026-11-17)
|
||||
|
||||
原约定的 `email` 与单值 `role` Claims 移除,改为:
|
||||
|
||||
| 变更 | 原因 |
|
||||
|---|---|
|
||||
| `role` → `roles` 数组 | 同一账号可同时持有 USER / CONSULTANT / ADMIN 三种角色(HLD §3.2) |
|
||||
| 新增 `tokenVersion` | 管理员禁用账号时抬升库内版本,令既有 JWT 立即失效(R-UPDATE-003 / AC-005) |
|
||||
|
||||
`JwtAuthenticationFilter` 在验签后需查库比对账号状态与 `tokenVersion`:
|
||||
账号不存在 / 已禁用 / 版本不一致 → 不放行,返回 401 并带明确原因。
|
||||
|
||||
## 备选方案
|
||||
|
||||
@@ -22,7 +37,8 @@ JWT Payload:
|
||||
|------|------|----------|
|
||||
| Session + Cookie | Spring Security 默认方案 | 需 Redis 存储 session、跨域配置复杂、不适合前后端分离 |
|
||||
| OAuth2 / OIDC | 标准协议 | 增加 IDP 依赖,小型项目不需要 |
|
||||
| JWT HMAC-SHA256 | 无状态、无额外存储 | 无法主动使 token 失效 |
|
||||
| JWT HMAC-SHA256 | 无状态、无额外存储 | 无法主动使 token 失效(本次以 `tokenVersion` 补齐) |
|
||||
| JWT + 撤销名单(黑名单) | 精确吊销 | 需持久化与额外查询,收益有限;`tokenVersion` 已满足账号级失效 |
|
||||
|
||||
## 后果
|
||||
|
||||
@@ -30,8 +46,10 @@ JWT Payload:
|
||||
- 无状态、无需 Redis
|
||||
- 前后端分离友好(`Authorization: Bearer <token>`)
|
||||
- 后端自行签发,无外部依赖
|
||||
- 账号级会话失效无需维护令牌黑名单
|
||||
|
||||
**负面**:
|
||||
- Token 签发后无法主动吊销(24h 内有效)
|
||||
- 每个已认证请求需查库一次(比对状态与版本),有额外开销
|
||||
- Token 仍无法按请求粒度吊销(24h 内有效,账号级失效除外)
|
||||
- 密钥保存在配置中,泄漏风险需注意
|
||||
- 载荷明文字段不宜存放敏感信息
|
||||
- 载荷明文字段不宜存放敏感信息(手机号不入载荷,只放账号 ID)
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
# 数据字典
|
||||
|
||||
> 空壳:示例字典枚举已清除。框架类型保留(`Description` / `DataDictionaryType` / `DataDictionaryUtil`)。
|
||||
> 实现 iteration1 时注册字典并回写本文档。
|
||||
> 框架类型保留(`Description` / `DataDictionaryType` / `DataDictionaryUtil`)。
|
||||
> ACC 已注册 `AccDataDictionaryType`(`domain/datadictionary/AccDataDictionaryType.java`)。
|
||||
|
||||
当前注册字典类型:**无**。
|
||||
## 当前注册字典类型
|
||||
|
||||
| 类型 | 说明 | 枚举来源 |
|
||||
|---|---|---|
|
||||
| `AccDataDictionaryType.ACCOUNT_STATUS` | 账号状态 | `AccountStatus`(ACTIVE / DISABLED) |
|
||||
| `AccDataDictionaryType.ACCOUNT_ROLE` | 账号角色 | `AccountRole`(USER / CONSULTANT / ADMIN) |
|
||||
| `AccDataDictionaryType.AGREEMENT_TYPE` | 协议类型 | `AgreementType`(service / privacy) |
|
||||
|
||||
## 新增枚举的约定
|
||||
|
||||
1. 枚举放在 `domain/vo/`,实现 `Description`(`getCode()` / `getDescription()`)。
|
||||
2. 在 `AccDataDictionaryType`(或后续 feature 的字典类型)中登记。
|
||||
3. 回写本文档的「当前注册字典类型」表。
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# 错误码清单
|
||||
|
||||
> 框架约定(空壳 as-built)。业务专属错误码待 iteration1 实现后补充。
|
||||
> 与 `GlobalExceptionHandler` 及 `docs/standards/error.md` 对齐。
|
||||
> as-built(含 ACC)。与 `GlobalExceptionHandler` 及 `docs/standards/error.md` 对齐。
|
||||
|
||||
## 当前 Handler 映射
|
||||
|
||||
@@ -12,6 +11,29 @@
|
||||
| `MethodArgumentNotValidException` | 400 | `VALIDATION_ERROR` | `@Valid` 失败 |
|
||||
| 其它 `Exception` | 500 | `SYSTEM_ERROR` | 兜底(对外「系统繁忙」) |
|
||||
|
||||
鉴权失败由 Spring Security 直接返回 **401 / 403**,不走 `ErrorResponse`。
|
||||
|
||||
响应体字段:`errorCode` / `errorMessage` / `data`。
|
||||
|
||||
## 鉴权失败(Spring Security 直接返回,不经 GlobalExceptionHandler)
|
||||
|
||||
| 场景 | HTTP | errorCode | errorMessage 来源 |
|
||||
|---|---|---|---|
|
||||
| 未携带 / 无效 / 过期 token | 401 | `UNAUTHORIZED` | 「未登录或登录已过期」 |
|
||||
| 账号被禁用 | 401 | `UNAUTHORIZED` | 「账号不可用:<禁用原因>」 |
|
||||
| 版本不一致(账号被禁用/启用后) | 401 | `UNAUTHORIZED` | 「登录状态已失效,请重新登录」 |
|
||||
| 已登录但无权限(如非 ADMIN 访问 `/admin/**`) | 403 | `FORBIDDEN` | 「无权访问该资源」 |
|
||||
|
||||
实现:`RestAuthenticationEntryPoint`(401)/ `RestAccessDeniedHandler`(403),
|
||||
响应体沿用与 `GlobalExceptionHandler.ErrorResponse` 相同的字段结构,便于前端统一处理。
|
||||
|
||||
## ACC 典型错误文案
|
||||
|
||||
| 场景 | HTTP | errorCode | errorMessage |
|
||||
|---|---|---|---|
|
||||
| 验证码错误 | 400 | `PARAM_ERROR` | 验证码错误 |
|
||||
| 验证码已使用 / 过期 / 不存在 | 400 | `PARAM_ERROR` | 验证码已使用,请重新获取 / 验证码已过期,请重新获取 / 验证码不存在或已过期 |
|
||||
| 验证码连续错误 5 次 | 400 | `PARAM_ERROR` | 验证码连续错误次数过多,已作废 |
|
||||
| 手机号格式非法 | 400 | `PARAM_ERROR` | 手机号格式不正确 |
|
||||
| 发码过于频繁 | 409 | `BUSINESS_CONFLICT` | 验证码发送过于频繁,请稍后再试 |
|
||||
| 账号被禁用时登录 | 409 | `BUSINESS_CONFLICT` | 账号不可用:<禁用原因> |
|
||||
| 咨询师不存在或不可展示 | 400 | `PARAM_ERROR` | 咨询师不存在或不可展示 |
|
||||
| 管理员账号或密码错误 | 400 | `PARAM_ERROR` | 账号或密码不正确 |
|
||||
|
||||
@@ -1,30 +1,73 @@
|
||||
# 安全设计
|
||||
|
||||
> 平台骨架 as-built。登录/注册等业务 API 待 ACC 实现。
|
||||
> as-built(含 ACC 账号与个人中心)。
|
||||
|
||||
## JWT Token
|
||||
|
||||
**算法**:HMAC-SHA256(`jjwt`)
|
||||
|
||||
**配置**:`jwt.secret` / `jwt.expiration`(毫秒)
|
||||
**配置**:`jwt.secret` / `jwt.expiration`(毫秒,默认 24h)
|
||||
|
||||
**Claims(约定)**:`sub`=userId,`email`,`role`(如 `ROLE_USER` / `ROLE_ADMIN`),`iat`,`exp`
|
||||
**Claims(as-built)**:
|
||||
|
||||
| Claim | 说明 |
|
||||
|---|---|
|
||||
| `sub` | 账号 ID(`account.id`) |
|
||||
| `roles` | 角色数组,如 `["USER","CONSULTANT"]` |
|
||||
| `tokenVersion` | 会话版本,与 `account.token_version` 比对 |
|
||||
| `iat` / `exp` | 签发 / 过期时间 |
|
||||
|
||||
> 旧约定中的 `email` / `role` 单值 Claims 已移除(见 ADR-004 的 Claims 扩展)。
|
||||
|
||||
## 处理流程
|
||||
|
||||
```
|
||||
请求 → JwtAuthenticationFilter
|
||||
提取 Bearer token → 校验 → UserContextHolder + SecurityContextHolder
|
||||
提取 Bearer token → 验签 → 解析 claims
|
||||
→ 查库取账号:不存在 / 已禁用 / tokenVersion 不一致 → 不放行(401,带原因)
|
||||
→ 写 UserContextHolder(accountId + roles)+ SecurityContextHolder(authority = ROLE_*)
|
||||
finally 清除 ThreadLocal / SecurityContext
|
||||
```
|
||||
|
||||
## 当前放行
|
||||
**会话失效**:管理员禁用 / 启用账号会抬升 `tokenVersion`,旧 JWT 与库内版本不一致 → 立即 401。
|
||||
账号被禁用时过滤器返回提示「账号不可用:<原因>」。
|
||||
|
||||
- `GET /api/v1/health` — permitAll
|
||||
- 其它 `/api/**` — authenticated(无签发入口时仅能带有效 token 访问)
|
||||
## 角色与端点
|
||||
|
||||
| 端点 | 要求 |
|
||||
|---|---|
|
||||
| `GET /api/v1/health` | permitAll |
|
||||
| `POST /api/v1/auth/**` | permitAll(发码 / 验证码登录 / 管理员登录) |
|
||||
| `/api/v1/admin/**` | `ROLE_ADMIN`(否则 403) |
|
||||
| 其它 `/api/**` | authenticated(401) |
|
||||
|
||||
角色授权:JWT authority 为 `ROLE_USER` / `ROLE_CONSULTANT` / `ROLE_ADMIN`,
|
||||
与 Spring Security `hasRole` 对齐;`SecurityUtils.hasRole("CONSULTANT")` 同时接受带/不带 `ROLE_` 前缀。
|
||||
|
||||
## 手机号保护
|
||||
|
||||
| 项 | 做法 |
|
||||
|---|---|
|
||||
| 存储 | `phone_hash`(HMAC-SHA256,带 `phone.crypto.key`)+ `phone_cipher`(AES-256-GCM) |
|
||||
| 查询 | 唯一索引建在 `phone_hash` 上,不存明文可比对字段 |
|
||||
| 展示 | 仅本人(`/api/v1/me`)返回明文;管理端等其它视角脱敏为 `138****8000` |
|
||||
| 密钥 | `phone.crypto.key` 由环境变量注入,生产禁止入仓 |
|
||||
|
||||
## 密码
|
||||
|
||||
- 仅 ADMIN 账号使用密码登录;BCrypt 存储(`PasswordService` / `PasswordServiceImpl`)。
|
||||
- ADMIN 账号由平台种子创建(`AccountSeedInitializer`),不开放自助注册或角色提升。
|
||||
|
||||
## 短信验证码
|
||||
|
||||
- 库内只存 `code_hash`,不存明文。
|
||||
- TTL 默认 5 分钟;连续错误 5 次即作废;同一手机号 60 秒内不可重发(`BUSINESS_CONFLICT`)。
|
||||
- 发送通道本期为 `MockSmsSender`(固定码仅本地联调 / E2E 使用,生产留空)。
|
||||
|
||||
## 相关类
|
||||
|
||||
- `JwtTokenProvider` / `JwtAuthenticationFilter`
|
||||
- `JwtTokenProvider`(实现 `TokenIssuer`)/ `JwtAuthenticationFilter`
|
||||
- `UserContext` / `UserContextHolder` / `SecurityUtils`
|
||||
- `RestAuthenticationEntryPoint`(401)/ `RestAccessDeniedHandler`(403)
|
||||
- `PasswordService` / `PasswordServiceImpl`(BCrypt)
|
||||
- `AesPhoneCrypto` / `MockSmsSender` / `StubDisplayableConsultantPort`
|
||||
|
||||
Reference in New Issue
Block a user