This reverts commit 7398451030.
Этот коммит содержится в:
@@ -2080,7 +2080,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.App.ClearSessionCacheForUser(c.AppContext.Session().UserId)
|
c.App.ClearSessionCacheForUser(c.AppContext.Session().UserId)
|
||||||
c.App.SetSessionExpireInHours(c.AppContext.Session(), *c.App.Config().ServiceSettings.SessionLengthMobileInHours())
|
c.App.SetSessionExpireInDays(c.AppContext.Session(), *c.App.Config().ServiceSettings.SessionLengthMobileInDays)
|
||||||
|
|
||||||
maxAge := *c.App.Config().ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
|
maxAge := *c.App.Config().ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
|
||||||
|
|
||||||
|
|||||||
@@ -280,10 +280,10 @@ type AppIface interface {
|
|||||||
SessionHasPermissionToManageBot(session model.Session, botUserId string) *model.AppError
|
SessionHasPermissionToManageBot(session model.Session, botUserId string) *model.AppError
|
||||||
// SessionIsRegistered determines if a specific session has been registered
|
// SessionIsRegistered determines if a specific session has been registered
|
||||||
SessionIsRegistered(session model.Session) bool
|
SessionIsRegistered(session model.Session) bool
|
||||||
// SetSessionExpireInHours sets the session's expiry the specified number of days
|
// SetSessionExpireInDays sets the session's expiry the specified number of days
|
||||||
// relative to either the session creation date or the current time, depending
|
// relative to either the session creation date or the current time, depending
|
||||||
// on the `ExtendSessionOnActivity` config setting.
|
// on the `ExtendSessionOnActivity` config setting.
|
||||||
SetSessionExpireInHours(session *model.Session, hours int)
|
SetSessionExpireInDays(session *model.Session, days int)
|
||||||
// SetStatusDoNotDisturbTimed takes endtime in unix epoch format in UTC
|
// SetStatusDoNotDisturbTimed takes endtime in unix epoch format in UTC
|
||||||
// and sets status of given userId to dnd which will be restored back after endtime
|
// and sets status of given userId to dnd which will be restored back after endtime
|
||||||
SetStatusDoNotDisturbTimed(userId string, endtime int64)
|
SetStatusDoNotDisturbTimed(userId string, endtime int64)
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ func (a *App) DoLogin(c *request.Context, w http.ResponseWriter, r *http.Request
|
|||||||
session.GenerateCSRF()
|
session.GenerateCSRF()
|
||||||
|
|
||||||
if deviceID != "" {
|
if deviceID != "" {
|
||||||
a.ch.srv.userService.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthMobileInHours())
|
a.ch.srv.userService.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthMobileInDays)
|
||||||
|
|
||||||
// A special case where we logout of all other sessions with the same Id
|
// A special case where we logout of all other sessions with the same Id
|
||||||
if err := a.RevokeSessionsForDeviceId(user.Id, deviceID, ""); err != nil {
|
if err := a.RevokeSessionsForDeviceId(user.Id, deviceID, ""); err != nil {
|
||||||
@@ -186,11 +186,11 @@ func (a *App) DoLogin(c *request.Context, w http.ResponseWriter, r *http.Request
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if isMobile {
|
} else if isMobile {
|
||||||
a.ch.srv.userService.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthMobileInHours())
|
a.ch.srv.userService.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthMobileInDays)
|
||||||
} else if isOAuthUser || isSaml {
|
} else if isOAuthUser || isSaml {
|
||||||
a.ch.srv.userService.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthSSOInHours())
|
a.ch.srv.userService.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthSSOInDays)
|
||||||
} else {
|
} else {
|
||||||
a.ch.srv.userService.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthWebInHours())
|
a.ch.srv.userService.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthWebInDays)
|
||||||
}
|
}
|
||||||
|
|
||||||
ua := uasurfer.Parse(r.UserAgent())
|
ua := uasurfer.Parse(r.UserAgent())
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ func (a *App) newSession(appName string, user *model.User) (*model.Session, *mod
|
|||||||
// Set new token an session
|
// Set new token an session
|
||||||
session := &model.Session{UserId: user.Id, Roles: user.Roles, IsOAuth: true}
|
session := &model.Session{UserId: user.Id, Roles: user.Roles, IsOAuth: true}
|
||||||
session.GenerateCSRF()
|
session.GenerateCSRF()
|
||||||
a.ch.srv.userService.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthSSOInHours())
|
a.ch.srv.userService.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthSSOInDays)
|
||||||
session.AddProp(model.SessionPropPlatform, appName)
|
session.AddProp(model.SessionPropPlatform, appName)
|
||||||
session.AddProp(model.SessionPropOs, "OAuth2")
|
session.AddProp(model.SessionPropOs, "OAuth2")
|
||||||
session.AddProp(model.SessionPropBrowser, "OAuth2")
|
session.AddProp(model.SessionPropBrowser, "OAuth2")
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
|
|||||||
session.UserId = model.NewId()
|
session.UserId = model.NewId()
|
||||||
session.Token = model.NewId()
|
session.Token = model.NewId()
|
||||||
session.Roles = model.SystemUserRoleId
|
session.Roles = model.SystemUserRoleId
|
||||||
th.App.SetSessionExpireInHours(session, 24)
|
th.App.SetSessionExpireInDays(session, 1)
|
||||||
|
|
||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
session, err = th.App.CreateSession(session)
|
session, err = th.App.CreateSession(session)
|
||||||
@@ -111,7 +111,7 @@ func TestOAuthDeleteApp(t *testing.T) {
|
|||||||
session.Token = model.NewId()
|
session.Token = model.NewId()
|
||||||
session.Roles = model.SystemUserRoleId
|
session.Roles = model.SystemUserRoleId
|
||||||
session.IsOAuth = true
|
session.IsOAuth = true
|
||||||
th.App.ch.srv.userService.SetSessionExpireInHours(session, 24)
|
th.App.ch.srv.userService.SetSessionExpireInDays(session, 1)
|
||||||
|
|
||||||
session, _ = th.App.CreateSession(session)
|
session, _ = th.App.CreateSession(session)
|
||||||
|
|
||||||
|
|||||||
@@ -15038,9 +15038,9 @@ func (a *OpenTracingAppLayer) SetSearchEngine(se *searchengine.Broker) {
|
|||||||
a.app.SetSearchEngine(se)
|
a.app.SetSearchEngine(se)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *OpenTracingAppLayer) SetSessionExpireInHours(session *model.Session, hours int) {
|
func (a *OpenTracingAppLayer) SetSessionExpireInDays(session *model.Session, days int) {
|
||||||
origCtx := a.ctx
|
origCtx := a.ctx
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetSessionExpireInHours")
|
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetSessionExpireInDays")
|
||||||
|
|
||||||
a.ctx = newCtx
|
a.ctx = newCtx
|
||||||
a.app.Srv().Store.SetContext(newCtx)
|
a.app.Srv().Store.SetContext(newCtx)
|
||||||
@@ -15050,7 +15050,7 @@ func (a *OpenTracingAppLayer) SetSessionExpireInHours(session *model.Session, ho
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
a.app.SetSessionExpireInHours(session, hours)
|
a.app.SetSessionExpireInDays(session, days)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *OpenTracingAppLayer) SetStatusAwayIfNeeded(userID string, manual bool) {
|
func (a *OpenTracingAppLayer) SetStatusAwayIfNeeded(userID string, manual bool) {
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ func (a *App) UpdateLastActivityAtIfNeeded(session model.Session) {
|
|||||||
|
|
||||||
a.UpdateWebConnUserActivity(session, now)
|
a.UpdateWebConnUserActivity(session, now)
|
||||||
|
|
||||||
if now-session.LastActivityAt < model.SessionActivityTimeoutMiliseconds {
|
if now-session.LastActivityAt < model.SessionActivityTimeout {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,22 +321,22 @@ func (a *App) GetSessionLengthInMillis(session *model.Session) int64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var hours int
|
var days int
|
||||||
if session.IsMobileApp() {
|
if session.IsMobileApp() {
|
||||||
hours = *a.Config().ServiceSettings.SessionLengthMobileInHours()
|
days = *a.Config().ServiceSettings.SessionLengthMobileInDays
|
||||||
} else if session.IsSSOLogin() {
|
} else if session.IsSSOLogin() {
|
||||||
hours = *a.Config().ServiceSettings.SessionLengthSSOInHours()
|
days = *a.Config().ServiceSettings.SessionLengthSSOInDays
|
||||||
} else {
|
} else {
|
||||||
hours = *a.Config().ServiceSettings.SessionLengthWebInHours()
|
days = *a.Config().ServiceSettings.SessionLengthWebInDays
|
||||||
}
|
}
|
||||||
return int64(hours * 60 * 60 * 1000)
|
return int64(days * 24 * 60 * 60 * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSessionExpireInHours sets the session's expiry the specified number of days
|
// SetSessionExpireInDays sets the session's expiry the specified number of days
|
||||||
// relative to either the session creation date or the current time, depending
|
// relative to either the session creation date or the current time, depending
|
||||||
// on the `ExtendSessionOnActivity` config setting.
|
// on the `ExtendSessionOnActivity` config setting.
|
||||||
func (a *App) SetSessionExpireInHours(session *model.Session, hours int) {
|
func (a *App) SetSessionExpireInDays(session *model.Session, days int) {
|
||||||
a.ch.srv.userService.SetSessionExpireInHours(session, hours)
|
a.ch.srv.userService.SetSessionExpireInDays(session, days)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError) {
|
func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError) {
|
||||||
@@ -425,7 +425,7 @@ func (a *App) createSessionForUserAccessToken(tokenString string) (*model.Sessio
|
|||||||
} else {
|
} else {
|
||||||
session.AddProp(model.SessionPropIsGuest, "false")
|
session.AddProp(model.SessionPropIsGuest, "false")
|
||||||
}
|
}
|
||||||
a.ch.srv.userService.SetSessionExpireInHours(session, model.SessionUserAccessTokenExpiryHours)
|
a.ch.srv.userService.SetSessionExpireInDays(session, model.SessionUserAccessTokenExpiry)
|
||||||
|
|
||||||
session, nErr = a.Srv().Store.Session().Save(session)
|
session, nErr = a.Srv().Store.Session().Save(session)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
|
|||||||
@@ -199,14 +199,14 @@ func (us *UserService) RevokeAccessToken(token string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSessionExpireInHours sets the session's expiry the specified number of days
|
// SetSessionExpireInDays sets the session's expiry the specified number of days
|
||||||
// relative to either the session creation date or the current time, depending
|
// relative to either the session creation date or the current time, depending
|
||||||
// on the `ExtendSessionOnActivity` config setting.
|
// on the `ExtendSessionOnActivity` config setting.
|
||||||
func (us *UserService) SetSessionExpireInHours(session *model.Session, hours int) {
|
func (us *UserService) SetSessionExpireInDays(session *model.Session, days int) {
|
||||||
if session.CreateAt == 0 || *us.config().ServiceSettings.ExtendSessionLengthWithActivity {
|
if session.CreateAt == 0 || *us.config().ServiceSettings.ExtendSessionLengthWithActivity {
|
||||||
session.ExpiresAt = model.GetMillis() + (1000 * 60 * 60 * int64(hours))
|
session.ExpiresAt = model.GetMillis() + (1000 * 60 * 60 * 24 * int64(days))
|
||||||
} else {
|
} else {
|
||||||
session.ExpiresAt = session.CreateAt + (1000 * 60 * 60 * int64(hours))
|
session.ExpiresAt = session.CreateAt + (1000 * 60 * 60 * 24 * int64(days))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func TestSetSessionExpireInDays(t *testing.T) {
|
|||||||
CreateAt: create,
|
CreateAt: create,
|
||||||
ExpiresAt: model.GetMillis() + dayInMillis,
|
ExpiresAt: model.GetMillis() + dayInMillis,
|
||||||
}
|
}
|
||||||
th.service.SetSessionExpireInHours(session, tt.days*24)
|
th.service.SetSessionExpireInDays(session, tt.days)
|
||||||
|
|
||||||
// must be within 5 seconds of expected time.
|
// must be within 5 seconds of expected time.
|
||||||
require.GreaterOrEqual(t, session.ExpiresAt, tt.want-grace)
|
require.GreaterOrEqual(t, session.ExpiresAt, tt.want-grace)
|
||||||
@@ -112,7 +112,7 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
|
|||||||
session.UserId = model.NewId()
|
session.UserId = model.NewId()
|
||||||
session.Token = model.NewId()
|
session.Token = model.NewId()
|
||||||
session.Roles = model.SystemUserRoleId
|
session.Roles = model.SystemUserRoleId
|
||||||
th.service.SetSessionExpireInHours(session, 24)
|
th.service.SetSessionExpireInDays(session, 1)
|
||||||
|
|
||||||
session, _ = th.service.CreateSession(session)
|
session, _ = th.service.CreateSession(session)
|
||||||
err = th.service.RevokeAccessToken(session.Token)
|
err = th.service.RevokeAccessToken(session.Token)
|
||||||
|
|||||||
@@ -8271,10 +8271,6 @@
|
|||||||
"id": "model.config.is_valid.saml_username_attribute.app_error",
|
"id": "model.config.is_valid.saml_username_attribute.app_error",
|
||||||
"translation": "Invalid Username attribute. Must be set."
|
"translation": "Invalid Username attribute. Must be set."
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id": "model.config.is_valid.session_length_sso_in_days.app_error",
|
|
||||||
"translation": " "
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "model.config.is_valid.site_url.app_error",
|
"id": "model.config.is_valid.site_url.app_error",
|
||||||
"translation": "Site URL must be a valid URL and start with http:// or https://."
|
"translation": "Site URL must be a valid URL and start with http:// or https://."
|
||||||
|
|||||||
@@ -7,4 +7,3 @@ func NewBool(b bool) *bool { return &b }
|
|||||||
func NewInt(n int) *int { return &n }
|
func NewInt(n int) *int { return &n }
|
||||||
func NewInt64(n int64) *int64 { return &n }
|
func NewInt64(n int64) *int64 { return &n }
|
||||||
func NewString(s string) *string { return &s }
|
func NewString(s string) *string { return &s }
|
||||||
func NewFloat32(s float32) *float32 { return &s }
|
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ type ServiceSettings struct {
|
|||||||
ExtendSessionLengthWithActivity *bool `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
ExtendSessionLengthWithActivity *bool `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
||||||
SessionLengthWebInDays *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
SessionLengthWebInDays *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
||||||
SessionLengthMobileInDays *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
SessionLengthMobileInDays *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
||||||
SessionLengthSSOInDays *float32 `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
SessionLengthSSOInDays *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
||||||
SessionCacheInMinutes *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
SessionCacheInMinutes *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
||||||
SessionIdleTimeoutInMinutes *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
SessionIdleTimeoutInMinutes *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
|
||||||
WebsocketSecurePort *int `access:"write_restrictable,cloud_restrictable"` // telemetry: none
|
WebsocketSecurePort *int `access:"write_restrictable,cloud_restrictable"` // telemetry: none
|
||||||
@@ -368,18 +368,6 @@ type ServiceSettings struct {
|
|||||||
ManagedResourcePaths *string `access:"environment_web_server,write_restrictable,cloud_restrictable"`
|
ManagedResourcePaths *string `access:"environment_web_server,write_restrictable,cloud_restrictable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServiceSettings) SessionLengthWebInHours() *int {
|
|
||||||
return NewInt(*s.SessionLengthWebInDays * 24)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ServiceSettings) SessionLengthMobileInHours() *int {
|
|
||||||
return NewInt(*s.SessionLengthMobileInDays * 24)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ServiceSettings) SessionLengthSSOInHours() *int {
|
|
||||||
return NewInt(int(*s.SessionLengthSSOInDays * 24))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ServiceSettings) SetDefaults(isUpdate bool) {
|
func (s *ServiceSettings) SetDefaults(isUpdate bool) {
|
||||||
if s.EnableEmailInvitations == nil {
|
if s.EnableEmailInvitations == nil {
|
||||||
// If the site URL is also not present then assume this is a clean install
|
// If the site URL is also not present then assume this is a clean install
|
||||||
@@ -610,7 +598,7 @@ func (s *ServiceSettings) SetDefaults(isUpdate bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.SessionLengthSSOInDays == nil {
|
if s.SessionLengthSSOInDays == nil {
|
||||||
s.SessionLengthSSOInDays = NewFloat32(30)
|
s.SessionLengthSSOInDays = NewInt(30)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.SessionCacheInMinutes == nil {
|
if s.SessionCacheInMinutes == nil {
|
||||||
@@ -3596,10 +3584,6 @@ func (s *ServiceSettings) isValid() *AppError {
|
|||||||
return NewAppError("Config.IsValid", "model.config.is_valid.collapsed_threads.app_error", nil, "", http.StatusBadRequest)
|
return NewAppError("Config.IsValid", "model.config.is_valid.collapsed_threads.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *s.SessionLengthSSOInHours() < 1 {
|
|
||||||
return NewAppError("Config.IsValid", "model.config.is_valid.session_length_sso_in_days.app_error", nil, "", http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ const (
|
|||||||
SessionTypeCloudKey = "CloudKey"
|
SessionTypeCloudKey = "CloudKey"
|
||||||
SessionTypeRemoteclusterToken = "RemoteClusterToken"
|
SessionTypeRemoteclusterToken = "RemoteClusterToken"
|
||||||
SessionPropIsGuest = "is_guest"
|
SessionPropIsGuest = "is_guest"
|
||||||
SessionActivityTimeoutMiliseconds = 1000 * 60 * 5 // 5 minutes
|
SessionActivityTimeout = 1000 * 60 * 5 // 5 minutes
|
||||||
SessionUserAccessTokenExpiryHours = 100 * 365 * 24 // 100 years
|
SessionUserAccessTokenExpiry = 100 * 365 // 100 years
|
||||||
)
|
)
|
||||||
|
|
||||||
//msgp StringMap
|
//msgp StringMap
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
//go:build !linux
|
|
||||||
// +build !linux
|
// +build !linux
|
||||||
|
|
||||||
package upgrader
|
package upgrader
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ func TestHandlerServeCSRFToken(t *testing.T) {
|
|||||||
IsOAuth: false,
|
IsOAuth: false,
|
||||||
}
|
}
|
||||||
session.GenerateCSRF()
|
session.GenerateCSRF()
|
||||||
th.App.SetSessionExpireInHours(session, 24)
|
th.App.SetSessionExpireInDays(session, 1)
|
||||||
session, err := th.App.CreateSession(session)
|
session, err := th.App.CreateSession(session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected nil, got %s", err)
|
t.Errorf("Expected nil, got %s", err)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user