forked from baron/baron-sso
userfront 이력 session ID기반 작업 완료.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -117,6 +118,8 @@ func AuditMiddleware(config AuditConfig) fiber.Handler {
|
||||
userID, _ := c.Locals("user_id").(string)
|
||||
loginID, _ := c.Locals("login_id").(string)
|
||||
tenantID, _ := c.Locals("tenant_id").(string)
|
||||
sessionID, _ := c.Locals("session_id").(string)
|
||||
clientIP := extractClientIP(c)
|
||||
|
||||
// 6. Capture & Mask Body
|
||||
var maskedBody string
|
||||
@@ -141,6 +144,9 @@ func AuditMiddleware(config AuditConfig) fiber.Handler {
|
||||
"tenant_id": tenantID,
|
||||
"request_body": maskedBody,
|
||||
}
|
||||
if sessionID != "" {
|
||||
details["session_id"] = sessionID
|
||||
}
|
||||
if err != nil {
|
||||
details["error"] = err.Error()
|
||||
}
|
||||
@@ -152,9 +158,10 @@ func AuditMiddleware(config AuditConfig) fiber.Handler {
|
||||
EventID: reqID,
|
||||
Timestamp: start,
|
||||
UserID: userID,
|
||||
SessionID: sessionID,
|
||||
EventType: fmt.Sprintf("%s %s", c.Method(), c.Path()),
|
||||
Status: statusText,
|
||||
IPAddress: c.IP(),
|
||||
IPAddress: clientIP,
|
||||
UserAgent: c.Get("User-Agent"),
|
||||
Details: string(detailsJSON),
|
||||
}
|
||||
@@ -190,3 +197,18 @@ func AuditMiddleware(config AuditConfig) fiber.Handler {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func extractClientIP(c *fiber.Ctx) string {
|
||||
if forwarded := c.Get("X-Forwarded-For"); forwarded != "" {
|
||||
parts := strings.Split(forwarded, ",")
|
||||
if len(parts) > 0 {
|
||||
if ip := strings.TrimSpace(parts[0]); ip != "" {
|
||||
return ip
|
||||
}
|
||||
}
|
||||
}
|
||||
if realIP := strings.TrimSpace(c.Get("X-Real-IP")); realIP != "" {
|
||||
return realIP
|
||||
}
|
||||
return c.IP()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user