Update session cache if a plugin extends a session (#19178)

Этот коммит содержится в:
Ben Schumacher
2022-03-15 17:38:09 +01:00
коммит произвёл GitHub
родитель 4da98cb51a
Коммит 8d72cabee8
4 изменённых файлов: 95 добавлений и 16 удалений

Просмотреть файл

@@ -286,18 +286,12 @@ func (a *App) ExtendSessionExpiryIfNeeded(session *model.Session) bool {
auditRec.AddMeta("session", session)
newExpiry := now + sessionLength
if err := a.Srv().Store.Session().UpdateExpiresAt(session.Id, newExpiry); err != nil {
if err := a.ch.srv.userService.ExtendSessionExpiry(session, newExpiry); err != nil {
mlog.Error("Failed to update ExpiresAt", mlog.String("user_id", session.UserId), mlog.String("session_id", session.Id), mlog.Err(err))
auditRec.AddMeta("err", err.Error())
return false
}
// Update local cache. No need to invalidate cache for cluster as the session cache timeout
// ensures each node will get an extended expiry within the next 10 minutes.
// Worst case is another node may generate a redundant expiry update.
session.ExpiresAt = newExpiry
a.ch.srv.userService.AddSessionToCache(session)
mlog.Debug("Session extended", mlog.String("user_id", session.UserId), mlog.String("session_id", session.Id),
mlog.Int64("newExpiry", newExpiry), mlog.Int64("session_length", sessionLength))
@@ -306,14 +300,6 @@ func (a *App) ExtendSessionExpiryIfNeeded(session *model.Session) bool {
return true
}
func (a *App) extendSessionExpiry(sessionID string, newExpiry int64) *model.AppError {
if err := a.Srv().Store.Session().UpdateExpiresAt(sessionID, newExpiry); err != nil {
return model.NewAppError("ExtendSessionExpiry", "app.session.extend_session_expiry.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
}
// GetSessionLengthInMillis returns the session length, in milliseconds,
// based on the type of session (Mobile, SSO, Web/LDAP).
func (a *App) GetSessionLengthInMillis(session *model.Session) int64 {