MM-41211: Replaces SessionLength*InDays with SessionLength*InHours. (#19838)

* MM-41211: Replaces SessionLength[Web|Mobile|SSO]InDays with SessionLength[Web|Mobile|SSO]InHours.

* MM-41211: Clear the value of the old config settings.
Этот коммит содержится в:
Martin Kraft
2022-04-28 17:31:35 -04:00
коммит произвёл GitHub
родитель 4bc2ed3973
Коммит cb3d8f0a1c
19 изменённых файлов: 198 добавлений и 168 удалений

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

@@ -2085,9 +2085,9 @@ 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.SetSessionExpireInDays(c.AppContext.Session(), *c.App.Config().ServiceSettings.SessionLengthMobileInDays) c.App.SetSessionExpireInHours(c.AppContext.Session(), *c.App.Config().ServiceSettings.SessionLengthMobileInHours)
maxAge := *c.App.Config().ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24 maxAgeSeconds := *c.App.Config().ServiceSettings.SessionLengthMobileInHours * 60 * 60
secure := false secure := false
if app.GetProtocol(r) == "https" { if app.GetProtocol(r) == "https" {
@@ -2096,12 +2096,12 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
subpath, _ := utils.GetSubpathFromConfig(c.App.Config()) subpath, _ := utils.GetSubpathFromConfig(c.App.Config())
expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAge), 0) expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAgeSeconds), 0)
sessionCookie := &http.Cookie{ sessionCookie := &http.Cookie{
Name: model.SessionCookieToken, Name: model.SessionCookieToken,
Value: c.AppContext.Session().Token, Value: c.AppContext.Session().Token,
Path: subpath, Path: subpath,
MaxAge: maxAge, MaxAge: maxAgeSeconds,
Expires: expiresAt, Expires: expiresAt,
HttpOnly: true, HttpOnly: true,
Domain: c.App.GetCookieDomain(), Domain: c.App.GetCookieDomain(),

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

@@ -277,10 +277,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
// SetSessionExpireInDays sets the session's expiry the specified number of days // SetSessionExpireInHours sets the session's expiry the specified number of hours
// 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.
SetSessionExpireInDays(session *model.Session, days int) SetSessionExpireInHours(session *model.Session, hours 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)

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

@@ -83,7 +83,7 @@ func (a *App) getSessionExpiredPushMessage(session *model.Session) string {
T := i18n.GetUserTranslations(locale) T := i18n.GetUserTranslations(locale)
siteName := *a.Config().TeamSettings.SiteName siteName := *a.Config().TeamSettings.SiteName
props := map[string]interface{}{"siteName": siteName, "daysCount": *a.Config().ServiceSettings.SessionLengthMobileInDays} props := map[string]interface{}{"siteName": siteName, "hoursCount": *a.Config().ServiceSettings.SessionLengthMobileInHours}
return T("api.push_notifications.session.expired", props) return T("api.push_notifications.session.expired", props)
} }

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

@@ -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.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthMobileInDays) a.ch.srv.userService.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthMobileInHours)
// 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.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthMobileInDays) a.ch.srv.userService.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthMobileInHours)
} else if isOAuthUser || isSaml { } else if isOAuthUser || isSaml {
a.ch.srv.userService.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthSSOInDays) a.ch.srv.userService.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthSSOInHours)
} else { } else {
a.ch.srv.userService.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthWebInDays) a.ch.srv.userService.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthWebInHours)
} }
ua := uasurfer.Parse(r.UserAgent()) ua := uasurfer.Parse(r.UserAgent())
@@ -245,9 +245,9 @@ func (a *App) AttachCloudSessionCookie(c *request.Context, w http.ResponseWriter
secure = true secure = true
} }
maxAge := *a.Config().ServiceSettings.SessionLengthWebInDays * 60 * 60 * 24 maxAgeSeconds := *a.Config().ServiceSettings.SessionLengthWebInHours * 60 * 60
subpath, _ := utils.GetSubpathFromConfig(a.Config()) subpath, _ := utils.GetSubpathFromConfig(a.Config())
expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAge), 0) expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAgeSeconds), 0)
domain := "" domain := ""
if siteURL, err := url.Parse(a.GetSiteURL()); err == nil { if siteURL, err := url.Parse(a.GetSiteURL()); err == nil {
@@ -276,7 +276,7 @@ func (a *App) AttachCloudSessionCookie(c *request.Context, w http.ResponseWriter
Name: model.SessionCookieCloudUrl, Name: model.SessionCookieCloudUrl,
Value: workspaceName, Value: workspaceName,
Path: subpath, Path: subpath,
MaxAge: maxAge, MaxAge: maxAgeSeconds,
Expires: expiresAt, Expires: expiresAt,
Domain: domain, Domain: domain,
Secure: secure, Secure: secure,
@@ -292,16 +292,16 @@ func (a *App) AttachSessionCookies(c *request.Context, w http.ResponseWriter, r
secure = true secure = true
} }
maxAge := *a.Config().ServiceSettings.SessionLengthWebInDays * 60 * 60 * 24 maxAgeSeconds := *a.Config().ServiceSettings.SessionLengthWebInHours * 60 * 60
domain := a.GetCookieDomain() domain := a.GetCookieDomain()
subpath, _ := utils.GetSubpathFromConfig(a.Config()) subpath, _ := utils.GetSubpathFromConfig(a.Config())
expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAge), 0) expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAgeSeconds), 0)
sessionCookie := &http.Cookie{ sessionCookie := &http.Cookie{
Name: model.SessionCookieToken, Name: model.SessionCookieToken,
Value: c.Session().Token, Value: c.Session().Token,
Path: subpath, Path: subpath,
MaxAge: maxAge, MaxAge: maxAgeSeconds,
Expires: expiresAt, Expires: expiresAt,
HttpOnly: true, HttpOnly: true,
Domain: domain, Domain: domain,
@@ -312,7 +312,7 @@ func (a *App) AttachSessionCookies(c *request.Context, w http.ResponseWriter, r
Name: model.SessionCookieUser, Name: model.SessionCookieUser,
Value: c.Session().UserId, Value: c.Session().UserId,
Path: subpath, Path: subpath,
MaxAge: maxAge, MaxAge: maxAgeSeconds,
Expires: expiresAt, Expires: expiresAt,
Domain: domain, Domain: domain,
Secure: secure, Secure: secure,
@@ -322,7 +322,7 @@ func (a *App) AttachSessionCookies(c *request.Context, w http.ResponseWriter, r
Name: model.SessionCookieCsrf, Name: model.SessionCookieCsrf,
Value: c.Session().GetCSRF(), Value: c.Session().GetCSRF(),
Path: subpath, Path: subpath,
MaxAge: maxAge, MaxAge: maxAgeSeconds,
Expires: expiresAt, Expires: expiresAt,
Domain: domain, Domain: domain,
Secure: secure, Secure: secure,

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

@@ -317,7 +317,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
AccessToken: accessData.Token, AccessToken: accessData.Token,
TokenType: model.AccessTokenType, TokenType: model.AccessTokenType,
RefreshToken: accessData.RefreshToken, RefreshToken: accessData.RefreshToken,
ExpiresIn: int32((accessData.ExpiresAt - model.GetMillis()) / 1000), ExpiresInSeconds: int32((accessData.ExpiresAt - model.GetMillis()) / 1000),
} }
} }
} else { } else {
@@ -338,7 +338,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
AccessToken: session.Token, AccessToken: session.Token,
TokenType: model.AccessTokenType, TokenType: model.AccessTokenType,
RefreshToken: accessData.RefreshToken, RefreshToken: accessData.RefreshToken,
ExpiresIn: int32(*a.Config().ServiceSettings.SessionLengthSSOInDays * 60 * 60 * 24), ExpiresInSeconds: int32(*a.Config().ServiceSettings.SessionLengthSSOInHours * 60 * 60),
} }
} }
@@ -371,7 +371,7 @@ func (a *App) newSession(app *model.OAuthApp, user *model.User) (*model.Session,
// 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.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthSSOInDays) a.ch.srv.userService.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthSSOInHours)
session.AddProp(model.SessionPropPlatform, app.Name) session.AddProp(model.SessionPropPlatform, app.Name)
session.AddProp(model.SessionPropOAuthAppID, app.Id) session.AddProp(model.SessionPropOAuthAppID, app.Id)
session.AddProp(model.SessionPropMattermostAppID, app.MattermostAppID) session.AddProp(model.SessionPropMattermostAppID, app.MattermostAppID)
@@ -410,7 +410,7 @@ func (a *App) newSessionUpdateToken(app *model.OAuthApp, accessData *model.Acces
AccessToken: session.Token, AccessToken: session.Token,
RefreshToken: accessData.RefreshToken, RefreshToken: accessData.RefreshToken,
TokenType: model.AccessTokenType, TokenType: model.AccessTokenType,
ExpiresIn: int32(*a.Config().ServiceSettings.SessionLengthSSOInDays * 60 * 60 * 24), ExpiresInSeconds: int32(*a.Config().ServiceSettings.SessionLengthSSOInHours * 60 * 60),
} }
return accessRsp, nil return accessRsp, nil

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

