You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2020/09/25 12:48:34 UTC
[cloudstack-primate] branch master updated: Fixing login,
session expired and blacklisted api requests
This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack-primate.git
The following commit(s) were added to refs/heads/master by this push:
new c5da02e Fixing login, session expired and blacklisted api requests
new 2f1767d Merge pull request #745 from shapeblue/fix-api-perms
c5da02e is described below
commit c5da02e24796cbbe379b8a6e0b8cd6fc6b71a5a7
Author: davidjumani <dj...@gmail.com>
AuthorDate: Thu Sep 24 17:32:46 2020 +0530
Fixing login, session expired and blacklisted api requests
---
src/locales/en.json | 1 +
src/permission.js | 3 ++-
src/store/modules/user.js | 5 +++++
src/utils/request.js | 19 ++++++++++++++++---
src/views/AutogenView.vue | 18 +++++++++++-------
src/views/iam/DomainView.vue | 11 ++++-------
6 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/src/locales/en.json b/src/locales/en.json
index b7af2d0..5530fbd 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -25,6 +25,7 @@
"error.release.dedicate.zone": "Failed to release dedicated zone",
"error.session.expired": "Your session has expired.",
"error.unable.to.reach.management.server": "Unable to reach Management Server",
+"error.unable.to.proceed": "Unable to proceed. Please contact your administrator",
"error.unresolved.internet.name": "Your internet name cannot be resolved.",
"firewall.close": "Firewall",
"force.delete.domain.warning": "Warning: Choosing this option will cause the deletion of all child domains and all associated accounts and their resources.",
diff --git a/src/permission.js b/src/permission.js
index 161a1b4..d22c00f 100644
--- a/src/permission.js
+++ b/src/permission.js
@@ -66,7 +66,8 @@ router.beforeEach((to, from, next) => {
.catch(() => {
notification.error({
message: 'Error',
- description: i18n.t('message.error.discovering.feature')
+ description: i18n.t('message.error.discovering.feature'),
+ duration: 0
})
store.dispatch('Logout').then(() => {
next({ path: '/user/login', query: { redirect: to.fullPath } })
diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index 76271ff..aba087d 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -19,6 +19,7 @@ import Cookies from 'js-cookie'
import Vue from 'vue'
import md5 from 'md5'
import message from 'ant-design-vue/es/message'
+import notification from 'ant-design-vue/es/notification'
import router from '@/router'
import store from '@/store'
import { login, logout, api } from '@/api'
@@ -112,6 +113,8 @@ const user = {
commit('SET_LDAP', {})
commit('SET_CLOUDIAN', {})
+ notification.destroy()
+
resolve()
}).catch(error => {
reject(error)
@@ -148,6 +151,8 @@ const user = {
api('listZones', { listall: true }).then(json => {
const zones = json.listzonesresponse.zone || []
commit('SET_ZONES', zones)
+ }).catch(error => {
+ reject(error)
})
api('listApis').then(response => {
const apis = {}
diff --git a/src/utils/request.js b/src/utils/request.js
index ffc62eb..9371aee 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -37,16 +37,29 @@ const err = (error) => {
notification.error({ message: i18n.t('label.forbidden'), description: data.message })
}
if (response.status === 401) {
- if (response.config && response.config.params && ['listIdps'].includes(response.config.params.command)) {
+ if (response.config && response.config.params && ['listIdps', 'cloudianIsEnabled'].includes(response.config.params.command)) {
return
}
+ for (const key in response.data) {
+ if (key.includes('response')) {
+ if (response.data[key].errortext.includes('not available for user')) {
+ notification.error({
+ message: 'Error',
+ description: response.data[key].errortext + ' ' + i18n.t('error.unable.to.proceed'),
+ duration: 0
+ })
+ return
+ }
+ }
+ }
notification.error({
message: i18n.t('label.unauthorized'),
description: i18n.t('message.authorization.failed'),
- key: 'http-401'
+ key: 'http-401',
+ duration: 0
})
store.dispatch('Logout').then(() => {
- router.go(0)
+ router.push({ path: '/user/login', query: { redirect: router.history.current.fullPath } })
})
}
if (response.status === 404) {
diff --git a/src/views/AutogenView.vue b/src/views/AutogenView.vue
index 6b2272e..c8742b4 100644
--- a/src/views/AutogenView.vue
+++ b/src/views/AutogenView.vue
@@ -646,6 +646,10 @@ export default {
}
}
}).catch(error => {
+ if ([401].includes(error.response.status)) {
+ return
+ }
+
if (Object.keys(this.searchParams).length > 0) {
this.itemCount = 0
this.items = []
@@ -656,13 +660,6 @@ export default {
return
}
- if ([401].includes(error.response.status)) {
- store.dispatch('Logout').then(() => {
- this.$router.push({ path: '/user/login', query: { redirect: this.$route.fullPath } })
- })
- return
- }
-
this.$notifyError(error)
if ([405].includes(error.response.status)) {
@@ -890,6 +887,9 @@ export default {
api(action.api, params).then(json => {
this.handleResponse(json, resourceName, action, false)
}).catch(error => {
+ if ([401].includes(error.response.status)) {
+ return
+ }
this.$notifyError(error)
})
},
@@ -990,6 +990,10 @@ export default {
}
this.closeAction()
}).catch(error => {
+ if ([401].includes(error.response.status)) {
+ return
+ }
+
console.log(error)
this.$notifyError(error)
}).finally(f => {
diff --git a/src/views/iam/DomainView.vue b/src/views/iam/DomainView.vue
index 287ca56..12ba40b 100644
--- a/src/views/iam/DomainView.vue
+++ b/src/views/iam/DomainView.vue
@@ -175,19 +175,16 @@ export default {
this.resource = domains[0] || {}
this.treeSelected = domains[0] || {}
}).catch(error => {
+ if ([401].includes(error.response.status)) {
+ return
+ }
+
this.$notification.error({
message: this.$t('message.request.failed'),
description: error.response.headers['x-description'],
duration: 0
})
- if ([401].includes(error.response.status)) {
- store.dispatch('Logout').then(() => {
- this.$router.push({ path: '/user/login', query: { redirect: this.$route.fullPath } })
- })
- return
- }
-
if ([405].includes(error.response.status)) {
this.$router.push({ path: '/exception/403' })
}