summaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
authorYoshie Muranaka <yoshiemuranaka@gmail.com>2020-04-09 22:41:27 +0300
committerYoshie Muranaka <yoshiemuranaka@gmail.com>2020-04-25 01:48:35 +0300
commitc4e38abf5c31d77474d5287620d1ddc8089b6dae (patch)
tree9f606da745a8f8f30db41f9794c925cc9590fb37 /src/store
parent9e36f522b94511c1d77335493c09e68975db031c (diff)
downloadwebui-vue-c4e38abf5c31d77474d5287620d1ddc8089b6dae.tar.xz
Add LDAP page
Adds ability to enable LDAP service and modify LDAP and ActiveDirectory properties. Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com> Change-Id: I59d65bba7f6fe321af395227ce2f7188d9c006b7
Diffstat (limited to 'src/store')
-rw-r--r--src/store/index.js2
-rw-r--r--src/store/modules/AccessControl/LdapStore.js156
2 files changed, 158 insertions, 0 deletions
diff --git a/src/store/index.js b/src/store/index.js
index 0180213d..364e16c0 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -3,6 +3,7 @@ import Vuex from 'vuex';
import GlobalStore from './modules/GlobalStore';
import AuthenticationStore from './modules/Authentication/AuthenticanStore';
+import LdapStore from './modules/AccessControl/LdapStore';
import LocalUserManagementStore from './modules/AccessControl/LocalUserMangementStore';
import SslCertificatesStore from './modules/AccessControl/SslCertificatesStore';
import OverviewStore from './modules/Overview/OverviewStore';
@@ -25,6 +26,7 @@ export default new Vuex.Store({
modules: {
global: GlobalStore,
authentication: AuthenticationStore,
+ ldap: LdapStore,
localUsers: LocalUserManagementStore,
overview: OverviewStore,
firmware: FirmwareStore,
diff --git a/src/store/modules/AccessControl/LdapStore.js b/src/store/modules/AccessControl/LdapStore.js
new file mode 100644
index 00000000..54fbbccd
--- /dev/null
+++ b/src/store/modules/AccessControl/LdapStore.js
@@ -0,0 +1,156 @@
+import api from '@/store/api';
+import i18n from '@/i18n';
+
+const LdapStore = {
+ namespaced: true,
+ state: {
+ isServiceEnabled: null,
+ ldap: {
+ serviceEnabled: null,
+ serviceAddress: null,
+ bindDn: null,
+ baseDn: null,
+ userAttribute: null,
+ groupsAttribute: null
+ },
+ activeDirectory: {
+ serviceEnabled: null,
+ serviceAddress: null,
+ bindDn: null,
+ baseDn: null,
+ userAttribute: null,
+ groupsAttribute: null
+ }
+ },
+ getters: {
+ isServiceEnabled: state => state.isServiceEnabled,
+ ldap: state => state.ldap,
+ activeDirectory: state => state.activeDirectory
+ },
+ mutations: {
+ setServiceEnabled: (state, serviceEnabled) =>
+ (state.isServiceEnabled = serviceEnabled),
+ setLdapProperties: (
+ state,
+ {
+ ServiceEnabled,
+ ServiceAddresses,
+ Authentication = {},
+ LDAPService: { SearchSettings = {} } = {}
+ }
+ ) => {
+ state.ldap.serviceAddress = ServiceAddresses[0];
+ state.ldap.serviceEnabled = ServiceEnabled;
+ state.ldap.baseDn = SearchSettings.BaseDistinguishedNames[0];
+ state.ldap.bindDn = Authentication.Username;
+ state.ldap.userAttribute = SearchSettings.UsernameAttribute;
+ state.ldap.groupsAttribute = SearchSettings.GroupsAttribute;
+ },
+ setActiveDirectoryProperties: (
+ state,
+ {
+ ServiceEnabled,
+ ServiceAddresses,
+ Authentication = {},
+ LDAPService: { SearchSettings = {} } = {}
+ }
+ ) => {
+ state.activeDirectory.serviceEnabled = ServiceEnabled;
+ state.activeDirectory.serviceAddress = ServiceAddresses[0];
+ state.activeDirectory.bindDn = Authentication.Username;
+ state.activeDirectory.baseDn = SearchSettings.BaseDistinguishedNames[0];
+ state.activeDirectory.userAttribute = SearchSettings.UsernameAttribute;
+ state.activeDirectory.groupsAttribute = SearchSettings.GroupsAttribute;
+ }
+ },
+ actions: {
+ getAccountSettings({ commit }) {
+ api
+ .get('/redfish/v1/AccountService')
+ .then(({ data: { LDAP = {}, ActiveDirectory = {} } }) => {
+ const ldapEnabled = LDAP.ServiceEnabled;
+ const activeDirectoryEnabled = ActiveDirectory.ServiceEnabled;
+
+ commit('setServiceEnabled', ldapEnabled || activeDirectoryEnabled);
+ commit('setLdapProperties', LDAP);
+ commit('setActiveDirectoryProperties', ActiveDirectory);
+ })
+ .catch(error => console.log(error));
+ },
+ async saveLdapSettings({ state, dispatch }, properties) {
+ const data = { LDAP: properties };
+ if (state.activeDirectory.serviceEnabled) {
+ // Disable Active Directory service if enabled
+ await api.patch('/redfish/v1/AccountService', {
+ ActiveDirectory: { ServiceEnabled: false }
+ });
+ }
+ return await api
+ .patch('/redfish/v1/AccountService', data)
+ .then(() => dispatch('getAccountSettings'))
+ .then(() => i18n.t('pageLdap.toast.successSaveLdapSettings'))
+ .catch(error => {
+ console.log(error);
+ throw new Error(i18n.t('pageLdap.toast.errorSaveLdapSettings'));
+ });
+ },
+ async saveActiveDirectorySettings({ state, dispatch }, properties) {
+ const data = { ActiveDirectory: properties };
+ if (state.ldap.serviceEnabled) {
+ // Disable LDAP service if enabled
+ await api.patch('/redfish/v1/AccountService', {
+ LDAP: { ServiceEnabled: false }
+ });
+ }
+ return await api
+ .patch('/redfish/v1/AccountService', data)
+ .then(() => dispatch('getAccountSettings'))
+ .then(() => i18n.t('pageLdap.toast.successSaveActiveDirectorySettings'))
+ .catch(error => {
+ console.log(error);
+ throw new Error(
+ i18n.t('pageLdap.toast.errorSaveActiveDirectorySettings')
+ );
+ });
+ },
+ async saveAccountSettings(
+ { dispatch },
+ {
+ serviceEnabled,
+ serviceAddress,
+ activeDirectoryEnabled,
+ bindDn,
+ bindPassword,
+ baseDn,
+ userIdAttribute,
+ groupIdAttribute
+ }
+ ) {
+ const data = {
+ ServiceEnabled: serviceEnabled,
+ ServiceAddresses: [serviceAddress],
+ Authentication: {
+ Username: bindDn,
+ Password: bindPassword
+ },
+ LDAPService: {
+ SearchSettings: {
+ BaseDistinguishedNames: [baseDn]
+ }
+ }
+ };
+ if (groupIdAttribute)
+ data.LDAPService.SearchSettings.GroupsAttribute = groupIdAttribute;
+ if (userIdAttribute)
+ data.LDAPService.SearchSettings.UsernameAttribute = userIdAttribute;
+
+ if (activeDirectoryEnabled) {
+ return await dispatch('saveActiveDirectorySettings', data);
+ } else {
+ return await dispatch('saveLdapSettings', data);
+ }
+ }
+ }
+};
+
+export default LdapStore;