fix: logout event log (#13916)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2022-04-06 01:30:22 +08:00
committed by GitHub
co-authored by Qiu Jian
parent 3b7a12c3e5
commit 094c643dd0
4 changed files with 39 additions and 0 deletions
+7
View File
@@ -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, "")
+1
View File
@@ -120,6 +120,7 @@ const (
ACT_IMAGE_PROBE = "image_probe"
ACT_AUTHENTICATE = "authenticate"
ACT_LOGOUT = "logout"
ACT_HEALTH_CHECK = "health_check"
+5
View File
@@ -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("健康检查"),
+26
View File
@@ -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