blob: 1bb5adba59716f533294352761dc192a823b1b0b [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">
Mateusz Gapski471f2e02020-07-27 14:43:26 +02006 <b-form-group :disabled="loading">
7 <b-row>
8 <b-col>
9 <b-form-group
10 class="mb-3"
11 :label="$t('pageLdap.form.ldapAuthentication')"
12 label-for="enable-ldap-auth"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -070013 >
Mateusz Gapski471f2e02020-07-27 14:43:26 +020014 <b-form-checkbox
15 id="enable-ldap-auth"
16 v-model="form.ldapAuthenticationEnabled"
17 data-test-id="ldap-checkbox-ldapAuthenticationEnabled"
18 @change="onChangeldapAuthenticationEnabled"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -070019 >
Mateusz Gapski471f2e02020-07-27 14:43:26 +020020 {{ $t('global.action.enable') }}
21 </b-form-checkbox>
22 </b-form-group>
23 </b-col>
24 </b-row>
25 <div class="form-background p-3">
26 <b-form-group
27 class="m-0"
28 :label="$t('pageLdap.ariaLabel.ldapSettings')"
29 label-class="sr-only"
30 :disabled="!form.ldapAuthenticationEnabled"
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -070031 >
Mateusz Gapski471f2e02020-07-27 14:43:26 +020032 <b-row>
33 <b-col md="3" lg="4" xl="3">
34 <b-form-group
35 class="mb-4"
36 :label="$t('pageLdap.form.secureLdapUsingSsl')"
37 >
38 <b-form-text id="enable-secure-help-block">
39 {{ $t('pageLdap.form.secureLdapHelper') }}
40 </b-form-text>
41 <b-form-checkbox
42 id="enable-secure-ldap"
43 v-model="form.secureLdapEnabled"
44 aria-describedby="enable-secure-help-block"
45 data-test-id="ldap-checkbox-secureLdapEnabled"
46 :disabled="
47 !caCertificateExpiration || !ldapCertificateExpiration
48 "
49 @change="$v.form.secureLdapEnabled.$touch()"
50 >
51 {{ $t('global.action.enable') }}
52 </b-form-checkbox>
53 </b-form-group>
54 <dl>
55 <dt>{{ $t('pageLdap.form.caCertificateValidUntil') }}</dt>
56 <dd v-if="caCertificateExpiration">
57 {{ caCertificateExpiration | formatDate }}
58 </dd>
59 <dd v-else>--</dd>
60 <dt>{{ $t('pageLdap.form.ldapCertificateValidUntil') }}</dt>
61 <dd v-if="ldapCertificateExpiration">
62 {{ ldapCertificateExpiration | formatDate }}
63 </dd>
64 <dd v-else>--</dd>
65 </dl>
66 <b-link
67 class="d-inline-block mb-4 m-md-0"
68 to="/access-control/ssl-certificates"
69 >
70 {{ $t('pageLdap.form.manageSslCertificates') }}
71 </b-link>
72 </b-col>
73 <b-col md="9" lg="8" xl="9">
74 <b-row>
75 <b-col>
76 <b-form-group :label="$t('pageLdap.form.serviceType')">
77 <b-form-radio
78 v-model="form.activeDirectoryEnabled"
79 data-test-id="ldap-radio-activeDirectoryEnabled"
80 :value="false"
81 @change="onChangeServiceType"
82 >
83 OpenLDAP
84 </b-form-radio>
85 <b-form-radio
86 v-model="form.activeDirectoryEnabled"
87 data-test-id="ldap-radio-activeDirectoryEnabled"
88 :value="true"
89 @change="onChangeServiceType"
90 >
91 Active Directory
92 </b-form-radio>
93 </b-form-group>
94 </b-col>
95 </b-row>
96 <b-row>
97 <b-col sm="6" xl="4">
98 <b-form-group label-for="server-uri">
99 <template v-slot:label>
100 {{ $t('pageLdap.form.serverUri') }}
101 <info-tooltip
102 :title="$t('pageLdap.form.serverUriTooltip')"
103 />
104 </template>
105 <b-input-group :prepend="ldapProtocol">
106 <b-form-input
107 id="server-uri"
108 v-model="form.serverUri"
109 data-test-id="ldap-input-serverUri"
110 :state="getValidationState($v.form.serverUri)"
111 @change="$v.form.serverUri.$touch()"
112 />
113 <b-form-invalid-feedback role="alert">
114 {{ $t('global.form.fieldRequired') }}
115 </b-form-invalid-feedback>
116 </b-input-group>
117 </b-form-group>
118 </b-col>
119 <b-col sm="6" xl="4">
120 <b-form-group
121 :label="$t('pageLdap.form.bindDn')"
122 label-for="bind-dn"
123 >
124 <b-form-input
125 id="bind-dn"
126 v-model="form.bindDn"
127 data-test-id="ldap-input-bindDn"
128 :state="getValidationState($v.form.bindDn)"
129 @change="$v.form.bindDn.$touch()"
130 />
131 <b-form-invalid-feedback role="alert">
132 {{ $t('global.form.fieldRequired') }}
133 </b-form-invalid-feedback>
134 </b-form-group>
135 </b-col>
136 <b-col sm="6" xl="4">
137 <b-form-group
138 :label="$t('pageLdap.form.bindPassword')"
139 label-for="bind-password"
140 >
141 <input-password-toggle
142 data-test-id="ldap-input-togglePassword"
143 >
144 <b-form-input
145 id="bind-password"
146 v-model="form.bindPassword"
147 type="password"
148 :state="getValidationState($v.form.bindPassword)"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -0500149 class="form-control-with-button"
Mateusz Gapski471f2e02020-07-27 14:43:26 +0200150 @change="$v.form.bindPassword.$touch()"
151 />
152 <b-form-invalid-feedback role="alert">
153 {{ $t('global.form.fieldRequired') }}
154 </b-form-invalid-feedback>
155 </input-password-toggle>
156 </b-form-group>
157 </b-col>
158 <b-col sm="6" xl="4">
159 <b-form-group
160 :label="$t('pageLdap.form.baseDn')"
161 label-for="base-dn"
162 >
163 <b-form-input
164 id="base-dn"
165 v-model="form.baseDn"
166 data-test-id="ldap-input-baseDn"
167 :state="getValidationState($v.form.baseDn)"
168 @change="$v.form.baseDn.$touch()"
169 />
170 <b-form-invalid-feedback role="alert">
171 {{ $t('global.form.fieldRequired') }}
172 </b-form-invalid-feedback>
173 </b-form-group>
174 </b-col>
175 <b-col sm="6" xl="4">
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500176 <b-form-group label-for="user-id-attribute">
177 <template v-slot:label>
178 {{ $t('pageLdap.form.userIdAttribute') }} -
179 <span class="form-text d-inline">
180 {{ $t('global.form.optional') }}
181 </span>
182 </template>
Mateusz Gapski471f2e02020-07-27 14:43:26 +0200183 <b-form-input
184 id="user-id-attribute"
185 v-model="form.userIdAttribute"
186 data-test-id="ldap-input-userIdAttribute"
187 @change="$v.form.userIdAttribute.$touch()"
188 />
189 </b-form-group>
190 </b-col>
191 <b-col sm="6" xl="4">
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500192 <b-form-group label-for="group-id-attribute">
193 <template v-slot:label>
194 {{ $t('pageLdap.form.groupIdAttribute') }} -
195 <span class="form-text d-inline">
196 {{ $t('global.form.optional') }}
197 </span>
198 </template>
Mateusz Gapski471f2e02020-07-27 14:43:26 +0200199 <b-form-input
200 id="group-id-attribute"
201 v-model="form.groupIdAttribute"
202 data-test-id="ldap-input-groupIdAttribute"
203 @change="$v.form.groupIdAttribute.$touch()"
204 />
205 </b-form-group>
206 </b-col>
207 </b-row>
208 </b-col>
209 </b-row>
210 </b-form-group>
211 </div>
212 <b-row class="mt-4 mb-5">
213 <b-col>
214 <b-btn
215 variant="primary"
216 type="submit"
217 data-test-id="ldap-button-saveSettings"
218 :disabled="!$v.form.$anyDirty"
219 >
220 {{ $t('global.action.saveSettings') }}
221 </b-btn>
222 </b-col>
223 </b-row>
224 </b-form-group>
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700225 </b-form>
226 </page-section>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700227
228 <!-- Role groups -->
229 <page-section :section-title="$t('pageLdap.roleGroups')">
230 <table-role-groups />
231 </page-section>
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700232 </b-container>
233</template>
234
235<script>
236import { mapGetters } from 'vuex';
237import { find } from 'lodash';
238import { requiredIf } from 'vuelidate/lib/validators';
239
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700240import BVToastMixin from '@/components/Mixins/BVToastMixin';
241import VuelidateMixin from '@/components/Mixins/VuelidateMixin';
242import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Derick Montagued853fba2020-07-16 11:24:10 -0500243import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700244import PageTitle from '@/components/Global/PageTitle';
245import PageSection from '@/components/Global/PageSection';
246import InfoTooltip from '@/components/Global/InfoTooltip';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700247import TableRoleGroups from './TableRoleGroups';
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700248
249export default {
250 name: 'Ldap',
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700251 components: {
252 InfoTooltip,
253 InputPasswordToggle,
254 PageTitle,
255 PageSection,
256 TableRoleGroups
257 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700258 mixins: [BVToastMixin, VuelidateMixin, LoadingBarMixin],
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700259 data() {
260 return {
261 form: {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700262 ldapAuthenticationEnabled: this.$store.getters['ldap/isServiceEnabled'],
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700263 secureLdapEnabled: false,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700264 activeDirectoryEnabled: this.$store.getters[
265 'ldap/isActiveDirectoryEnabled'
266 ],
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700267 serverUri: '',
268 bindDn: '',
269 bindPassword: '',
270 baseDn: '',
271 userIdAttribute: '',
272 groupIdAttribute: ''
273 }
274 };
275 },
276 computed: {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700277 ...mapGetters('ldap', [
278 'isServiceEnabled',
279 'isActiveDirectoryEnabled',
280 'ldap',
281 'activeDirectory'
282 ]),
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700283 sslCertificates() {
284 return this.$store.getters['sslCertificates/allCertificates'];
285 },
286 caCertificateExpiration() {
287 const caCertificate = find(this.sslCertificates, {
288 type: 'TrustStore Certificate'
289 });
290 if (caCertificate === undefined) return null;
291 return caCertificate.validUntil;
292 },
293 ldapCertificateExpiration() {
294 const ldapCertificate = find(this.sslCertificates, {
295 type: 'LDAP Certificate'
296 });
297 if (ldapCertificate === undefined) return null;
298 return ldapCertificate.validUntil;
299 },
300 ldapProtocol() {
301 return this.form.secureLdapEnabled ? 'ldaps://' : 'ldap://';
302 }
303 },
304 watch: {
305 isServiceEnabled: function(value) {
306 this.form.ldapAuthenticationEnabled = value;
307 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700308 isActiveDirectoryEnabled: function(value) {
309 this.form.activeDirectoryEnabled = value;
310 this.setFormValues();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700311 }
312 },
313 validations: {
314 form: {
315 ldapAuthenticationEnabled: {},
316 secureLdapEnabled: {},
317 activeDirectoryEnabled: {
318 required: requiredIf(function() {
319 return this.form.ldapAuthenticationEnabled;
320 })
321 },
322 serverUri: {
323 required: requiredIf(function() {
324 return this.form.ldapAuthenticationEnabled;
325 })
326 },
327 bindDn: {
328 required: requiredIf(function() {
329 return this.form.ldapAuthenticationEnabled;
330 })
331 },
332 bindPassword: {
333 required: requiredIf(function() {
334 return this.form.ldapAuthenticationEnabled;
335 })
336 },
337 baseDn: {
338 required: requiredIf(function() {
339 return this.form.ldapAuthenticationEnabled;
340 })
341 },
342 userIdAttribute: {},
343 groupIdAttribute: {}
344 }
345 },
346 created() {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700347 this.startLoader();
348 this.$store
349 .dispatch('ldap/getAccountSettings')
350 .finally(() => this.endLoader());
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700351 this.$store.dispatch('sslCertificates/getCertificates');
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700352 this.setFormValues();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700353 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700354 beforeRouteLeave(to, from, next) {
355 this.hideLoader();
356 next();
357 },
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700358 methods: {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700359 setFormValues(serviceType) {
360 if (!serviceType) {
361 serviceType = this.isActiveDirectoryEnabled
362 ? this.activeDirectory
363 : this.ldap;
364 }
365 const {
366 serviceAddress = '',
367 bindDn = '',
368 baseDn = '',
369 userAttribute = '',
370 groupsAttribute = ''
371 } = serviceType;
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700372 const secureLdap =
373 serviceAddress && serviceAddress.includes('ldaps://') ? true : false;
374 const serverUri = serviceAddress
375 ? serviceAddress.replace(/ldaps?:\/\//, '')
376 : '';
377 this.form.secureLdapEnabled = secureLdap;
378 this.form.serverUri = serverUri;
379 this.form.bindDn = bindDn;
380 this.form.bindPassword = '';
381 this.form.baseDn = baseDn;
382 this.form.userIdAttribute = userAttribute;
383 this.form.groupIdAttribute = groupsAttribute;
384 },
385 handleSubmit() {
386 this.$v.$touch();
387 if (this.$v.$invalid) return;
388 const data = {
389 serviceEnabled: this.form.ldapAuthenticationEnabled,
390 activeDirectoryEnabled: this.form.activeDirectoryEnabled,
391 serviceAddress: `${this.ldapProtocol}${this.form.serverUri}`,
392 bindDn: this.form.bindDn,
393 bindPassword: this.form.bindPassword,
394 baseDn: this.form.baseDn,
395 userIdAttribute: this.form.userIdAttribute,
396 groupIdAttribute: this.form.groupIdAttribute
397 };
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700398 this.startLoader();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700399 this.$store
400 .dispatch('ldap/saveAccountSettings', data)
401 .then(success => {
402 this.successToast(success);
403 this.$v.form.$reset();
404 })
405 .catch(({ message }) => this.errorToast(message))
406 .finally(() => {
407 this.form.bindPassword = '';
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700408 this.endLoader();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700409 });
410 },
411 onChangeServiceType(isActiveDirectoryEnabled) {
412 this.$v.form.activeDirectoryEnabled.$touch();
413 const serviceType = isActiveDirectoryEnabled
414 ? this.activeDirectory
415 : this.ldap;
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700416 // Set form values according to user selected
417 // service type
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700418 this.setFormValues(serviceType);
419 },
420 onChangeldapAuthenticationEnabled(isServiceEnabled) {
421 this.$v.form.ldapAuthenticationEnabled.$touch();
422 if (!isServiceEnabled) {
423 // Request will fail if sent with empty values.
424 // The frontend only checks for required fields
425 // when the service is enabled. This is to prevent
426 // an error if a user clears any properties then
427 // disables the service.
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700428 this.setFormValues();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700429 }
430 }
431 }
432};
433</script>