summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYoshie Muranaka <yoshiemuranaka@gmail.com>2020-09-22 00:35:58 +0300
committerDerick Montague <derick.montague@ibm.com>2020-10-23 17:15:50 +0300
commitd624dae9d6727a09f6eb33b95c19986826359d6c (patch)
treec2e036e30e059595d922138d63738cf876f163c5 /src
parentef8c3f33b580b6bba09268765326ac7900eea65a (diff)
downloadwebui-vue-d624dae9d6727a09f6eb33b95c19986826359d6c.tar.xz
Add support for mutual TLS
Adding check for 'IsAuthenticated' cookie in AuthenticationStore and adding a check in created hook for AppHeader component because it is visible on all authenticated pages. Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com> Change-Id: Ic558c9c45fd3f5874c8c516cb6bc005cba4946e2
Diffstat (limited to 'src')
-rw-r--r--src/components/AppHeader/AppHeader.vue3
-rw-r--r--src/store/modules/Authentication/AuthenticanStore.js27
-rw-r--r--src/views/Login/Login.vue2
3 files changed, 24 insertions, 8 deletions
diff --git a/src/components/AppHeader/AppHeader.vue b/src/components/AppHeader/AppHeader.vue
index 4eba7522..5f05406a 100644
--- a/src/components/AppHeader/AppHeader.vue
+++ b/src/components/AppHeader/AppHeader.vue
@@ -169,6 +169,9 @@ export default {
}
},
created() {
+ // Reset auth state to check if user is authenticated based
+ // on available browser cookies
+ this.$store.dispatch('authentication/resetStoreState');
this.getHostInfo();
this.getEvents();
},
diff --git a/src/store/modules/Authentication/AuthenticanStore.js b/src/store/modules/Authentication/AuthenticanStore.js
index 0dd616a9..c42b9da1 100644
--- a/src/store/modules/Authentication/AuthenticanStore.js
+++ b/src/store/modules/Authentication/AuthenticanStore.js
@@ -6,31 +6,39 @@ const AuthenticationStore = {
namespaced: true,
state: {
authError: false,
- cookie: Cookies.get('XSRF-TOKEN')
+ xsrfCookie: Cookies.get('XSRF-TOKEN'),
+ isAuthenticatedCookie: Cookies.get('IsAuthenticated')
},
getters: {
authError: state => state.authError,
- isLoggedIn: state => !!state.cookie,
- token: state => state.cookie
+ isLoggedIn: state => {
+ return (
+ state.xsrfCookie !== undefined || state.isAuthenticatedCookie == 'true'
+ );
+ },
+ token: state => state.xsrfCookie
},
mutations: {
authSuccess(state) {
state.authError = false;
- state.cookie = Cookies.get('XSRF-TOKEN');
+ state.xsrfCookie = Cookies.get('XSRF-TOKEN');
},
authError(state, authError = true) {
state.authError = authError;
},
- logout() {
+ logout(state) {
Cookies.remove('XSRF-TOKEN');
+ Cookies.remove('IsAuthenticated');
localStorage.removeItem('storedUsername');
+ state.xsrfCookie = undefined;
+ state.isAuthenticatedCookie = undefined;
}
},
actions: {
- login({ commit }, auth) {
+ login({ commit }, { username, password }) {
commit('authError', false);
return api
- .post('/login', { data: auth })
+ .post('/login', { data: [username, password] })
.then(() => commit('authSuccess'))
.catch(error => {
commit('authError');
@@ -49,6 +57,11 @@ const AuthenticationStore = {
.get(`/redfish/v1/AccountService/Accounts/${username}`)
.then(({ data: { PasswordChangeRequired } }) => PasswordChangeRequired)
.catch(error => console.log(error));
+ },
+ resetStoreState({ state }) {
+ state.authError = false;
+ state.xsrfCookie = Cookies.get('XSRF-TOKEN');
+ state.isAuthenticatedCookie = Cookies.get('IsAuthenticated');
}
}
};
diff --git a/src/views/Login/Login.vue b/src/views/Login/Login.vue
index 4d523de6..dd0a415b 100644
--- a/src/views/Login/Login.vue
+++ b/src/views/Login/Login.vue
@@ -117,7 +117,7 @@ export default {
const username = this.userInfo.username;
const password = this.userInfo.password;
this.$store
- .dispatch('authentication/login', [username, password])
+ .dispatch('authentication/login', { username, password })
.then(() => {
localStorage.setItem('storedLanguage', i18n.locale);
localStorage.setItem('storedUsername', username);