This is an automated email from the ASF dual-hosted git repository.
vishesh92 pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.20 by this push:
new 8eeccdbb8a2 UI: don’t continue with session with an expired userid
(#13969)
8eeccdbb8a2 is described below
commit 8eeccdbb8a24ad68978a153dc929fc705a027d53
Author: dahn <[email protected]>
AuthorDate: Mon Sep 14 10:34:23 2026 +0200
UI: don’t continue with session with an expired userid (#13969)
---
ui/src/store/modules/user.js | 131 +++++++++++++++++--------------------------
1 file changed, 53 insertions(+), 78 deletions(-)
diff --git a/ui/src/store/modules/user.js b/ui/src/store/modules/user.js
index 21cd603e378..eb3fdccb5e2 100644
--- a/ui/src/store/modules/user.js
+++ b/ui/src/store/modules/user.js
@@ -46,6 +46,51 @@ import {
LATEST_CS_VERSION
} from '@/store/mutation-types'
+function setLoginCookies (result) {
+ Cookies.set('account', result.account)
+ Cookies.set('domainid', result.domainid)
+ Cookies.set('role', result.type)
+ Cookies.set('timezone', result.timezone)
+ Cookies.set('timezoneoffset', result.timezoneoffset)
+ Cookies.set('userfullname', result.firstname + ' ' + result.lastname)
+ Cookies.set('userid', result.userid)
+ Cookies.set('username', result.username)
+}
+
+function processLoginResponse (commit, response) {
+ const result = response.loginresponse || {}
+ setLoginCookies(result)
+ vueProps.$localStorage.set(ACCESS_TOKEN, result.sessionkey, 24 * 60 * 60 *
1000)
+ commit('SET_TOKEN', result.sessionkey)
+ commit('SET_TIMEZONE_OFFSET', result.timezoneoffset)
+
+ const cachedUseBrowserTimezone =
vueProps.$localStorage.get(USE_BROWSER_TIMEZONE, false)
+ commit('SET_USE_BROWSER_TIMEZONE', cachedUseBrowserTimezone)
+ const darkMode = vueProps.$localStorage.get(DARK_MODE, false)
+ commit('SET_DARK_MODE', darkMode)
+ const cachedCustomColumns = vueProps.$localStorage.get(CUSTOM_COLUMNS, {})
+ commit('SET_CUSTOM_COLUMNS', cachedCustomColumns)
+
+ commit('SET_APIS', {})
+ commit('SET_NAME', '')
+ commit('SET_AVATAR', '')
+ commit('SET_INFO', {})
+ commit('SET_PROJECT', {})
+ commit('SET_HEADER_NOTICES', [])
+ commit('SET_FEATURES', {})
+ commit('SET_LDAP', {})
+ commit('SET_CLOUDIAN', {})
+ commit('SET_DOMAIN_STORE', {})
+ commit('SET_LOGOUT_FLAG', false)
+ commit('SET_2FA_ENABLED', (result.is2faenabled === 'true'))
+ commit('SET_2FA_PROVIDER', result.providerfor2fa)
+ commit('SET_2FA_ISSUER', result.issuerfor2fa)
+ commit('SET_LOGIN_FLAG', false)
+ const latestVersion = vueProps.$localStorage.get(LATEST_CS_VERSION, {
version: '', fetchedTs: 0 })
+ commit('SET_LATEST_VERSION', latestVersion)
+ notification.destroy()
+}
+
const user = {
state: {
token: '',
@@ -192,45 +237,7 @@ const user = {
Login ({ commit }, userInfo) {
return new Promise((resolve, reject) => {
login(userInfo).then(response => {
- const result = response.loginresponse || {}
- Cookies.set('account', result.account, { expires: 1 })
- Cookies.set('domainid', result.domainid, { expires: 1 })
- Cookies.set('role', result.type, { expires: 1 })
- Cookies.set('timezone', result.timezone, { expires: 1 })
- Cookies.set('timezoneoffset', result.timezoneoffset, { expires: 1 })
- Cookies.set('userfullname', result.firstname + ' ' +
result.lastname, { expires: 1 })
- Cookies.set('userid', result.userid, { expires: 1 })
- Cookies.set('username', result.username, { expires: 1 })
- vueProps.$localStorage.set(ACCESS_TOKEN, result.sessionkey, 24 * 60
* 60 * 1000)
- commit('SET_TOKEN', result.sessionkey)
- commit('SET_TIMEZONE_OFFSET', result.timezoneoffset)
-
- const cachedUseBrowserTimezone =
vueProps.$localStorage.get(USE_BROWSER_TIMEZONE, false)
- commit('SET_USE_BROWSER_TIMEZONE', cachedUseBrowserTimezone)
- const darkMode = vueProps.$localStorage.get(DARK_MODE, false)
- commit('SET_DARK_MODE', darkMode)
- const cachedCustomColumns =
vueProps.$localStorage.get(CUSTOM_COLUMNS, {})
- commit('SET_CUSTOM_COLUMNS', cachedCustomColumns)
-
- commit('SET_APIS', {})
- commit('SET_NAME', '')
- commit('SET_AVATAR', '')
- commit('SET_INFO', {})
- commit('SET_PROJECT', {})
- commit('SET_HEADER_NOTICES', [])
- commit('SET_FEATURES', {})
- commit('SET_LDAP', {})
- commit('SET_CLOUDIAN', {})
- commit('SET_DOMAIN_STORE', {})
- commit('SET_LOGOUT_FLAG', false)
- commit('SET_2FA_ENABLED', (result.is2faenabled === 'true'))
- commit('SET_2FA_PROVIDER', result.providerfor2fa)
- commit('SET_2FA_ISSUER', result.issuerfor2fa)
- commit('SET_LOGIN_FLAG', false)
- const latestVersion = vueProps.$localStorage.get(LATEST_CS_VERSION,
{ version: '', fetchedTs: 0 })
- commit('SET_LATEST_VERSION', latestVersion)
- notification.destroy()
-
+ processLoginResponse(commit, response)
resolve()
}).catch(error => {
reject(error)
@@ -241,45 +248,7 @@ const user = {
OauthLogin ({ commit }, userInfo) {
return new Promise((resolve, reject) => {
oauthlogin(userInfo).then(response => {
- const result = response.loginresponse || {}
- Cookies.set('account', result.account, { expires: 1 })
- Cookies.set('domainid', result.domainid, { expires: 1 })
- Cookies.set('role', result.type, { expires: 1 })
- Cookies.set('timezone', result.timezone, { expires: 1 })
- Cookies.set('timezoneoffset', result.timezoneoffset, { expires: 1 })
- Cookies.set('userfullname', result.firstname + ' ' +
result.lastname, { expires: 1 })
- Cookies.set('userid', result.userid, { expires: 1 })
- Cookies.set('username', result.username, { expires: 1 })
- vueProps.$localStorage.set(ACCESS_TOKEN, result.sessionkey, 24 * 60
* 60 * 1000)
- commit('SET_TOKEN', result.sessionkey)
- commit('SET_TIMEZONE_OFFSET', result.timezoneoffset)
-
- const cachedUseBrowserTimezone =
vueProps.$localStorage.get(USE_BROWSER_TIMEZONE, false)
- commit('SET_USE_BROWSER_TIMEZONE', cachedUseBrowserTimezone)
- const darkMode = vueProps.$localStorage.get(DARK_MODE, false)
- commit('SET_DARK_MODE', darkMode)
- const cachedCustomColumns =
vueProps.$localStorage.get(CUSTOM_COLUMNS, {})
- commit('SET_CUSTOM_COLUMNS', cachedCustomColumns)
-
- commit('SET_APIS', {})
- commit('SET_NAME', '')
- commit('SET_AVATAR', '')
- commit('SET_INFO', {})
- commit('SET_PROJECT', {})
- commit('SET_HEADER_NOTICES', [])
- commit('SET_FEATURES', {})
- commit('SET_LDAP', {})
- commit('SET_CLOUDIAN', {})
- commit('SET_DOMAIN_STORE', {})
- commit('SET_LOGOUT_FLAG', false)
- commit('SET_2FA_ENABLED', (result.is2faenabled === 'true'))
- commit('SET_2FA_PROVIDER', result.providerfor2fa)
- commit('SET_2FA_ISSUER', result.issuerfor2fa)
- commit('SET_LOGIN_FLAG', false)
- const latestVersion = vueProps.$localStorage.get(LATEST_CS_VERSION,
{ version: '', fetchedTs: 0 })
- commit('SET_LATEST_VERSION', latestVersion)
- notification.destroy()
-
+ processLoginResponse(commit, response)
resolve()
}).catch(error => {
reject(error)
@@ -304,6 +273,11 @@ const user = {
commit('SET_DARK_MODE', darkMode)
commit('SET_LATEST_VERSION', latestVersion)
if (hasAuth) {
+ if (!Cookies.get('userid')) {
+ reject(new Error('Identity session expired'))
+ return
+ }
+
console.log('Login detected, using cached APIs')
commit('SET_ZONES', cachedZones)
commit('SET_SHOW_SECURITY_GROUPS', cachedShowSecurityGroups)
@@ -433,6 +407,7 @@ const user = {
})
}).catch(error => {
console.error(error)
+ throw error
})
},