Commit 1ac0f580 by CaIon

feat(audit): add authentication method tracking in audit logs

parent 51475c80
...@@ -68,9 +68,17 @@ func auditOperatorInfo(c *gin.Context) map[string]interface{} { ...@@ -68,9 +68,17 @@ func auditOperatorInfo(c *gin.Context) map[string]interface{} {
"admin_id": c.GetInt("id"), "admin_id": c.GetInt("id"),
"admin_username": c.GetString("username"), "admin_username": c.GetString("username"),
"admin_role": c.GetInt("role"), "admin_role": c.GetInt("role"),
"auth_method": auditAuthMethod(c),
} }
} }
func auditAuthMethod(c *gin.Context) string {
if c.GetBool("use_access_token") {
return "access_token"
}
return "session"
}
// markAuditLogged 标记当前请求已在 handler 内手动记录审计日志, // markAuditLogged 标记当前请求已在 handler 内手动记录审计日志,
// 使鉴权链路中的审计兜底(finishAdminAudit)跳过兜底记录,避免重复。 // 使鉴权链路中的审计兜底(finishAdminAudit)跳过兜底记录,避免重复。
func markAuditLogged(c *gin.Context) { func markAuditLogged(c *gin.Context) {
......
...@@ -162,6 +162,7 @@ func finishAdminAudit(c *gin.Context, writer *auditResponseWriter) { ...@@ -162,6 +162,7 @@ func finishAdminAudit(c *gin.Context, writer *auditResponseWriter) {
"admin_id": operatorId, "admin_id": operatorId,
"admin_username": operatorName, "admin_username": operatorName,
"admin_role": operatorRole, "admin_role": operatorRole,
"auth_method": auditAuthMethod(c),
} }
auditInfo := map[string]interface{}{ auditInfo := map[string]interface{}{
"method": method, "method": method,
...@@ -179,6 +180,13 @@ func finishAdminAudit(c *gin.Context, writer *auditResponseWriter) { ...@@ -179,6 +180,13 @@ func finishAdminAudit(c *gin.Context, writer *auditResponseWriter) {
}) })
} }
func auditAuthMethod(c *gin.Context) string {
if c.GetBool("use_access_token") {
return "access_token"
}
return "session"
}
// auditResponseSuccess 依据 HTTP 状态码与响应体推断操作是否成功。 // auditResponseSuccess 依据 HTTP 状态码与响应体推断操作是否成功。
// 优先解析响应 JSON 中的 success 字段;无法解析时退回到状态码判断。 // 优先解析响应 JSON 中的 success 字段;无法解析时退回到状态码判断。
func auditResponseSuccess(status int, body []byte) bool { func auditResponseSuccess(status int, body []byte) bool {
......
...@@ -65,7 +65,7 @@ export default defineConfig(({ envMode }) => { ...@@ -65,7 +65,7 @@ export default defineConfig(({ envMode }) => {
}, },
server: { server: {
host: '0.0.0.0', host: '0.0.0.0',
strictPort: true, strictPort: false,
proxy: devProxy, proxy: devProxy,
}, },
output: { output: {
......
...@@ -473,6 +473,12 @@ export function DetailsDialog(props: DetailsDialogProps) { ...@@ -473,6 +473,12 @@ export function DetailsDialog(props: DetailsDialogProps) {
if (hasUsername) return String(username) if (hasUsername) return String(username)
return `ID: ${id}` return `ID: ${id}`
})() })()
const authMethodLabel = (() => {
if (!isManage || !props.isAdmin || !adminInfo?.auth_method) return ''
if (adminInfo.auth_method === 'access_token') return t('Access Token')
if (adminInfo.auth_method === 'session') return t('Session')
return String(adminInfo.auth_method)
})()
// Localized operation text rendered from the language-independent op // Localized operation text rendered from the language-independent op
// descriptor (shared by audit type=3 and login type=7). // descriptor (shared by audit type=3 and login type=7).
...@@ -806,6 +812,12 @@ export function DetailsDialog(props: DetailsDialogProps) { ...@@ -806,6 +812,12 @@ export function DetailsDialog(props: DetailsDialogProps) {
{operationText != null && ( {operationText != null && (
<DetailRow label={t('Operation')} value={operationText} /> <DetailRow label={t('Operation')} value={operationText} />
)} )}
{authMethodLabel !== '' && (
<DetailRow
label={t('Authentication Method')}
value={authMethodLabel}
/>
)}
{changedFieldsText !== '' && ( {changedFieldsText !== '' && (
<DetailRow <DetailRow
label={t('Changed Fields')} label={t('Changed Fields')}
......
...@@ -110,6 +110,7 @@ export interface LogOtherData { ...@@ -110,6 +110,7 @@ export interface LogOtherData {
admin_username?: string admin_username?: string
admin_id?: number | string admin_id?: number | string
admin_role?: number admin_role?: number
auth_method?: 'session' | 'access_token' | string
} }
// Language-independent operation descriptor (audit/login logs). // Language-independent operation descriptor (audit/login logs).
// Frontend renders localized content from action + params via i18n templates. // Frontend renders localized content from action + params via i18n templates.
......
...@@ -436,6 +436,7 @@ ...@@ -436,6 +436,7 @@
"auth.resetPasswordConfirm.retry": "Retry ({{seconds}}s)", "auth.resetPasswordConfirm.retry": "Retry ({{seconds}}s)",
"auth.resetPasswordConfirm.success": "Your password has been reset successfully", "auth.resetPasswordConfirm.success": "Your password has been reset successfully",
"Authentication": "Authentication", "Authentication": "Authentication",
"Authentication Method": "Authentication Method",
"Authenticator code": "Authenticator code", "Authenticator code": "Authenticator code",
"Authorization Endpoint": "Authorization Endpoint", "Authorization Endpoint": "Authorization Endpoint",
"Authorization Endpoint (Optional)": "Authorization Endpoint (Optional)", "Authorization Endpoint (Optional)": "Authorization Endpoint (Optional)",
...@@ -3686,6 +3687,7 @@ ...@@ -3686,6 +3687,7 @@
"Settings": "Settings", "Settings": "Settings",
"Settings & Preferences": "Settings & Preferences", "Settings & Preferences": "Settings & Preferences",
"Settings updated successfully": "Settings updated successfully", "Settings updated successfully": "Settings updated successfully",
"Session": "Session",
"Setup guide": "Setup guide", "Setup guide": "Setup guide",
"Setup guide complete": "Setup guide complete", "Setup guide complete": "Setup guide complete",
"Setup guide is collapsed. Expand it anytime.": "Setup guide is collapsed. Expand it anytime.", "Setup guide is collapsed. Expand it anytime.": "Setup guide is collapsed. Expand it anytime.",
......
...@@ -436,6 +436,7 @@ ...@@ -436,6 +436,7 @@
"auth.resetPasswordConfirm.retry": "Réessayer ({{seconds}}s)", "auth.resetPasswordConfirm.retry": "Réessayer ({{seconds}}s)",
"auth.resetPasswordConfirm.success": "Votre mot de passe a été réinitialisé avec succès", "auth.resetPasswordConfirm.success": "Votre mot de passe a été réinitialisé avec succès",
"Authentication": "Authentification", "Authentication": "Authentification",
"Authentication Method": "Méthode d'authentification",
"Authenticator code": "Code d'authentification", "Authenticator code": "Code d'authentification",
"Authorization Endpoint": "Point de terminaison d'autorisation", "Authorization Endpoint": "Point de terminaison d'autorisation",
"Authorization Endpoint (Optional)": "Point de terminaison d'autorisation (Facultatif)", "Authorization Endpoint (Optional)": "Point de terminaison d'autorisation (Facultatif)",
...@@ -3686,6 +3687,7 @@ ...@@ -3686,6 +3687,7 @@
"Settings": "Paramètres", "Settings": "Paramètres",
"Settings & Preferences": "Paramètres et préférences", "Settings & Preferences": "Paramètres et préférences",
"Settings updated successfully": "Paramètres mis à jour avec succès", "Settings updated successfully": "Paramètres mis à jour avec succès",
"Session": "Session",
"Setup guide": "Guide de configuration", "Setup guide": "Guide de configuration",
"Setup guide complete": "Guide de configuration terminé", "Setup guide complete": "Guide de configuration terminé",
"Setup guide is collapsed. Expand it anytime.": "Le guide de configuration est réduit. Vous pouvez le rouvrir à tout moment.", "Setup guide is collapsed. Expand it anytime.": "Le guide de configuration est réduit. Vous pouvez le rouvrir à tout moment.",
......
...@@ -436,6 +436,7 @@ ...@@ -436,6 +436,7 @@
"auth.resetPasswordConfirm.retry": "再試行 ({{seconds}}秒)", "auth.resetPasswordConfirm.retry": "再試行 ({{seconds}}秒)",
"auth.resetPasswordConfirm.success": "パスワードが正常にリセットされました", "auth.resetPasswordConfirm.success": "パスワードが正常にリセットされました",
"Authentication": "認証", "Authentication": "認証",
"Authentication Method": "認証方式",
"Authenticator code": "認証コード", "Authenticator code": "認証コード",
"Authorization Endpoint": "認可エンドポイント", "Authorization Endpoint": "認可エンドポイント",
"Authorization Endpoint (Optional)": "認証エンドポイント (オプション)", "Authorization Endpoint (Optional)": "認証エンドポイント (オプション)",
...@@ -3686,6 +3687,7 @@ ...@@ -3686,6 +3687,7 @@
"Settings": "設定", "Settings": "設定",
"Settings & Preferences": "設定と環境設定", "Settings & Preferences": "設定と環境設定",
"Settings updated successfully": "設定が正常に更新されました", "Settings updated successfully": "設定が正常に更新されました",
"Session": "セッション",
"Setup guide": "セットアップガイド", "Setup guide": "セットアップガイド",
"Setup guide complete": "セットアップガイド完了", "Setup guide complete": "セットアップガイド完了",
"Setup guide is collapsed. Expand it anytime.": "セットアップガイドは折りたたまれています。いつでも展開できます。", "Setup guide is collapsed. Expand it anytime.": "セットアップガイドは折りたたまれています。いつでも展開できます。",
......
...@@ -436,6 +436,7 @@ ...@@ -436,6 +436,7 @@
"auth.resetPasswordConfirm.retry": "Повторить ({{seconds}}с)", "auth.resetPasswordConfirm.retry": "Повторить ({{seconds}}с)",
"auth.resetPasswordConfirm.success": "Ваш пароль успешно сброшен", "auth.resetPasswordConfirm.success": "Ваш пароль успешно сброшен",
"Authentication": "Аутентификация", "Authentication": "Аутентификация",
"Authentication Method": "Метод аутентификации",
"Authenticator code": "Код аутентификатора", "Authenticator code": "Код аутентификатора",
"Authorization Endpoint": "Конечная точка авторизации", "Authorization Endpoint": "Конечная точка авторизации",
"Authorization Endpoint (Optional)": "Конечная точка авторизации (необязательно)", "Authorization Endpoint (Optional)": "Конечная точка авторизации (необязательно)",
...@@ -3686,6 +3687,7 @@ ...@@ -3686,6 +3687,7 @@
"Settings": "Настройки", "Settings": "Настройки",
"Settings & Preferences": "Настройки и предпочтения", "Settings & Preferences": "Настройки и предпочтения",
"Settings updated successfully": "Настройки успешно обновлены", "Settings updated successfully": "Настройки успешно обновлены",
"Session": "Сессия",
"Setup guide": "Руководство по настройке", "Setup guide": "Руководство по настройке",
"Setup guide complete": "Руководство по настройке завершено", "Setup guide complete": "Руководство по настройке завершено",
"Setup guide is collapsed. Expand it anytime.": "Руководство по настройке свернуто. Его можно открыть в любой момент.", "Setup guide is collapsed. Expand it anytime.": "Руководство по настройке свернуто. Его можно открыть в любой момент.",
......
...@@ -436,6 +436,7 @@ ...@@ -436,6 +436,7 @@
"auth.resetPasswordConfirm.retry": "Thử lại ({{seconds}} giây)", "auth.resetPasswordConfirm.retry": "Thử lại ({{seconds}} giây)",
"auth.resetPasswordConfirm.success": "Mật khẩu của bạn đã được đặt lại thành công", "auth.resetPasswordConfirm.success": "Mật khẩu của bạn đã được đặt lại thành công",
"Authentication": "Xác thực", "Authentication": "Xác thực",
"Authentication Method": "Phương thức xác thực",
"Authenticator code": "Mã xác thực", "Authenticator code": "Mã xác thực",
"Authorization Endpoint": "Điểm cuối ủy quyền", "Authorization Endpoint": "Điểm cuối ủy quyền",
"Authorization Endpoint (Optional)": "Điểm cuối ủy quyền (Tùy chọn)", "Authorization Endpoint (Optional)": "Điểm cuối ủy quyền (Tùy chọn)",
...@@ -3686,6 +3687,7 @@ ...@@ -3686,6 +3687,7 @@
"Settings": "Cài đặt", "Settings": "Cài đặt",
"Settings & Preferences": "Cài đặt & Tùy chọn", "Settings & Preferences": "Cài đặt & Tùy chọn",
"Settings updated successfully": "Cài đặt đã được cập nhật thành công", "Settings updated successfully": "Cài đặt đã được cập nhật thành công",
"Session": "Phiên",
"Setup guide": "Hướng dẫn thiết lập", "Setup guide": "Hướng dẫn thiết lập",
"Setup guide complete": "Đã hoàn tất hướng dẫn thiết lập", "Setup guide complete": "Đã hoàn tất hướng dẫn thiết lập",
"Setup guide is collapsed. Expand it anytime.": "Hướng dẫn thiết lập đã được thu gọn. Bạn có thể mở lại bất cứ lúc nào.", "Setup guide is collapsed. Expand it anytime.": "Hướng dẫn thiết lập đã được thu gọn. Bạn có thể mở lại bất cứ lúc nào.",
......
...@@ -436,6 +436,7 @@ ...@@ -436,6 +436,7 @@
"auth.resetPasswordConfirm.retry": "重试 ({{seconds}}s)", "auth.resetPasswordConfirm.retry": "重试 ({{seconds}}s)",
"auth.resetPasswordConfirm.success": "您的密码已成功重置", "auth.resetPasswordConfirm.success": "您的密码已成功重置",
"Authentication": "身份验证", "Authentication": "身份验证",
"Authentication Method": "认证方式",
"Authenticator code": "身份验证器代码", "Authenticator code": "身份验证器代码",
"Authorization Endpoint": "授权端点", "Authorization Endpoint": "授权端点",
"Authorization Endpoint (Optional)": "授权端点(可选)", "Authorization Endpoint (Optional)": "授权端点(可选)",
...@@ -3686,6 +3687,7 @@ ...@@ -3686,6 +3687,7 @@
"Settings": "设置", "Settings": "设置",
"Settings & Preferences": "设置与偏好", "Settings & Preferences": "设置与偏好",
"Settings updated successfully": "设置更新成功", "Settings updated successfully": "设置更新成功",
"Session": "会话",
"Setup guide": "设置引导", "Setup guide": "设置引导",
"Setup guide complete": "设置引导已完成", "Setup guide complete": "设置引导已完成",
"Setup guide is collapsed. Expand it anytime.": "设置引导已收起,可随时展开。", "Setup guide is collapsed. Expand it anytime.": "设置引导已收起,可随时展开。",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment