mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Update login policy (#2822)
* fix: login Policy * fix: del login Policy
This commit is contained in:
parent
269dd7180f
commit
41d5688de6
2
go.mod
2
go.mod
@ -12,7 +12,7 @@ require (
|
|||||||
github.com/gorilla/websocket v1.5.1
|
github.com/gorilla/websocket v1.5.1
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||||
github.com/mitchellh/mapstructure v1.5.0
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
github.com/openimsdk/protocol v0.0.72-alpha.51
|
github.com/openimsdk/protocol v0.0.72-alpha.53
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.16
|
github.com/openimsdk/tools v0.0.50-alpha.16
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/prometheus/client_golang v1.18.0
|
github.com/prometheus/client_golang v1.18.0
|
||||||
|
4
go.sum
4
go.sum
@ -319,8 +319,8 @@ github.com/onsi/gomega v1.25.0 h1:Vw7br2PCDYijJHSfBOWhov+8cAnUf8MfMaIOV323l6Y=
|
|||||||
github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
|
github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
|
||||||
github.com/openimsdk/gomake v0.0.14-alpha.5 h1:VY9c5x515lTfmdhhPjMvR3BBRrRquAUCFsz7t7vbv7Y=
|
github.com/openimsdk/gomake v0.0.14-alpha.5 h1:VY9c5x515lTfmdhhPjMvR3BBRrRquAUCFsz7t7vbv7Y=
|
||||||
github.com/openimsdk/gomake v0.0.14-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
|
github.com/openimsdk/gomake v0.0.14-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
|
||||||
github.com/openimsdk/protocol v0.0.72-alpha.51 h1:G5Yjndp/FRyOJWhoQcSF2x2GvYiAIlqN0vjkvjUPycU=
|
github.com/openimsdk/protocol v0.0.72-alpha.53 h1:DMzvDd418GaJJLT2Iw+AX+oNc41DROWErXDkZxB+MMM=
|
||||||
github.com/openimsdk/protocol v0.0.72-alpha.51/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
|
github.com/openimsdk/protocol v0.0.72-alpha.53/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.16 h1:bC1AQvJMuOHtZm8LZRvN8L5mH1Ws2VYdL+TLTs1iGSc=
|
github.com/openimsdk/tools v0.0.50-alpha.16 h1:bC1AQvJMuOHtZm8LZRvN8L5mH1Ws2VYdL+TLTs1iGSc=
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.16/go.mod h1:h1cYmfyaVtgFbKmb1Cfsl8XwUOMTt8ubVUQrdGtsUh4=
|
github.com/openimsdk/tools v0.0.50-alpha.16/go.mod h1:h1cYmfyaVtgFbKmb1Cfsl8XwUOMTt8ubVUQrdGtsUh4=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||||
|
@ -327,11 +327,6 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
|
|||||||
|
|
||||||
switch ws.msgGatewayConfig.Share.MultiLogin.Policy {
|
switch ws.msgGatewayConfig.Share.MultiLogin.Policy {
|
||||||
case constant.DefalutNotKick:
|
case constant.DefalutNotKick:
|
||||||
case constant.WebAndOther:
|
|
||||||
if constant.PlatformIDToClass(newClient.PlatformID) == constant.WebPlatformStr {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fallthrough
|
|
||||||
case constant.PCAndOther:
|
case constant.PCAndOther:
|
||||||
if constant.PlatformIDToClass(newClient.PlatformID) == constant.TerminalPC {
|
if constant.PlatformIDToClass(newClient.PlatformID) == constant.TerminalPC {
|
||||||
return
|
return
|
||||||
@ -356,7 +351,7 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
|
|||||||
log.ZWarn(newClient.ctx, "InvalidateToken err", err, "userID", newClient.UserID,
|
log.ZWarn(newClient.ctx, "InvalidateToken err", err, "userID", newClient.UserID,
|
||||||
"platformID", newClient.PlatformID)
|
"platformID", newClient.PlatformID)
|
||||||
}
|
}
|
||||||
case constant.PcMobileAndWeb:
|
case constant.AllLoginButSameClassKick:
|
||||||
clients, ok := ws.clients.GetAll(newClient.UserID)
|
clients, ok := ws.clients.GetAll(newClient.UserID)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
@ -370,21 +365,6 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
kickTokenFunc(kickClients)
|
kickTokenFunc(kickClients)
|
||||||
|
|
||||||
case constant.SingleTerminalLogin:
|
|
||||||
clients, ok := ws.clients.GetAll(newClient.UserID)
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var (
|
|
||||||
kickClients []*Client
|
|
||||||
)
|
|
||||||
for _, client := range clients {
|
|
||||||
kickClients = append(kickClients, client)
|
|
||||||
}
|
|
||||||
kickTokenFunc(kickClients)
|
|
||||||
case constant.Customize:
|
|
||||||
// todo
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,17 +172,8 @@ func (a *authDatabase) checkToken(ctx context.Context, tokens map[int]map[string
|
|||||||
kickToken = append(kickToken, ts[len(ts)-1])
|
kickToken = append(kickToken, ts[len(ts)-1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case constant.SingleTerminalLogin:
|
|
||||||
for _, ts := range loginTokenMap {
|
|
||||||
kickToken = append(kickToken, ts...)
|
|
||||||
}
|
|
||||||
case constant.WebAndOther:
|
|
||||||
unkickTerminal = constant.WebPlatformStr
|
|
||||||
fallthrough
|
|
||||||
case constant.PCAndOther:
|
case constant.PCAndOther:
|
||||||
if unkickTerminal == "" {
|
unkickTerminal = constant.TerminalPC
|
||||||
unkickTerminal = constant.TerminalPC
|
|
||||||
}
|
|
||||||
if constant.PlatformIDToClass(platformID) != unkickTerminal {
|
if constant.PlatformIDToClass(platformID) != unkickTerminal {
|
||||||
for plt, ts := range loginTokenMap {
|
for plt, ts := range loginTokenMap {
|
||||||
if constant.PlatformIDToClass(plt) != unkickTerminal {
|
if constant.PlatformIDToClass(plt) != unkickTerminal {
|
||||||
@ -214,17 +205,17 @@ func (a *authDatabase) checkToken(ctx context.Context, tokens map[int]map[string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case constant.PcMobileAndWeb:
|
case constant.AllLoginButSameClassKick:
|
||||||
var (
|
var (
|
||||||
reserved = make(map[string]bool)
|
reserved = make(map[string]struct{})
|
||||||
)
|
)
|
||||||
|
|
||||||
for plt, ts := range loginTokenMap {
|
for plt, ts := range loginTokenMap {
|
||||||
if constant.PlatformIDToClass(plt) == constant.PlatformIDToClass(platformID) {
|
if constant.PlatformIDToClass(plt) == constant.PlatformIDToClass(platformID) {
|
||||||
kickToken = append(kickToken, ts...)
|
kickToken = append(kickToken, ts...)
|
||||||
} else {
|
} else {
|
||||||
if !reserved[constant.PlatformIDToClass(plt)] {
|
if _, ok := reserved[constant.PlatformIDToClass(plt)]; !ok {
|
||||||
reserved[constant.PlatformIDToClass(plt)] = true
|
reserved[constant.PlatformIDToClass(plt)] = struct{}{}
|
||||||
kickToken = append(kickToken, ts[:len(ts)-1]...)
|
kickToken = append(kickToken, ts[:len(ts)-1]...)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
@ -232,22 +223,6 @@ func (a *authDatabase) checkToken(ctx context.Context, tokens map[int]map[string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case constant.Customize:
|
|
||||||
if a.multiLogin.CustomizeLoginNum[platformID] <= 0 {
|
|
||||||
return nil, nil, errs.New("Do not allow login on this end").Wrap()
|
|
||||||
}
|
|
||||||
for plt, ts := range loginTokenMap {
|
|
||||||
l := len(ts)
|
|
||||||
if platformID == plt {
|
|
||||||
l++
|
|
||||||
}
|
|
||||||
// a.multiLogin.CustomizeLoginNum[platformID] must > 0
|
|
||||||
limit := min(a.multiLogin.CustomizeLoginNum[plt], a.multiLogin.MaxNumOneEnd)
|
|
||||||
if l > limit {
|
|
||||||
kickToken = append(kickToken, ts[:l-limit]...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return nil, nil, errs.New("unknown multiLogin policy").Wrap()
|
return nil, nil, errs.New("unknown multiLogin policy").Wrap()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user