← 返回列表
全部 Skill›商业 Business›backend-auth-module-guideline

backend-auth-module-guideline

作者 @findsun-vn · 语言 en
Guide backend generation for authentication and authorization modules in Spring Boot module-based architecture.
商业 Business房地产与法律通用待翻译
最近源活动
—
检测 SKILL.md 语言
en
星标 ★
0
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

Skill: backend-auth-module-guideline

Purpose

Ensure authentication and authorization backend code is:

  • secure
  • layered correctly
  • API-contract-safe
  • consistent with module-based architecture
  • aligned with planner and OpenAPI

Scope

Use this skill when the module is:

  • auth
  • or any module that includes:
  • login
  • register
  • logout
  • refresh token
  • current user
  • password change
  • role / permission checks
  • session / token management

Backend Module Path

Authentication-related backend code must still follow:

backend/src/main/java/com/yourapp/modules/<module_name>/

Standard module structure:

  • controller/
  • service/
  • service/impl/
  • mapper/
  • entity/
  • dto/
  • vo/
  • convertor/

Do not create a separate architecture just because the module is auth.


Core Auth Flows

Typical auth module flows may include:

  • register
  • login
  • logout
  • refresh token
  • current authenticated user
  • password update/reset
  • role / permission retrieval

Generate only the flows supported by:

  • planner output
  • OpenAPI contract

Do not invent extra business flows without support.


Security Rules

Password handling

  • passwords must be hashed
  • never store plain text passwords
  • never return passwords or hashes in API responses
  • password comparison must use secure verification logic

Token handling

  • token generation must be centralized
  • token validation must be centralized
  • token refresh must follow the defined contract
  • do not expose internal token claims/storage structure unless required

Error handling

  • authentication failure handling must be explicit
  • avoid leaking sensitive account details
  • keep auth-related exceptions controlled and safe

Role / permission handling

  • enforce role/permission checks according to planner/OpenAPI
  • keep authorization logic explicit
  • do not mix permission checks randomly into unrelated controller code

Controller Rules

Auth controllers must:

  • expose auth endpoints only
  • delegate all real logic to services
  • return standard wrapped responses

Auth controllers must not:

  • hash passwords directly
  • validate tokens manually in controller logic
  • embed business/security policy inline

Service Rules

Auth services must handle:

  • registration business logic
  • credential verification
  • password hashing orchestration
  • token issuance
  • token refresh
  • current user resolution
  • role / permission business rules where needed

Keep auth logic centralized rather than scattered.


DTO / VO Rules

Use request DTOs and response VOs consistent with OpenAPI.

Typical request types:

  • LoginRequest
  • RegisterRequest
  • RefreshTokenRequest
  • ChangePasswordRequest

Typical response types:

  • AuthResponse
  • CurrentUserResponse

If OpenAPI defines different names, follow OpenAPI exactly.


Entity Rules

Typical auth-related entities may include:

  • user
  • role
  • permission
  • refresh_token
  • user_role
  • role_permission

Only generate entities that are actually required by:

  • planner
  • DB schema
  • OpenAPI

Do not overbuild a security model beyond the defined scope.


Mapper Rules

Use MyBatis Plus mappers for auth persistence as usual.

Common mapper responsibilities:

  • find user by login identity
  • find role/permission associations
  • persist refresh/session/token records if schema requires
  • update password or auth status fields

Do not put business logic into mappers.


Convertor Rules

Use convertors for:

  • request -> entity mapping where applicable
  • user/entity -> auth response mapping
  • current user response mapping

Do not let services accumulate repetitive mapping noise.


Standard Success Response Rule

All successful auth endpoints must still follow:

{

"code": 0,

"message": "success",

"data": {}

}

Examples:

  • login response payload inside data
  • register response payload inside data
  • current user payload inside data

Sensitive Data Rule

Never expose:

  • password
  • password_hash
  • internal credential secrets
  • hidden token persistence details
  • internal security-only flags unless explicitly required

Forbidden Patterns

  • password hashing inside controller
  • returning entity directly from auth endpoint
  • plain text password storage
  • token logic duplicated in many places
  • random authorization checks spread without structure
  • leaking sensitive auth internals in response payloads

Final Goal

Generated auth backend code must be:

  • secure
  • layered
  • explicit
  • maintainable
  • aligned with OpenAPI and module structure
评论
Ffindsun-vn
findsun-vn
findsun-vn/E-Commerce
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@findsun-vn
所属大类商业 Business / 房地产与法律
国内可用性通用
最近源活动—
风险提示无
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。