|
@@ -222,8 +222,7 @@ func authPlainHandler(server *Server, client *Client, mechanism string, value []
|
222
|
222
|
account = loadAccount(server, tx, accountKey)
|
223
|
223
|
}
|
224
|
224
|
|
225
|
|
- account.Clients = append(account.Clients, client)
|
226
|
|
- client.account = account
|
|
225
|
+ client.LoginToAccount(account)
|
227
|
226
|
|
228
|
227
|
return err
|
229
|
228
|
})
|
|
@@ -237,6 +236,26 @@ func authPlainHandler(server *Server, client *Client, mechanism string, value []
|
237
|
236
|
return false
|
238
|
237
|
}
|
239
|
238
|
|
|
239
|
+// LoginToAccount logs the client into the given account.
|
|
240
|
+func (client *Client) LoginToAccount(account *ClientAccount) {
|
|
241
|
+ if client.account == account {
|
|
242
|
+ // already logged into this acct, no changing necessary
|
|
243
|
+ return
|
|
244
|
+ } else if client.account != nil {
|
|
245
|
+ // logout of existing acct
|
|
246
|
+ var newClientAccounts []*Client
|
|
247
|
+ for _, c := range account.Clients {
|
|
248
|
+ if c != client {
|
|
249
|
+ newClientAccounts = append(newClientAccounts, c)
|
|
250
|
+ }
|
|
251
|
+ }
|
|
252
|
+ account.Clients = newClientAccounts
|
|
253
|
+ }
|
|
254
|
+
|
|
255
|
+ account.Clients = append(account.Clients, client)
|
|
256
|
+ client.account = account
|
|
257
|
+}
|
|
258
|
+
|
240
|
259
|
// authExternalHandler parses the SASL EXTERNAL mechanism.
|
241
|
260
|
func authExternalHandler(server *Server, client *Client, mechanism string, value []byte) bool {
|
242
|
261
|
if client.certfp == "" {
|
|
@@ -275,8 +294,7 @@ func authExternalHandler(server *Server, client *Client, mechanism string, value
|
275
|
294
|
account = loadAccount(server, tx, accountKey)
|
276
|
295
|
}
|
277
|
296
|
|
278
|
|
- account.Clients = append(account.Clients, client)
|
279
|
|
- client.account = account
|
|
297
|
+ client.LoginToAccount(account)
|
280
|
298
|
|
281
|
299
|
return nil
|
282
|
300
|
})
|