Files
shz-backend/docs/test-backdoor-login.md

59 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 测试环境 PC 用户后门登录
测试环境无法访问外部统一门户时,可以通过用户选择页直接建立本系统登录态:
```text
http://47.111.103.66/shihezi/backDoor
```
页面只显示 `sys_user` 中未删除、未停用的用户,支持按用户 ID、账号、姓名或手机号搜索。同一账号存在多条历史记录时只显示 `create_time` 最新的有效记录;旧用户 ID 即使通过 `?id=` 直接访问也会被拒绝。手机号会脱敏,身份证号不会展示。选择用户后,后端生成与 PC 单点登录相同类型的两小时 token页面将 token 写入同源的 `access_token``refresh_token`,然后无论用户类型都统一进入 `/shihezi/job-portal`
用户选择页采用全屏布局,每页显示 8 个账号并提供分页,不产生页面滚动条或横向表格滚动条。
已知用户 ID 时,也可以直接访问:
```text
http://47.111.103.66/shihezi/backDoor?id=123
```
## 启用边界
- `application.yml` 中默认 `backdoor.login.enabled: false`
- 只有 `application-test.yml` 将它覆盖为 `true`
- Controller、登录服务和页面渲染器都使用同一个条件配置生产环境未开启时不会注册 `/backDoor` 路由。
- 每次后门登录都会记录用户 ID、账号和正常的登录信息便于审计。
## Nginx 路由
当前 `/shihezi/` 是前端 SPA 路径。必须在 SPA 的通用 `location` 之前,将后门路径精确转发到后端;否则浏览器会把 `/shihezi/backDoor` 当成前端路由并跳转到普通登录页。
示例(后端监听地址按测试服务器实际配置调整):
```nginx
location = /shihezi/backDoor {
proxy_pass http://127.0.0.1:9091/backDoor;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
```
查询参数会保留,因此用户列表搜索和 `?id=123` 直接登录都使用同一条规则。配置完成后先执行 `nginx -t`,再按项目的测试环境发布流程加载配置。本仓库不会自动部署或重载 Nginx。
## 本地访问
`test` profile 启动后,可以直接访问后端地址:
```text
http://127.0.0.1:9091/backDoor
```
若本地前端路径与测试环境不同,可覆盖:
```yaml
backdoor:
login:
portal-base-path: /shihezi
```