blob: 50ba8f168f7f6b0dc4ae1f0e6f39bd818837a7ff [file] [log] [blame]
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -07001<template>
2 <b-container fluid="xl">
3 <page-title :description="$t('pageLdap.pageDescription')" />
4 <page-section :section-title="$t('pageLdap.settings')">
5 <b-form novalidate @submit.prevent="handleSubmit">
6 <b-row>
7 <b-col>
8 <b-form-group
9 class="mb-3"
10 :label="$t('pageLdap.form.ldapAuthentication')"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070011 label-for="enable-ldap-auth"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -070012 >
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -070013 <b-form-checkbox
14 id="enable-ldap-auth"
15 v-model="form.ldapAuthenticationEnabled"
SurenNewared1988ad2020-07-23 18:02:25 +053016 data-test-id="ldap-checkbox-ldapAuthenticationEnabled"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -070017 @change="onChangeldapAuthenticationEnabled"
18 >
19 {{ $t('global.action.enable') }}
20 </b-form-checkbox>
21 </b-form-group>
22 </b-col>
23 </b-row>
24 <div class="form-background p-3">
25 <b-form-group
26 class="m-0"
27 :label="$t('pageLdap.ariaLabel.ldapSettings')"
28 label-class="sr-only"
29 :disabled="!form.ldapAuthenticationEnabled"
30 >
31 <b-row>
32 <b-col md="3" lg="4" xl="3">
33 <b-form-group
34 class="mb-4"
35 :label="$t('pageLdap.form.secureLdapUsingSsl')"
36 >
37 <b-form-text id="enable-secure-help-block">
38 {{ $t('pageLdap.form.secureLdapHelper') }}
39 </b-form-text>
40 <b-form-checkbox
41 id="enable-secure-ldap"
42 v-model="form.secureLdapEnabled"
43 aria-describedby="enable-secure-help-block"
SurenNewared1988ad2020-07-23 18:02:25 +053044 data-test-id="ldap-checkbox-secureLdapEnabled"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -070045 :disabled="
46 !caCertificateExpiration || !ldapCertificateExpiration
47 "
48 @change="$v.form.secureLdapEnabled.$touch()"
49 >
50 {{ $t('global.action.enable') }}
51 </b-form-checkbox>
52 </b-form-group>
53 <dl>
54 <dt>{{ $t('pageLdap.form.caCertificateValidUntil') }}</dt>
55 <dd v-if="caCertificateExpiration">
56 {{ caCertificateExpiration | formatDate }}
57 </dd>
58 <dd v-else>--</dd>
59 <dt>{{ $t('pageLdap.form.ldapCertificateValidUntil') }}</dt>
60 <dd v-if="ldapCertificateExpiration">
61 {{ ldapCertificateExpiration | formatDate }}
62 </dd>
63 <dd v-else>--</dd>
64 </dl>
65 <b-link
66 class="d-inline-block mb-4 m-md-0"
67 to="/access-control/ssl-certificates"
68 >
69 {{ $t('pageLdap.form.manageSslCertificates') }}
70 </b-link>
71 </b-col>
72 <b-col md="9" lg="8" xl="9">
73 <b-row>
74 <b-col>
75 <b-form-group :label="$t('pageLdap.form.serviceType')">
76 <b-form-radio
77 v-model="form.activeDirectoryEnabled"
SurenNewared1988ad2020-07-23 18:02:25 +053078 data-test-id="ldap-radio-activeDirectoryEnabled"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -070079 :value="false"
80 @change="onChangeServiceType"
81 >
82 OpenLDAP
83 </b-form-radio>
84 <b-form-radio
85 v-model="form.activeDirectoryEnabled"
SurenNewared1988ad2020-07-23 18:02:25 +053086 data-test-id="ldap-radio-activeDirectoryEnabled"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -070087 :value="true"
88 @change="onChangeServiceType"
89 >
90 Active Directory
91 </b-form-radio>
92 </b-form-group>
93 </b-col>
94 </b-row>
95 <b-row>
96 <b-col sm="6" xl="4">
97 <b-form-group label-for="server-uri">
98 <template v-slot:label>
99 {{ $t('pageLdap.form.serverUri') }}
100 <info-tooltip
101 :title="$t('pageLdap.form.serverUriTooltip')"
102 />
103 </template>
104 <b-input-group :prepend="ldapProtocol">
105 <b-form-input
106 id="server-uri"
107 v-model="form.serverUri"
SurenNewared1988ad2020-07-23 18:02:25 +0530108 data-test-id="ldap-input-serverUri"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700109 :state="getValidationState($v.form.serverUri)"
110 @change="$v.form.serverUri.$touch()"
111 />
112 <b-form-invalid-feedback role="alert">
113 {{ $t('global.form.fieldRequired') }}
114 </b-form-invalid-feedback>
115 </b-input-group>
116 </b-form-group>
117 </b-col>
118 <b-col sm="6" xl="4">
119 <b-form-group
120 :label="$t('pageLdap.form.bindDn')"
121 label-for="bind-dn"
122 >
123 <b-form-input
124 id="bind-dn"
125 v-model="form.bindDn"
SurenNewared1988ad2020-07-23 18:02:25 +0530126 data-test-id="ldap-input-bindDn"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700127 :state="getValidationState($v.form.bindDn)"
128 @change="$v.form.bindDn.$touch()"
129 />
130 <b-form-invalid-feedback role="alert">
131 {{ $t('global.form.fieldRequired') }}
132 </b-form-invalid-feedback>
133 </b-form-group>
134 </b-col>
135 <b-col sm="6" xl="4">
136 <b-form-group
137 :label="$t('pageLdap.form.bindPassword')"
138 label-for="bind-password"
139 >
SurenNewared1988ad2020-07-23 18:02:25 +0530140 <input-password-toggle
141 data-test-id="ldap-input-togglePassword"
142 >
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700143 <b-form-input
144 id="bind-password"
145 v-model="form.bindPassword"
146 type="password"
147 :state="getValidationState($v.form.bindPassword)"
148 @change="$v.form.bindPassword.$touch()"
149 />
150 <b-form-invalid-feedback role="alert">
151 {{ $t('global.form.fieldRequired') }}
152 </b-form-invalid-feedback>
153 </input-password-toggle>
154 </b-form-group>
155 </b-col>
156 <b-col sm="6" xl="4">
157 <b-form-group
158 :label="$t('pageLdap.form.baseDn')"
159 label-for="base-dn"
160 >
161 <b-form-input
162 id="base-dn"
163 v-model="form.baseDn"
SurenNewared1988ad2020-07-23 18:02:25 +0530164 data-test-id="ldap-input-baseDn"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700165 :state="getValidationState($v.form.baseDn)"
166 @change="$v.form.baseDn.$touch()"
167 />
168 <b-form-invalid-feedback role="alert">
169 {{ $t('global.form.fieldRequired') }}
170 </b-form-invalid-feedback>
171 </b-form-group>
172 </b-col>
173 <b-col sm="6" xl="4">
174 <b-form-group
175 :label="$t('pageLdap.form.userIdAttribute')"
176 label-for="user-id-attribute"
177 >
178 <b-form-input
179 id="user-id-attribute"
180 v-model="form.userIdAttribute"
SurenNewared1988ad2020-07-23 18:02:25 +0530181 data-test-id="ldap-input-userIdAttribute"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700182 @change="$v.form.userIdAttribute.$touch()"
183 />
184 </b-form-group>
185 </b-col>
186 <b-col sm="6" xl="4">
187 <b-form-group
188 :label="$t('pageLdap.form.groupIdAttribute')"
189 label-for="group-id-attribute"
190 >
191 <b-form-input
192 id="group-id-attribute"
193 v-model="form.groupIdAttribute"
SurenNewared1988ad2020-07-23 18:02:25 +0530194 data-test-id="ldap-input-groupIdAttribute"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700195 @change="$v.form.groupIdAttribute.$touch()"
196 />
197 </b-form-group>
198 </b-col>
199 </b-row>
200 </b-col>
201 </b-row>
202 </b-form-group>
203 </div>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700204 <b-row class="mt-4 mb-5">
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700205 <b-col>
206 <b-btn
207 variant="primary"
208 type="submit"
SurenNewared1988ad2020-07-23 18:02:25 +0530209 data-test-id="ldap-button-saveSettings"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700210 :disabled="!$v.form.$anyDirty"
211 >
212 {{ $t('global.action.saveSettings') }}
213 </b-btn>
214 </b-col>
215 </b-row>
216 </b-form>
217 </page-section>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700218
219 <!-- Role groups -->
220 <page-section :section-title="$t('pageLdap.roleGroups')">
221 <table-role-groups />
222 </page-section>
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700223 </b-container>
224</template>
225
226<script>
227import { mapGetters } from 'vuex';
228import { find } from 'lodash';
229import { requiredIf } from 'vuelidate/lib/validators';
230
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700231import BVToastMixin from '@/components/Mixins/BVToastMixin';
232import VuelidateMixin from '@/components/Mixins/VuelidateMixin';
233import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Derick Montagued853fba2020-07-16 11:24:10 -0500234import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700235import PageTitle from '@/components/Global/PageTitle';
236import PageSection from '@/components/Global/PageSection';
237import InfoTooltip from '@/components/Global/InfoTooltip';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700238import TableRoleGroups from './TableRoleGroups';
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700239
240export default {
241 name: 'Ldap',
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700242 components: {
243 InfoTooltip,
244 InputPasswordToggle,
245 PageTitle,
246 PageSection,
247 TableRoleGroups
248 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700249 mixins: [BVToastMixin, VuelidateMixin, LoadingBarMixin],
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700250 data() {
251 return {
252 form: {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700253 ldapAuthenticationEnabled: this.$store.getters['ldap/isServiceEnabled'],
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700254 secureLdapEnabled: false,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700255 activeDirectoryEnabled: this.$store.getters[
256 'ldap/isActiveDirectoryEnabled'
257 ],
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700258 serverUri: '',
259 bindDn: '',
260 bindPassword: '',
261 baseDn: '',
262 userIdAttribute: '',
263 groupIdAttribute: ''
264 }
265 };
266 },
267 computed: {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700268 ...mapGetters('ldap', [
269 'isServiceEnabled',
270 'isActiveDirectoryEnabled',
271 'ldap',
272 'activeDirectory'
273 ]),
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700274 sslCertificates() {
275 return this.$store.getters['sslCertificates/allCertificates'];
276 },
277 caCertificateExpiration() {
278 const caCertificate = find(this.sslCertificates, {
279 type: 'TrustStore Certificate'
280 });
281 if (caCertificate === undefined) return null;
282 return caCertificate.validUntil;
283 },
284 ldapCertificateExpiration() {
285 const ldapCertificate = find(this.sslCertificates, {
286 type: 'LDAP Certificate'
287 });
288 if (ldapCertificate === undefined) return null;
289 return ldapCertificate.validUntil;
290 },
291 ldapProtocol() {
292 return this.form.secureLdapEnabled ? 'ldaps://' : 'ldap://';
293 }
294 },
295 watch: {
296 isServiceEnabled: function(value) {
297 this.form.ldapAuthenticationEnabled = value;
298 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700299 isActiveDirectoryEnabled: function(value) {
300 this.form.activeDirectoryEnabled = value;
301 this.setFormValues();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700302 }
303 },
304 validations: {
305 form: {
306 ldapAuthenticationEnabled: {},
307 secureLdapEnabled: {},
308 activeDirectoryEnabled: {
309 required: requiredIf(function() {
310 return this.form.ldapAuthenticationEnabled;
311 })
312 },
313 serverUri: {
314 required: requiredIf(function() {
315 return this.form.ldapAuthenticationEnabled;
316 })
317 },
318 bindDn: {
319 required: requiredIf(function() {
320 return this.form.ldapAuthenticationEnabled;
321 })
322 },
323 bindPassword: {
324 required: requiredIf(function() {
325 return this.form.ldapAuthenticationEnabled;
326 })
327 },
328 baseDn: {
329 required: requiredIf(function() {
330 return this.form.ldapAuthenticationEnabled;
331 })
332 },
333 userIdAttribute: {},
334 groupIdAttribute: {}
335 }
336 },
337 created() {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700338 this.startLoader();
339 this.$store
340 .dispatch('ldap/getAccountSettings')
341 .finally(() => this.endLoader());
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700342 this.$store.dispatch('sslCertificates/getCertificates');
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700343 this.setFormValues();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700344 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700345 beforeRouteLeave(to, from, next) {
346 this.hideLoader();
347 next();
348 },
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700349 methods: {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700350 setFormValues(serviceType) {
351 if (!serviceType) {
352 serviceType = this.isActiveDirectoryEnabled
353 ? this.activeDirectory
354 : this.ldap;
355 }
356 const {
357 serviceAddress = '',
358 bindDn = '',
359 baseDn = '',
360 userAttribute = '',
361 groupsAttribute = ''
362 } = serviceType;
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700363 const secureLdap =
364 serviceAddress && serviceAddress.includes('ldaps://') ? true : false;
365 const serverUri = serviceAddress
366 ? serviceAddress.replace(/ldaps?:\/\//, '')
367 : '';
368 this.form.secureLdapEnabled = secureLdap;
369 this.form.serverUri = serverUri;
370 this.form.bindDn = bindDn;
371 this.form.bindPassword = '';
372 this.form.baseDn = baseDn;
373 this.form.userIdAttribute = userAttribute;
374 this.form.groupIdAttribute = groupsAttribute;
375 },
376 handleSubmit() {
377 this.$v.$touch();
378 if (this.$v.$invalid) return;
379 const data = {
380 serviceEnabled: this.form.ldapAuthenticationEnabled,
381 activeDirectoryEnabled: this.form.activeDirectoryEnabled,
382 serviceAddress: `${this.ldapProtocol}${this.form.serverUri}`,
383 bindDn: this.form.bindDn,
384 bindPassword: this.form.bindPassword,
385 baseDn: this.form.baseDn,
386 userIdAttribute: this.form.userIdAttribute,
387 groupIdAttribute: this.form.groupIdAttribute
388 };
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700389 this.startLoader();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700390 this.$store
391 .dispatch('ldap/saveAccountSettings', data)
392 .then(success => {
393 this.successToast(success);
394 this.$v.form.$reset();
395 })
396 .catch(({ message }) => this.errorToast(message))
397 .finally(() => {
398 this.form.bindPassword = '';
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700399 this.endLoader();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700400 });
401 },
402 onChangeServiceType(isActiveDirectoryEnabled) {
403 this.$v.form.activeDirectoryEnabled.$touch();
404 const serviceType = isActiveDirectoryEnabled
405 ? this.activeDirectory
406 : this.ldap;
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700407 // Set form values according to user selected
408 // service type
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700409 this.setFormValues(serviceType);
410 },
411 onChangeldapAuthenticationEnabled(isServiceEnabled) {
412 this.$v.form.ldapAuthenticationEnabled.$touch();
413 if (!isServiceEnabled) {
414 // Request will fail if sent with empty values.
415 // The frontend only checks for required fields
416 // when the service is enabled. This is to prevent
417 // an error if a user clears any properties then
418 // disables the service.
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700419 this.setFormValues();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700420 }
421 }
422 }
423};
424</script>