DeleteSession 删除会话
(sessionID string)
| 942 | |
| 943 | // DeleteSession 删除会话 |
| 944 | func (ac *AccessController) DeleteSession(sessionID string) error { |
| 945 | ac.mu.Lock() |
| 946 | defer ac.mu.Unlock() |
| 947 | |
| 948 | session, exists := ac.sessions[sessionID] |
| 949 | if !exists { |
| 950 | return fmt.Errorf("session %s not found", sessionID) |
| 951 | } |
| 952 | |
| 953 | session.Status = SessionStatusRevoked |
| 954 | delete(ac.sessions, sessionID) |
| 955 | |
| 956 | // 记录审计日志 |
| 957 | if ac.config.EnableAudit && ac.auditLog != nil { |
| 958 | _ = ac.auditLog.LogEvent(AuditEvent{ |
| 959 | Type: AuditTypeSessionDeleted, |
| 960 | UserID: session.UserID, |
| 961 | Timestamp: time.Now(), |
| 962 | Message: fmt.Sprintf("Session %s revoked for user %s", sessionID, session.Username), |
| 963 | Metadata: map[string]any{ |
| 964 | "session_id": sessionID, |
| 965 | }, |
| 966 | }) |
| 967 | } |
| 968 | |
| 969 | return nil |
| 970 | } |
| 971 | |
| 972 | // generateSessionID 生成会话ID |
| 973 | func (ac *AccessController) generateSessionID(userID, ipAddress, userAgent string) string { |