feat: 接入后台消息治理与登录审计
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
adapter "github.com/tinode/chat/server/db"
|
||||
"github.com/tinode/chat/server/store/types"
|
||||
)
|
||||
|
||||
type SecurityAuditPersistenceInterface interface {
|
||||
RecordLogin(types.TenantID, *types.LoginAuditEvent) error
|
||||
RecordLoginFailure(types.TenantID, *types.LoginFailureEvent) error
|
||||
CloseLogin(types.TenantID, string, time.Time) error
|
||||
ApplyMessageAction(types.TenantID, *types.MessageAdminAction) error
|
||||
}
|
||||
|
||||
type securityAuditMapper struct{}
|
||||
|
||||
var SecurityAudit SecurityAuditPersistenceInterface = securityAuditMapper{}
|
||||
|
||||
func tenantSecurityAuditAdapter(tenantID types.TenantID) (adapter.TenantSecurityAuditAdapter, error) {
|
||||
business, err := tenantBusinessAdapter(tenantID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
audit, ok := business.(adapter.TenantSecurityAuditAdapter)
|
||||
if !ok {
|
||||
return nil, types.ErrUnsupported
|
||||
}
|
||||
return audit, nil
|
||||
}
|
||||
|
||||
func (securityAuditMapper) RecordLogin(tenantID types.TenantID, event *types.LoginAuditEvent) error {
|
||||
audit, err := tenantSecurityAuditAdapter(tenantID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return audit.TenantLoginAuditCreate(tenantID, event)
|
||||
}
|
||||
|
||||
func (securityAuditMapper) RecordLoginFailure(tenantID types.TenantID, event *types.LoginFailureEvent) error {
|
||||
audit, err := tenantSecurityAuditAdapter(tenantID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return audit.TenantLoginFailureCreate(tenantID, event)
|
||||
}
|
||||
|
||||
func (securityAuditMapper) CloseLogin(tenantID types.TenantID, sessionID string, at time.Time) error {
|
||||
audit, err := tenantSecurityAuditAdapter(tenantID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return audit.TenantLoginAuditClose(tenantID, sessionID, at)
|
||||
}
|
||||
|
||||
func (securityAuditMapper) ApplyMessageAction(tenantID types.TenantID, action *types.MessageAdminAction) error {
|
||||
audit, err := tenantSecurityAuditAdapter(tenantID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return audit.TenantMessageAdminApply(tenantID, action)
|
||||
}
|
||||
@@ -4714,6 +4714,7 @@ func init() {
|
||||
RegistrationConfig = registrationConfigMapper{}
|
||||
TenantEntry = tenantEntryMapper{}
|
||||
InternalAdminQueries = internalAdminQueryMapper{}
|
||||
SecurityAudit = securityAuditMapper{}
|
||||
Users = usersMapper{}
|
||||
Topics = topicsMapper{}
|
||||
Subs = subsMapper{}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
type LoginAuditEvent struct {
|
||||
UserID Uid
|
||||
Username string
|
||||
AccountType string
|
||||
AccountHash string
|
||||
AccountMask string
|
||||
LoginType string
|
||||
EventType string
|
||||
SessionID string
|
||||
DeviceID string
|
||||
Platform string
|
||||
AppVersion string
|
||||
IP string
|
||||
Region string
|
||||
UserAgent string
|
||||
RiskLevel string
|
||||
RequestID string
|
||||
LoginAt time.Time
|
||||
LogoutAt *time.Time
|
||||
Metadata map[string]any
|
||||
}
|
||||
|
||||
type LoginFailureEvent struct {
|
||||
UserID Uid
|
||||
AccountType string
|
||||
AccountHash string
|
||||
AccountMask string
|
||||
FailureType string
|
||||
Reason string
|
||||
Detail string
|
||||
IP string
|
||||
Region string
|
||||
DeviceID string
|
||||
Platform string
|
||||
AppVersion string
|
||||
UserAgent string
|
||||
RiskLevel string
|
||||
RiskAction string
|
||||
RequestID string
|
||||
AttemptAt time.Time
|
||||
Metadata map[string]any
|
||||
}
|
||||
|
||||
type MessageAdminAction struct {
|
||||
ActionID string
|
||||
CommandID string
|
||||
ConversationType string
|
||||
Topic string
|
||||
SeqID int64
|
||||
Action string
|
||||
Reason string
|
||||
ActorAdminID int64
|
||||
RequestID string
|
||||
ProcessedAt time.Time
|
||||
}
|
||||
Reference in New Issue
Block a user