diff --git a/pkg/apigateway/handler/auth.go b/pkg/apigateway/handler/auth.go index 162e955d9d..52e49f1da4 100644 --- a/pkg/apigateway/handler/auth.go +++ b/pkg/apigateway/handler/auth.go @@ -41,6 +41,7 @@ import ( compute_modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute" modules "yunion.io/x/onecloud/pkg/mcclient/modules/identity" "yunion.io/x/onecloud/pkg/util/httputils" + "yunion.io/x/onecloud/pkg/util/logclient" "yunion.io/x/onecloud/pkg/util/netutils2" "yunion.io/x/onecloud/pkg/util/rbacutils" "yunion.io/x/onecloud/pkg/util/seclib2" @@ -621,6 +622,12 @@ func (h *AuthHandlers) doLogin(ctx context.Context, w http.ResponseWriter, req * } func (h *AuthHandlers) postLogoutHandler(ctx context.Context, w http.ResponseWriter, req *http.Request) { + token, _, _ := fetchAuthInfo(ctx, req) + if token != nil { + // valid login, log the event + user := logclient.NewSimpleObject(token.GetUserId(), token.GetUserName(), "user") + logclient.AddActionLogWithContext(ctx, user, logclient.ACT_LOGOUT, "", token, true) + } clearAuthCookie(w) appsrv.DisableClientCache(w) appsrv.Send(w, "") diff --git a/pkg/util/logclient/consts.go b/pkg/util/logclient/consts.go index 852162a49f..78e2573347 100644 --- a/pkg/util/logclient/consts.go +++ b/pkg/util/logclient/consts.go @@ -120,6 +120,7 @@ const ( ACT_IMAGE_PROBE = "image_probe" ACT_AUTHENTICATE = "authenticate" + ACT_LOGOUT = "logout" ACT_HEALTH_CHECK = "health_check" diff --git a/pkg/util/logclient/consts_i18n.go b/pkg/util/logclient/consts_i18n.go index bc03cf25c2..2b976dffdd 100644 --- a/pkg/util/logclient/consts_i18n.go +++ b/pkg/util/logclient/consts_i18n.go @@ -398,6 +398,11 @@ func init() { CN("认证登录"), ) + t.Set(ACT_LOGOUT, i18n.NewTableEntry(). + EN("Logout"). + CN("退出登录"), + ) + t.Set(ACT_HEALTH_CHECK, i18n.NewTableEntry(). EN("Health Check"). CN("健康检查"), diff --git a/pkg/util/logclient/logclient.go b/pkg/util/logclient/logclient.go index 12b0093ed6..a43e377359 100644 --- a/pkg/util/logclient/logclient.go +++ b/pkg/util/logclient/logclient.go @@ -57,6 +57,32 @@ type IObject interface { Keyword() string } +type sSimpleObject struct { + id string + name string + keyword string +} + +func (s sSimpleObject) GetId() string { + return s.id +} + +func (s sSimpleObject) GetName() string { + return s.name +} + +func (s sSimpleObject) Keyword() string { + return s.keyword +} + +func NewSimpleObject(id, name, keyword string) IObject { + return sSimpleObject{ + id: id, + name: name, + keyword: keyword, + } +} + type IVirtualObject interface { IObject GetOwnerId() mcclient.IIdentityProvider