mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-05 20:11:14 +08:00
fix: AdminToken save to redis && limit 1 for each userID (#3224)
This commit is contained in:
parent
e76e02fdba
commit
3516f843db
@ -88,7 +88,7 @@ func Start(ctx context.Context, config *Config, client discovery.Conn, server gr
|
|||||||
users := make([]*tablerelation.User, 0)
|
users := make([]*tablerelation.User, 0)
|
||||||
|
|
||||||
for _, v := range config.Share.IMAdminUserID {
|
for _, v := range config.Share.IMAdminUserID {
|
||||||
users = append(users, &tablerelation.User{UserID: v, Nickname: v, AppMangerLevel: constant.AppNotificationAdmin})
|
users = append(users, &tablerelation.User{UserID: v, Nickname: v, AppMangerLevel: constant.AppAdmin})
|
||||||
}
|
}
|
||||||
userDB, err := mgo.NewUserMongo(mgocli.GetDB())
|
userDB, err := mgo.NewUserMongo(mgocli.GetDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -605,7 +605,7 @@ func (s *userServer) GetNotificationAccount(ctx context.Context, req *pbuser.Get
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, servererrs.ErrUserIDNotFound.Wrap()
|
return nil, servererrs.ErrUserIDNotFound.Wrap()
|
||||||
}
|
}
|
||||||
if user.AppMangerLevel == constant.AppAdmin || user.AppMangerLevel >= constant.AppNotificationAdmin {
|
if user.AppMangerLevel >= constant.AppAdmin {
|
||||||
return &pbuser.GetNotificationAccountResp{Account: &pbuser.NotificationAccountInfo{
|
return &pbuser.GetNotificationAccountResp{Account: &pbuser.NotificationAccountInfo{
|
||||||
UserID: user.UserID,
|
UserID: user.UserID,
|
||||||
FaceURL: user.FaceURL,
|
FaceURL: user.FaceURL,
|
||||||
|
@ -80,8 +80,6 @@ func (a *authDatabase) BatchSetTokenMapByUidPid(ctx context.Context, tokens []st
|
|||||||
|
|
||||||
// Create Token.
|
// Create Token.
|
||||||
func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformID int) (string, error) {
|
func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformID int) (string, error) {
|
||||||
isAdmin := authverify.IsManagerUserID(userID, a.adminUserIDs)
|
|
||||||
if !isAdmin {
|
|
||||||
tokens, err := a.cache.GetAllTokensWithoutError(ctx, userID)
|
tokens, err := a.cache.GetAllTokensWithoutError(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -106,7 +104,6 @@ func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformI
|
|||||||
log.ZDebug(ctx, "kicked token in create token", "token", k)
|
log.ZDebug(ctx, "kicked token in create token", "token", k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
claims := tokenverify.BuildClaims(userID, platformID, a.accessExpire)
|
claims := tokenverify.BuildClaims(userID, platformID, a.accessExpire)
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||||
@ -115,11 +112,9 @@ func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformI
|
|||||||
return "", errs.WrapMsg(err, "token.SignedString")
|
return "", errs.WrapMsg(err, "token.SignedString")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isAdmin {
|
|
||||||
if err = a.cache.SetTokenFlagEx(ctx, userID, platformID, tokenString, constant.NormalToken); err != nil {
|
if err = a.cache.SetTokenFlagEx(ctx, userID, platformID, tokenString, constant.NormalToken); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return tokenString, nil
|
return tokenString, nil
|
||||||
}
|
}
|
||||||
@ -224,9 +219,6 @@ func (a *authDatabase) checkToken(ctx context.Context, tokens map[int]map[string
|
|||||||
}
|
}
|
||||||
|
|
||||||
//var adminTokenMaxNum = a.multiLogin.MaxNumOneEnd
|
//var adminTokenMaxNum = a.multiLogin.MaxNumOneEnd
|
||||||
//if a.multiLogin.Policy == constant.Customize {
|
|
||||||
// adminTokenMaxNum = a.multiLogin.CustomizeLoginNum[constant.AdminPlatformID]
|
|
||||||
//}
|
|
||||||
//l := len(adminToken)
|
//l := len(adminToken)
|
||||||
//if platformID == constant.AdminPlatformID {
|
//if platformID == constant.AdminPlatformID {
|
||||||
// l++
|
// l++
|
||||||
@ -234,5 +226,8 @@ func (a *authDatabase) checkToken(ctx context.Context, tokens map[int]map[string
|
|||||||
//if l > adminTokenMaxNum {
|
//if l > adminTokenMaxNum {
|
||||||
// kickToken = append(kickToken, adminToken[:l-adminTokenMaxNum]...)
|
// kickToken = append(kickToken, adminToken[:l-adminTokenMaxNum]...)
|
||||||
//}
|
//}
|
||||||
|
if platformID == constant.AdminPlatformID {
|
||||||
|
kickToken = append(kickToken, adminToken...)
|
||||||
|
}
|
||||||
return deleteToken, kickToken, nil
|
return deleteToken, kickToken, nil
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,11 @@ import (
|
|||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
|
"github.com/openimsdk/protocol/user"
|
||||||
"github.com/openimsdk/tools/db/pagination"
|
"github.com/openimsdk/tools/db/pagination"
|
||||||
"github.com/openimsdk/tools/db/tx"
|
"github.com/openimsdk/tools/db/tx"
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/user"
|
|
||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache"
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user