@@ -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.SetSessionExpireInDays(session, 1) th.App.SetSessionExpireInHours(session, 24)
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.SetSessionExpireInDays(session, 1) th.App.ch.srv.userService.SetSessionExpireInHours(session, 24)
session, _ = th.App.CreateSession(session) session, _ = th.App.CreateSession(session)

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

@@ -15309,9 +15309,9 @@ func (a *OpenTracingAppLayer) SetSearchEngine(se *searchengine.Broker) {
a.app.SetSearchEngine(se) a.app.SetSearchEngine(se)
} }
func (a *OpenTracingAppLayer) SetSessionExpireInDays(session *model.Session, days int) { func (a *OpenTracingAppLayer) SetSessionExpireInHours(session *model.Session, hours int) {
origCtx := a.ctx origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetSessionExpireInDays") span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetSessionExpireInHours")
a.ctx = newCtx a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx) a.app.Srv().Store.SetContext(newCtx)
@@ -15321,7 +15321,7 @@ func (a *OpenTracingAppLayer) SetSessionExpireInDays(session *model.Session, day
}() }()
defer span.Finish() defer span.Finish()
a.app.SetSessionExpireInDays(session, days) a.app.SetSessionExpireInHours(session, hours)
} }
func (a *OpenTracingAppLayer) SetStatusAwayIfNeeded(userID string, manual bool) { func (a *OpenTracingAppLayer) SetStatusAwayIfNeeded(userID string, manual bool) {

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

@@ -307,22 +307,22 @@ func (a *App) GetSessionLengthInMillis(session *model.Session) int64 {
return 0 return 0
} }
var days int var hours int
if session.IsMobileApp() { if session.IsMobileApp() {
days = *a.Config().ServiceSettings.SessionLengthMobileInDays hours = *a.Config().ServiceSettings.SessionLengthMobileInHours
} else if session.IsSSOLogin() { } else if session.IsSSOLogin() {
days = *a.Config().ServiceSettings.SessionLengthSSOInDays hours = *a.Config().ServiceSettings.SessionLengthSSOInHours
} else { } else {
days = *a.Config().ServiceSettings.SessionLengthWebInDays hours = *a.Config().ServiceSettings.SessionLengthWebInHours
} }
return int64(days * 24 * 60 * 60 * 1000) return int64(hours * 60 * 60 * 1000)
} }
// SetSessionExpireInDays sets the session's expiry the specified number of days // SetSessionExpireInHours sets the session's expiry the specified number of hours
// 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) SetSessionExpireInDays(session *model.Session, days int) { func (a *App) SetSessionExpireInHours(session *model.Session, hours int) {
a.ch.srv.userService.SetSessionExpireInDays(session, days) a.ch.srv.userService.SetSessionExpireInHours(session, hours)
} }
func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError) { func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError) {
@@ -411,7 +411,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.SetSessionExpireInDays(session, model.SessionUserAccessTokenExpiry) a.ch.srv.userService.SetSessionExpireInHours(session, model.SessionUserAccessTokenExpiryHours)
session, nErr = a.Srv().Store.Session().Save(session) session, nErr = a.Srv().Store.Session().Save(session)
if nErr != nil { if nErr != nil {

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

@@ -155,9 +155,9 @@ func TestApp_GetSessionLengthInMillis(t *testing.T) {
th := Setup(t) th := Setup(t)
defer th.TearDown() defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthMobileInDays = 3 }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthMobileInHours = 3 * 24 })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthSSOInDays = 2 }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthSSOInHours = 2 * 24 })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthWebInDays = 1 }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthWebInHours = 24 })
t.Run("get session length mobile", func(t *testing.T) { t.Run("get session length mobile", func(t *testing.T) {
session := &model.Session{ session := &model.Session{
@@ -244,9 +244,9 @@ func TestApp_ExtendExpiryIfNeeded(t *testing.T) {
defer th.TearDown() defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ExtendSessionLengthWithActivity = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ExtendSessionLengthWithActivity = true })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthMobileInDays = 3 }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthMobileInHours = 3 * 24 })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthSSOInDays = 2 }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthSSOInHours = 2 * 24 })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthWebInDays = 1 }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionLengthWebInHours = 24 })
t.Run("expired session should not be extended", func(t *testing.T) { t.Run("expired session should not be extended", func(t *testing.T) {
expires := model.GetMillis() - hourMillis expires := model.GetMillis() - hourMillis

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

@@ -199,14 +199,14 @@ func (us *UserService) RevokeAccessToken(token string) error {
return nil return nil
} }
// SetSessionExpireInDays sets the session's expiry the specified number of days // SetSessionExpireInHours sets the session's expiry the specified number of hours
// 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) SetSessionExpireInDays(session *model.Session, days int) { func (us *UserService) SetSessionExpireInHours(session *model.Session, hours int) {
if session.CreateAt == 0 || *us.config().ServiceSettings.ExtendSessionLengthWithActivity { if session.CreateAt == 0 || *us.config().ServiceSettings.ExtendSessionLengthWithActivity {
session.ExpiresAt = model.GetMillis() + (1000 * 60 * 60 * 24 * int64(days)) session.ExpiresAt = model.GetMillis() + (1000 * 60 * 60 * int64(hours))
} else { } else {
session.ExpiresAt = session.CreateAt + (1000 * 60 * 60 * 24 * int64(days)) session.ExpiresAt = session.CreateAt + (1000 * 60 * 60 * int64(hours))
} }
} }

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

@@ -54,7 +54,7 @@ func TestCache(t *testing.T) {
require.Empty(t, rkeys) require.Empty(t, rkeys)
} }
func TestSetSessionExpireInDays(t *testing.T) { func TestSetSessionExpireInHours(t *testing.T) {
th := Setup(t) th := Setup(t)
defer th.TearDown() defer th.TearDown()
@@ -91,7 +91,7 @@ func TestSetSessionExpireInDays(t *testing.T) {
CreateAt: create, CreateAt: create,
ExpiresAt: model.GetMillis() + dayInMillis, ExpiresAt: model.GetMillis() + dayInMillis,
} }
th.service.SetSessionExpireInDays(session, tt.days) th.service.SetSessionExpireInHours(session, tt.days*24)
// 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.SetSessionExpireInDays(session, 1) th.service.SetSessionExpireInHours(session, 24)
session, _ = th.service.CreateSession(session) session, _ = th.service.CreateSession(session)
err = th.service.RevokeAccessToken(session.Token) err = th.service.RevokeAccessToken(session.Token)

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

@@ -2393,7 +2393,7 @@
}, },
{ {
"id": "api.push_notifications.session.expired", "id": "api.push_notifications.session.expired",
"translation": "Session Expired: Please log in to continue receiving notifications. Sessions for {{.siteName}} are configured by your System Administrator to expire every {{.daysCount}} day(s)." "translation": "Session Expired: Please log in to continue receiving notifications. Sessions for {{.siteName}} are configured by your System Administrator to expire every {{.hoursCount}} hour(s)."
}, },
{ {
"id": "api.push_notifications_ack.forward.app_error", "id": "api.push_notifications_ack.forward.app_error",

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

@@ -143,7 +143,7 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) {
Name: model.SessionCookieToken, Name: model.SessionCookieToken,
Value: client.AuthToken, Value: client.AuthToken,
Path: "/", Path: "/",
MaxAge: *c.App.Config().ServiceSettings.SessionLengthWebInDays * 60 * 60 * 24, MaxAge: *c.App.Config().ServiceSettings.SessionLengthWebInHours * 60 * 60,
HttpOnly: true, HttpOnly: true,
} }
http.SetCookie(w, sessionCookie) http.SetCookie(w, sessionCookie)

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

