feat: add backdoor login functionality for testing environment
- Implemented SysUserMapper to include a method for selecting available users for backdoor login. - Created XML mappings for the new backdoor user selection query. - Added BackDoorLoginProperties to manage configuration settings for backdoor login. - Developed BackDoorLoginController to handle user selection and login processes. - Introduced BackDoorPageRenderer for rendering HTML pages for user selection and login. - Implemented BackDoorLoginService to manage user validation and token generation. - Added HTML templates for user selection, login, and error handling. - Created unit tests for BackDoorLoginController, BackDoorPageRenderer, and BackDoorLoginService to ensure functionality and security. - Documented usage and configuration in test-backdoor-login.md.
This commit is contained in:
57
docs/test-backdoor-login.md
Normal file
57
docs/test-backdoor-login.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# 测试环境 PC 用户后门登录
|
||||
|
||||
测试环境无法访问外部统一门户时,可以通过用户选择页直接建立本系统登录态:
|
||||
|
||||
```text
|
||||
http://47.111.103.66/shihezi/backDoor
|
||||
```
|
||||
|
||||
页面只显示 `sys_user` 中未删除、未停用的用户,支持按用户 ID、账号、姓名或手机号搜索。手机号会脱敏,身份证号不会展示。选择用户后,后端生成与 PC 单点登录相同类型的两小时 token,页面将 token 写入同源的 `access_token` 和 `refresh_token`,再根据 `/getInfo` 返回的用户类型进入求职门户或管理端。
|
||||
|
||||
已知用户 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
|
||||
api-base-path: /api/shihezi
|
||||
```
|
||||
Reference in New Issue
Block a user