datai/docs/archive/api-docs/auth/DataISfLoginController/0005-query-login-history.md

195 lines
5.9 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.

# 查询不同类型ORG成功登录历史
## 接口信息
- **接口名称**: 查询不同类型ORG成功登录历史
- **接口路径**: /salesforce/login/history/success/{orgType}
- **请求方法**: GET
- **模块归属**: datai-salesforce-auth
- **版本号**: v1.0
- **创建日期**: 2026-01-16
- **最后更新**: 2026-01-16
## 功能描述
查询指定ORG类型的成功登录历史记录。支持查询源ORG和目标ORG的登录历史返回所有成功登录的记录包括登录时间、登录类型、用户名、Session ID等信息。密码等敏感信息会被脱敏处理。
## 请求参数
### 路径参数
| 参数名 | 类型 | 必填 | 描述 | 示例 |
|--------|------|------|------|------|
| orgType | String | 是 | ORG类型可选值source源ORG、target目标ORG
## 响应数据
### 成功响应
**HTTP 状态码**: 200 OK
```json
{
"code": 200,
"message": "查询成功",
"data": [
{
"id": 1,
"loginType": "oauth2",
"username": "user@example.com",
"sessionIdResult": "00D...!AQc...",
"instanceUrl": "https://yourinstance.my.salesforce.com",
"userId": "005...",
"organizationId": "00D...",
"orgType": "source",
"status": "success",
"loginTime": "2026-01-16T10:30:00",
"expirationTime": "2026-01-16T11:30:00",
"userFullName": "John Doe",
"userEmail": "john.doe@example.com",
"organizationName": "Acme Corp"
}
]
}
```
| 字段名 | 类型 | 描述 | 示例 |
|--------|------|------|------|
| id | Long | 登录历史记录ID | 1 |
| loginType | String | 登录类型 | oauth2 |
| username | String | 用户名 | user@example.com |
| sessionIdResult | String | Session ID已脱敏 | 00D...!AQc... |
| instanceUrl | String | API访问基础地址 | https://yourinstance.my.salesforce.com |
| userId | String | 用户ID | 005... |
| organizationId | String | 组织ID | 00D... |
| orgType | String | 组织类型 | source |
| status | String | 登录状态 | success |
| loginTime | String | 登录时间 | 2026-01-16T10:30:00 |
| expirationTime | String | 过期时间 | 2026-01-16T11:30:00 |
| userFullName | String | 用户全名 | John Doe |
| userEmail | String | 用户邮箱 | john.doe@example.com |
| organizationName | String | 组织名称 | Acme Corp |
### 失败响应
**HTTP 状态码**: 400/500
```json
{
"code": 400,
"message": "查询失败",
"data": null
}
```
| 错误码 | 错误信息 | 描述 |
|--------|----------|------|
| 400 | 参数错误 | orgType参数无效 |
| 500 | 查询失败: 系统错误 | 系统内部错误 |
## 接口示例
### 请求示例
**查询源ORG登录历史**:
```bash
curl -X GET "http://localhost:8080/salesforce/login/history/success/source" \
-H "Content-Type: application/json"
```
**查询目标ORG登录历史**:
```bash
curl -X GET "http://localhost:8080/salesforce/login/history/success/target" \
-H "Content-Type: application/json"
```
### 响应示例
**成功**:
```json
{
"code": 200,
"message": "查询成功",
"data": [
{
"id": 1,
"loginType": "oauth2",
"username": "user@example.com",
"sessionIdResult": "00D...!AQc...",
"instanceUrl": "https://yourinstance.my.salesforce.com",
"userId": "005...",
"organizationId": "00D...",
"orgType": "source",
"status": "success",
"loginTime": "2026-01-16T10:30:00",
"expirationTime": "2026-01-16T11:30:00",
"userFullName": "John Doe",
"userEmail": "john.doe@example.com",
"organizationName": "Acme Corp"
}
]
}
```
**失败**:
```json
{
"code": 400,
"message": "查询失败",
"data": null
}
```
## 错误处理
1. **参数错误**: 检查orgType参数是否为有效的source、target、sandbox或production
2. **查询失败**: 记录错误日志并返回通用错误信息
3. **系统错误**: 记录错误日志并返回通用错误信息
## 注意事项
1. orgType参数必须为source、target、sandbox或production
2. 只返回成功登录的历史记录,不包括失败的登录记录
3. 密码等敏感信息会被脱敏处理,不会返回明文密码
4. Session ID会被脱敏处理只显示部分信息
5. 返回的登录历史记录按登录时间倒序排列,最新的记录在最前面
6. 可以使用返回的登录历史记录ID进行自动登录操作
7. 如果没有找到登录历史记录,返回空数组而不是错误
## 相关接口
- [登录操作](0001-do-login.md) - 执行Salesforce登录操作
- [登出操作](0002-logout.md) - 执行Salesforce登出操作
- [获取当前登录信息](0003-current.md) - 获取当前登录信息
- [自动登录](0004-auto-login.md) - 自动登录支持源ORG和目标ORG
- [根据登录历史自动登录](0006-auto-login-by-history.md) - 根据登录历史自动登录
## 实现细节
1. 接收orgType路径参数source、target、sandbox或production
2. 根据指定的orgType查询对应ORG类型的成功登录历史记录
3. 返回所有成功登录的记录,按登录时间倒序排列
4. 对敏感信息进行脱敏处理
## 测试信息
### 测试环境
- **环境**: 本地开发环境
- **版本**: v1.0
### 测试用例
| 测试场景 | 输入参数 | 预期结果 | 实际结果 | 状态 |
|----------|----------|----------|----------|------|
| 查询源ORG登录历史 | orgType=source | 返回源ORG登录历史记录 | 返回源ORG登录历史记录 | 通过 |
| 查询目标ORG登录历史 | orgType=target | 返回目标ORG登录历史记录 | 返回目标ORG登录历史记录 | 通过 |
| 查询沙盒ORG登录历史 | orgType=sandbox | 返回沙盒ORG登录历史记录 | 返回沙盒ORG登录历史记录 | 通过 |
| 查询生产ORG登录历史 | orgType=production | 返回生产ORG登录历史记录 | 返回生产ORG登录历史记录 | 通过 |
| 查询无效ORG类型 | orgType=invalid | 返回参数错误 | 返回参数错误 | 通过 |
| 查询无登录历史的ORG | orgType=source | 返回空数组 | 返回空数组 | 通过 |