@@ -26,7 +26,7 @@ type AccessData struct {
type AccessResponse struct { type AccessResponse struct {
AccessToken string `json:"access_token"` AccessToken string `json:"access_token"`
TokenType string `json:"token_type"` TokenType string `json:"token_type"`
ExpiresIn int32 `json:"expires_in"` ExpiresInSeconds int32 `json:"expires_in"`
Scope string `json:"scope"` Scope string `json:"scope"`
RefreshToken string `json:"refresh_token"` RefreshToken string `json:"refresh_token"`
IdToken string `json:"id_token"` IdToken string `json:"id_token"`

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

@@ -323,9 +323,17 @@ type ServiceSettings struct {
CorsDebug *bool `access:"integrations_cors,write_restrictable,cloud_restrictable"` CorsDebug *bool `access:"integrations_cors,write_restrictable,cloud_restrictable"`
AllowCookiesForSubdomains *bool `access:"write_restrictable,cloud_restrictable"` AllowCookiesForSubdomains *bool `access:"write_restrictable,cloud_restrictable"`
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"`
SessionLengthMobileInDays *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"` // Deprecated
SessionLengthSSOInDays *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"` SessionLengthWebInDays *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"` // telemetry: none
SessionLengthWebInHours *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
// Deprecated
SessionLengthMobileInDays *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"` // telemetry: none
SessionLengthMobileInHours *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"`
// Deprecated
SessionLengthSSOInDays *int `access:"environment_session_lengths,write_restrictable,cloud_restrictable"` // telemetry: none
SessionLengthSSOInHours *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
@@ -591,25 +599,46 @@ func (s *ServiceSettings) SetDefaults(isUpdate bool) {
s.ExtendSessionLengthWithActivity = NewBool(!isUpdate) s.ExtendSessionLengthWithActivity = NewBool(!isUpdate)
} }
if s.SessionLengthWebInHours == nil {
var webTTLDays int
if s.SessionLengthWebInDays == nil { if s.SessionLengthWebInDays == nil {
if isUpdate { if isUpdate {
s.SessionLengthWebInDays = NewInt(180) webTTLDays = 180
} else { } else {
s.SessionLengthWebInDays = NewInt(30) webTTLDays = 30
} }
} else {
webTTLDays = *s.SessionLengthWebInDays
} }
s.SessionLengthWebInHours = NewInt(webTTLDays * 24)
}
s.SessionLengthWebInDays = NewInt(-1)
if s.SessionLengthMobileInHours == nil {
var mobileTTLDays int
if s.SessionLengthMobileInDays == nil { if s.SessionLengthMobileInDays == nil {
if isUpdate { if isUpdate {
s.SessionLengthMobileInDays = NewInt(180) mobileTTLDays = 180
} else { } else {
s.SessionLengthMobileInDays = NewInt(30) mobileTTLDays = 30
} }
} else {
mobileTTLDays = *s.SessionLengthMobileInDays
} }
s.SessionLengthMobileInHours = NewInt(mobileTTLDays * 24)
}
s.SessionLengthMobileInDays = NewInt(-1)
if s.SessionLengthSSOInHours == nil {
var ssoTTLDays int
if s.SessionLengthSSOInDays == nil { if s.SessionLengthSSOInDays == nil {
s.SessionLengthSSOInDays = NewInt(30) ssoTTLDays = 30
} else {
ssoTTLDays = *s.SessionLengthSSOInDays
} }
s.SessionLengthSSOInHours = NewInt(ssoTTLDays * 24)
}
s.SessionLengthSSOInDays = NewInt(-1)
if s.SessionCacheInMinutes == nil { if s.SessionCacheInMinutes == nil {
s.SessionCacheInMinutes = NewInt(10) s.SessionCacheInMinutes = NewInt(10)

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

@@ -31,7 +31,7 @@ const (
SessionTypeRemoteclusterToken = "RemoteClusterToken" SessionTypeRemoteclusterToken = "RemoteClusterToken"
SessionPropIsGuest = "is_guest" SessionPropIsGuest = "is_guest"
SessionActivityTimeout = 1000 * 60 * 5 // 5 minutes SessionActivityTimeout = 1000 * 60 * 5 // 5 minutes
SessionUserAccessTokenExpiry = 100 * 365 // 100 years SessionUserAccessTokenExpiryHours = 100 * 365 * 24 // 100 years
) )
//msgp StringMap //msgp StringMap

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

@@ -384,9 +384,9 @@ func (ts *TelemetryService) trackConfig() {
"forward_80_to_443": *cfg.ServiceSettings.Forward80To443, "forward_80_to_443": *cfg.ServiceSettings.Forward80To443,
"maximum_login_attempts": *cfg.ServiceSettings.MaximumLoginAttempts, "maximum_login_attempts": *cfg.ServiceSettings.MaximumLoginAttempts,
"extend_session_length_with_activity": *cfg.ServiceSettings.ExtendSessionLengthWithActivity, "extend_session_length_with_activity": *cfg.ServiceSettings.ExtendSessionLengthWithActivity,
"session_length_web_in_days": *cfg.ServiceSettings.SessionLengthWebInDays, "session_length_web_in_hours": *cfg.ServiceSettings.SessionLengthWebInHours,
"session_length_mobile_in_days": *cfg.ServiceSettings.SessionLengthMobileInDays, "session_length_mobile_in_hours": *cfg.ServiceSettings.SessionLengthMobileInHours,
"session_length_sso_in_days": *cfg.ServiceSettings.SessionLengthSSOInDays, "session_length_sso_in_hours": *cfg.ServiceSettings.SessionLengthSSOInHours,
"session_cache_in_minutes": *cfg.ServiceSettings.SessionCacheInMinutes, "session_cache_in_minutes": *cfg.ServiceSettings.SessionCacheInMinutes,
"session_idle_timeout_in_minutes": *cfg.ServiceSettings.SessionIdleTimeoutInMinutes, "session_idle_timeout_in_minutes": *cfg.ServiceSettings.SessionIdleTimeoutInMinutes,
"isdefault_site_url": isDefault(*cfg.ServiceSettings.SiteURL, model.ServiceSettingsDefaultSiteURL), "isdefault_site_url": isDefault(*cfg.ServiceSettings.SiteURL, model.ServiceSettingsDefaultSiteURL),

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

@@ -36,7 +36,8 @@
"ExtendSessionLengthWithActivity": true, "ExtendSessionLengthWithActivity": true,
"SessionLengthWebInDays": 30, "SessionLengthWebInDays": 30,
"SessionLengthMobileInDays": 30, "SessionLengthMobileInDays": 30,
"SessionLengthSSOInDays": 30, "SessionLengthSSOInDays": -1,
"SessionLengthSSOInHours": 720,
"SessionCacheInMinutes": 10, "SessionCacheInMinutes": 10,
"SessionIdleTimeoutInMinutes": 0, "SessionIdleTimeoutInMinutes": 0,
"WebsocketSecurePort": 443, "WebsocketSecurePort": 443,

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

@@ -132,7 +132,7 @@ func TestHandlerServeCSRFToken(t *testing.T) {
IsOAuth: false, IsOAuth: false,
} }
session.GenerateCSRF() session.GenerateCSRF()
th.App.SetSessionExpireInDays(session, 1) th.App.SetSessionExpireInHours(session, 24)
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)