blob: 618434b67179e98492d64726ea90310350554655 [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">
176 <b-form-group
177 :label="$t('pageLdap.form.userIdAttribute')"
178 label-for="user-id-attribute"
179 >
180 <b-form-input
181 id="user-id-attribute"
182 v-model="form.userIdAttribute"
183 data-test-id="ldap-input-userIdAttribute"
184 @change="$v.form.userIdAttribute.$touch()"
185 />
186 </b-form-group>
187 </b-col>
188 <b-col sm="6" xl="4">
189 <b-form-group
190 :label="$t('pageLdap.form.groupIdAttribute')"
191 label-for="group-id-attribute"
192 >
193 <b-form-input
194 id="group-id-attribute"
195 v-model="form.groupIdAttribute"
196 data-test-id="ldap-input-groupIdAttribute"
197 @change="$v.form.groupIdAttribute.$touch()"
198 />
199 </b-form-group>
200 </b-col>
201 </b-row>
202 </b-col>
203 </b-row>
204 </b-form-group>
205 </div>
206 <b-row class="mt-4 mb-5">
207 <b-col>
208 <b-btn
209 variant="primary"
210 type="submit"
211 data-test-id="ldap-button-saveSettings"
212 :disabled="!$v.form.$anyDirty"
213 >
214 {{ $t('global.action.saveSettings') }}
215 </b-btn>
216 </b-col>
217 </b-row>
218 </b-form-group>
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700219 </b-form>
220 </page-section>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700221
222 <!-- Role groups -->
223 <page-section :section-title="$t('pageLdap.roleGroups')">
224 <table-role-groups />
225 </page-section>
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700226 </b-container>
227</template>
228
229<script>
230import { mapGetters } from 'vuex';
231import { find } from 'lodash';
232import { requiredIf } from 'vuelidate/lib/validators';
233
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700234import BVToastMixin from '@/components/Mixins/BVToastMixin';
235import VuelidateMixin from '@/components/Mixins/VuelidateMixin';
236import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Derick Montagued853fba2020-07-16 11:24:10 -0500237import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700238import PageTitle from '@/components/Global/PageTitle';
239import PageSection from '@/components/Global/PageSection';
240import InfoTooltip from '@/components/Global/InfoTooltip';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700241import TableRoleGroups from './TableRoleGroups';
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700242
243export default {
244 name: 'Ldap',
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700245 components: {
246 InfoTooltip,
247 InputPasswordToggle,
248 PageTitle,
249 PageSection,
250 TableRoleGroups
251 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700252 mixins: [BVToastMixin, VuelidateMixin, LoadingBarMixin],
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700253 data() {
254 return {
255 form: {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700256 ldapAuthenticationEnabled: this.$store.getters['ldap/isServiceEnabled'],
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700257 secureLdapEnabled: false,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700258 activeDirectoryEnabled: this.$store.getters[
259 'ldap/isActiveDirectoryEnabled'
260 ],
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700261 serverUri: '',
262 bindDn: '',
263 bindPassword: '',
264 baseDn: '',
265 userIdAttribute: '',
266 groupIdAttribute: ''
267 }
268 };
269 },
270 computed: {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700271 ...mapGetters('ldap', [
272 'isServiceEnabled',
273 'isActiveDirectoryEnabled',
274 'ldap',
275 'activeDirectory'
276 ]),
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700277 sslCertificates() {
278 return this.$store.getters['sslCertificates/allCertificates'];
279 },
280 caCertificateExpiration() {
281 const caCertificate = find(this.sslCertificates, {
282 type: 'TrustStore Certificate'
283 });
284 if (caCertificate === undefined) return null;
285 return caCertificate.validUntil;
286 },
287 ldapCertificateExpiration() {
288 const ldapCertificate = find(this.sslCertificates, {
289 type: 'LDAP Certificate'
290 });
291 if (ldapCertificate === undefined) return null;
292 return ldapCertificate.validUntil;
293 },
294 ldapProtocol() {
295 return this.form.secureLdapEnabled ? 'ldaps://' : 'ldap://';
296 }
297 },
298 watch: {
299 isServiceEnabled: function(value) {
300 this.form.ldapAuthenticationEnabled = value;
301 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700302 isActiveDirectoryEnabled: function(value) {
303 this.form.activeDirectoryEnabled = value;
304 this.setFormValues();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700305 }
306 },
307 validations: {
308 form: {
309 ldapAuthenticationEnabled: {},
310 secureLdapEnabled: {},
311 activeDirectoryEnabled: {
312 required: requiredIf(function() {
313 return this.form.ldapAuthenticationEnabled;
314 })
315 },
316 serverUri: {
317 required: requiredIf(function() {
318 return this.form.ldapAuthenticationEnabled;
319 })
320 },
321 bindDn: {
322 required: requiredIf(function() {
323 return this.form.ldapAuthenticationEnabled;
324 })
325 },
326 bindPassword: {
327 required: requiredIf(function() {
328 return this.form.ldapAuthenticationEnabled;
329 })
330 },
331 baseDn: {
332 required: requiredIf(function() {
333 return this.form.ldapAuthenticationEnabled;
334 })
335 },
336 userIdAttribute: {},
337 groupIdAttribute: {}
338 }
339 },
340 created() {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700341 this.startLoader();
342 this.$store
343 .dispatch('ldap/getAccountSettings')
344 .finally(() => this.endLoader());
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700345 this.$store.dispatch('sslCertificates/getCertificates');
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700346 this.setFormValues();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700347 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700348 beforeRouteLeave(to, from, next) {
349 this.hideLoader();
350 next();
351 },
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700352 methods: {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700353 setFormValues(serviceType) {
354 if (!serviceType) {
355 serviceType = this.isActiveDirectoryEnabled
356 ? this.activeDirectory
357 : this.ldap;
358 }
359 const {
360 serviceAddress = '',
361 bindDn = '',
362 baseDn = '',
363 userAttribute = '',
364 groupsAttribute = ''
365 } = serviceType;
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700366 const secureLdap =
367 serviceAddress && serviceAddress.includes('ldaps://') ? true : false;
368 const serverUri = serviceAddress
369 ? serviceAddress.replace(/ldaps?:\/\//, '')
370 : '';
371 this.form.secureLdapEnabled = secureLdap;
372 this.form.serverUri = serverUri;
373 this.form.bindDn = bindDn;
374 this.form.bindPassword = '';
375 this.form.baseDn = baseDn;
376 this.form.userIdAttribute = userAttribute;
377 this.form.groupIdAttribute = groupsAttribute;
378 },
379 handleSubmit() {
380 this.$v.$touch();
381 if (this.$v.$invalid) return;
382 const data = {
383 serviceEnabled: this.form.ldapAuthenticationEnabled,
384 activeDirectoryEnabled: this.form.activeDirectoryEnabled,
385 serviceAddress: `${this.ldapProtocol}${this.form.serverUri}`,
386 bindDn: this.form.bindDn,
387 bindPassword: this.form.bindPassword,
388 baseDn: this.form.baseDn,
389 userIdAttribute: this.form.userIdAttribute,
390 groupIdAttribute: this.form.groupIdAttribute
391 };
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700392 this.startLoader();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700393 this.$store
394 .dispatch('ldap/saveAccountSettings', data)
395 .then(success => {
396 this.successToast(success);
397 this.$v.form.$reset();
398 })
399 .catch(({ message }) => this.errorToast(message))
400 .finally(() => {
401 this.form.bindPassword = '';
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700402 this.endLoader();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700403 });
404 },
405 onChangeServiceType(isActiveDirectoryEnabled) {
406 this.$v.form.activeDirectoryEnabled.$touch();
407 const serviceType = isActiveDirectoryEnabled
408 ? this.activeDirectory
409 : this.ldap;
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700410 // Set form values according to user selected
411 // service type
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700412 this.setFormValues(serviceType);
413 },
414 onChangeldapAuthenticationEnabled(isServiceEnabled) {
415 this.$v.form.ldapAuthenticationEnabled.$touch();
416 if (!isServiceEnabled) {
417 // Request will fail if sent with empty values.
418 // The frontend only checks for required fields
419 // when the service is enabled. This is to prevent
420 // an error if a user clears any properties then
421 // disables the service.
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700422 this.setFormValues();
Yoshie Muranakac4e38ab2020-04-09 12:41:27 -0700423 }
424 }
425 }
426};
427</script>