1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package Mautic |
4
|
|
|
* @copyright 2019 Monogramm. All rights reserved |
5
|
|
|
* @author Monogramm |
6
|
|
|
* @link https://www.monogramm.io |
7
|
|
|
* @license GNU/AGPLv3 http://www.gnu.org/licenses/agpl.html |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace MauticPlugin\MauticLdapAuthBundle\Form\Type; |
11
|
|
|
|
12
|
|
|
use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; |
13
|
|
|
use Mautic\CoreBundle\Helper\CoreParametersHelper; |
14
|
|
|
use Symfony\Component\Form\AbstractType; |
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\NumberType; |
16
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
17
|
|
|
use Symfony\Component\Form\Extension\Core\Type\UrlType; |
18
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
19
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class ConfigType. |
23
|
|
|
*/ |
24
|
|
|
class ConfigType extends AbstractType |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var CoreParametersHelper |
28
|
|
|
*/ |
29
|
|
|
protected $parameters; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var TranslatorInterface |
33
|
|
|
*/ |
34
|
|
|
protected $translator; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* ConfigType constructor. |
38
|
|
|
* |
39
|
|
|
* @param CoreParametersHelper $parametersHelper |
40
|
|
|
* @param TranslatorInterface $translator |
41
|
|
|
*/ |
42
|
|
|
public function __construct(CoreParametersHelper $parametersHelper, TranslatorInterface $translator) |
43
|
|
|
{ |
44
|
|
|
$this->parameters = $parametersHelper; |
45
|
|
|
$this->translator = $translator; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param FormBuilderInterface $builder |
50
|
|
|
* @param array $options |
51
|
|
|
*/ |
52
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
53
|
|
|
{ |
54
|
|
|
|
55
|
|
|
$builder->add( |
56
|
|
|
'ldap_auth_host', |
57
|
|
|
UrlType::class, |
58
|
|
|
[ |
59
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.host', |
60
|
|
|
'label_attr' => ['class' => 'control-label'], |
61
|
|
|
'attr' => [ |
62
|
|
|
'class' => 'form-control', |
63
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.host.tooltip', |
64
|
|
|
], |
65
|
|
|
'default_protocol' => 'ldap' |
66
|
|
|
] |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$builder->add( |
70
|
|
|
'ldap_auth_port', |
71
|
|
|
NumberType::class, |
72
|
|
|
[ |
73
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.port', |
74
|
|
|
'label_attr' => ['class' => 'control-label'], |
75
|
|
|
'attr' => [ |
76
|
|
|
'class' => 'form-control', |
77
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.port.tooltip', |
78
|
|
|
], |
79
|
|
|
'empty_data' => 389, |
80
|
|
|
] |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$builder->add( |
84
|
|
|
'ldap_auth_ssl', |
85
|
|
|
YesNoButtonGroupType::class, |
86
|
|
|
[ |
87
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.ssl', |
88
|
|
|
'label_attr' => ['class' => 'control-label'], |
89
|
|
|
'attr' => [ |
90
|
|
|
'class' => 'form-control', |
91
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.ssl.tooltip', |
92
|
|
|
], |
93
|
|
|
'data' => isset($options['data']['ldap_auth_ssl']) ? |
94
|
|
|
(bool) $options['data']['ldap_auth_ssl'] |
95
|
|
|
: ( |
96
|
|
|
isset($options['data']['ldap_auth_host']) ? |
97
|
|
|
substr($options['data']['ldap_auth_host'], 0, 8) === 'ldaps://' |
98
|
|
|
: false |
99
|
|
|
), |
100
|
|
|
'empty_data' => false, |
101
|
|
|
] |
102
|
|
|
); |
103
|
|
|
$builder->add( |
104
|
|
|
'ldap_auth_starttls', |
105
|
|
|
YesNoButtonGroupType::class, |
106
|
|
|
[ |
107
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.starttls', |
108
|
|
|
'label_attr' => ['class' => 'control-label'], |
109
|
|
|
'attr' => [ |
110
|
|
|
'class' => 'form-control', |
111
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.starttls.tooltip', |
112
|
|
|
], |
113
|
|
|
'data' => isset($options['data']['ldap_auth_starttls']) ? |
114
|
|
|
(bool) $options['data']['ldap_auth_starttls'] |
115
|
|
|
: false, |
116
|
|
|
'empty_data' => false, |
117
|
|
|
] |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
$builder->add( |
121
|
|
|
'ldap_auth_version', |
122
|
|
|
NumberType::class, |
123
|
|
|
[ |
124
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.version', |
125
|
|
|
'label_attr' => ['class' => 'control-label'], |
126
|
|
|
'attr' => [ |
127
|
|
|
'class' => 'form-control', |
128
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.version.tooltip', |
129
|
|
|
], |
130
|
|
|
'empty_data' => 3, |
131
|
|
|
'required' => false, |
132
|
|
|
] |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
// TODO Coming feature: test LDAP connection |
136
|
|
|
/* |
137
|
|
|
$builder->add( |
138
|
|
|
'ldap_auth_test_connection_button', |
139
|
|
|
'standalone_button', |
140
|
|
|
[ |
141
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.test_connection', |
142
|
|
|
'required' => false, |
143
|
|
|
'attr' => [ |
144
|
|
|
'class' => 'btn btn-success', |
145
|
|
|
'onclick' => 'Mautic.testLdapServerConnection()', |
146
|
|
|
], |
147
|
|
|
] |
148
|
|
|
); |
149
|
|
|
*/ |
150
|
|
|
|
151
|
|
|
// TODO Coming feature: LDAP bind account and Group lookup |
152
|
|
|
/* |
153
|
|
|
$builder->add( |
154
|
|
|
'ldap_auth_mode', |
155
|
|
|
ChoiceType::class, |
156
|
|
|
[ |
157
|
|
|
'choices' => $this->getAuthenticationChoices(), |
158
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.ldap_authentication', |
159
|
|
|
'required' => false, |
160
|
|
|
'attr' => [ |
161
|
|
|
'class' => 'form-control', |
162
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.ldap_authentication.tooltip', |
163
|
|
|
'onchange' => 'Mautic.disableTestAuthenticationButton()', |
164
|
|
|
], |
165
|
|
|
'empty_value' => false, |
166
|
|
|
] |
167
|
|
|
); |
168
|
|
|
|
169
|
|
|
$builder->add( |
170
|
|
|
'ldap_auth_bind_dn', |
171
|
|
|
TextType::class, |
172
|
|
|
[ |
173
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.bind_dn', |
174
|
|
|
'label_attr' => ['class' => 'control-label'], |
175
|
|
|
'attr' => [ |
176
|
|
|
'class' => 'form-control', |
177
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.bind_dn.tooltip', |
178
|
|
|
], |
179
|
|
|
'empty_data' => null, |
180
|
|
|
] |
181
|
|
|
); |
182
|
|
|
|
183
|
|
|
$builder->add( |
184
|
|
|
'ldap_auth_bind_passwd', |
185
|
|
|
TextType::class, |
186
|
|
|
[ |
187
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.bind_passwd', |
188
|
|
|
'label_attr' => ['class' => 'control-label'], |
189
|
|
|
'attr' => [ |
190
|
|
|
'class' => 'form-control', |
191
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.bind_passwd.tooltip', |
192
|
|
|
], |
193
|
|
|
'empty_data' => null, |
194
|
|
|
] |
195
|
|
|
); |
196
|
|
|
|
197
|
|
|
$builder->add( |
198
|
|
|
'ldap_auth_test_authenticate_button', |
199
|
|
|
'standalone_button', |
200
|
|
|
[ |
201
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.test_authentication', |
202
|
|
|
'required' => false, |
203
|
|
|
'attr' => [ |
204
|
|
|
'class' => 'btn btn-info', |
205
|
|
|
'onclick' => 'Mautic.testLdapAuthentication()', |
206
|
|
|
], |
207
|
|
|
] |
208
|
|
|
); |
209
|
|
|
*/ |
210
|
|
|
|
211
|
|
|
$builder->add( |
212
|
|
|
'ldap_auth_base_dn', |
213
|
|
|
TextType::class, |
214
|
|
|
[ |
215
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.base_dn', |
216
|
|
|
'label_attr' => ['class' => 'control-label'], |
217
|
|
|
'attr' => [ |
218
|
|
|
'class' => 'form-control', |
219
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.base_dn.tooltip', |
220
|
|
|
], |
221
|
|
|
'empty_data' => null, |
222
|
|
|
] |
223
|
|
|
); |
224
|
|
|
$builder->add( |
225
|
|
|
'ldap_auth_user_query', |
226
|
|
|
TextType::class, |
227
|
|
|
[ |
228
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.user_query', |
229
|
|
|
'label_attr' => ['class' => 'control-label'], |
230
|
|
|
'attr' => [ |
231
|
|
|
'class' => 'form-control', |
232
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.user_query.tooltip', |
233
|
|
|
], |
234
|
|
|
'empty_data' => '(objectclass=inetOrgPerson)', |
235
|
|
|
] |
236
|
|
|
); |
237
|
|
|
|
238
|
|
|
$builder->add( |
239
|
|
|
'ldap_auth_isactivedirectory', |
240
|
|
|
YesNoButtonGroupType::class, |
241
|
|
|
[ |
242
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.isactivedirectory', |
243
|
|
|
'label_attr' => ['class' => 'control-label'], |
244
|
|
|
'attr' => [ |
245
|
|
|
'class' => 'form-control', |
246
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.isactivedirectory.tooltip', |
247
|
|
|
], |
248
|
|
|
'data' => isset($options['data']['ldap_auth_isactivedirectory']) ? |
249
|
|
|
(bool) $options['data']['ldap_auth_isactivedirectory'] |
250
|
|
|
: false, |
251
|
|
|
'empty_data' => false, |
252
|
|
|
'required' => false, |
253
|
|
|
] |
254
|
|
|
); |
255
|
|
|
$builder->add( |
256
|
|
|
'ldap_auth_activedirectory_domain', |
257
|
|
|
TextType::class, |
258
|
|
|
[ |
259
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.activedirectory_domain', |
260
|
|
|
'label_attr' => ['class' => 'control-label'], |
261
|
|
|
'attr' => [ |
262
|
|
|
'class' => 'form-control', |
263
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.activedirectory_domain.tooltip', |
264
|
|
|
], |
265
|
|
|
'empty_data' => null, |
266
|
|
|
'required' => false, |
267
|
|
|
] |
268
|
|
|
); |
269
|
|
|
|
270
|
|
|
$builder->add( |
271
|
|
|
'ldap_auth_username_attribute', |
272
|
|
|
TextType::class, |
273
|
|
|
[ |
274
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.username_attribute', |
275
|
|
|
'label_attr' => ['class' => 'control-label'], |
276
|
|
|
'attr' => [ |
277
|
|
|
'class' => 'form-control', |
278
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.username_attribute.tooltip', |
279
|
|
|
], |
280
|
|
|
'empty_data' => 'uid', |
281
|
|
|
] |
282
|
|
|
); |
283
|
|
|
|
284
|
|
|
$builder->add( |
285
|
|
|
'ldap_auth_email_attribute', |
286
|
|
|
TextType::class, |
287
|
|
|
[ |
288
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.email_attribute', |
289
|
|
|
'label_attr' => ['class' => 'control-label'], |
290
|
|
|
'attr' => [ |
291
|
|
|
'class' => 'form-control', |
292
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.email_attribute.tooltip', |
293
|
|
|
], |
294
|
|
|
'empty_data' => 'mail', |
295
|
|
|
] |
296
|
|
|
); |
297
|
|
|
|
298
|
|
|
$builder->add( |
299
|
|
|
'ldap_auth_firstname_attribute', |
300
|
|
|
TextType::class, |
301
|
|
|
[ |
302
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.firstname_attribute', |
303
|
|
|
'label_attr' => ['class' => 'control-label'], |
304
|
|
|
'attr' => [ |
305
|
|
|
'class' => 'form-control', |
306
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.firstname_attribute.tooltip', |
307
|
|
|
], |
308
|
|
|
'empty_data' => 'givenname', |
309
|
|
|
] |
310
|
|
|
); |
311
|
|
|
|
312
|
|
|
$builder->add( |
313
|
|
|
'ldap_auth_lastname_attribute', |
314
|
|
|
TextType::class, |
315
|
|
|
[ |
316
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.lastname_attribute', |
317
|
|
|
'label_attr' => ['class' => 'control-label'], |
318
|
|
|
'attr' => [ |
319
|
|
|
'class' => 'form-control', |
320
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.lastname_attribute.tooltip', |
321
|
|
|
], |
322
|
|
|
'empty_data' => 'sn', |
323
|
|
|
] |
324
|
|
|
); |
325
|
|
|
|
326
|
|
|
$builder->add( |
327
|
|
|
'ldap_auth_fullname_attribute', |
328
|
|
|
TextType::class, |
329
|
|
|
[ |
330
|
|
|
'label' => 'mautic.integration.sso.ldapauth.config.form.fullname_attribute', |
331
|
|
|
'label_attr' => ['class' => 'control-label'], |
332
|
|
|
'attr' => [ |
333
|
|
|
'class' => 'form-control', |
334
|
|
|
'tooltip' => 'mautic.integration.sso.ldapauth.config.form.fullname_attribute.tooltip', |
335
|
|
|
], |
336
|
|
|
'empty_data' => 'displayname', |
337
|
|
|
'required' => false, |
338
|
|
|
] |
339
|
|
|
); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* {@inheritdoc} |
344
|
|
|
*/ |
345
|
|
|
public function getName() |
346
|
|
|
{ |
347
|
|
|
return 'ldapconfig'; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
// TODO Coming feature: LDAP bind account and Group lookup |
351
|
|
|
// /** |
352
|
|
|
// * @return array |
353
|
|
|
// */ |
354
|
|
|
// private function getAuthenticationChoices() |
355
|
|
|
// { |
356
|
|
|
// $choices = $this->authenticationType->getAuthenticationTypes(); |
357
|
|
|
// |
358
|
|
|
// foreach ($choices as $value => $label) { |
359
|
|
|
// $choices[$value] = $this->translator->trans($label); |
360
|
|
|
// } |
361
|
|
|
// |
362
|
|
|
// asort($choices, SORT_NATURAL); |
363
|
|
|
// |
364
|
|
|
// return $choices; |
365
|
|
|
// } |
366
|
|
|
} |
367
|
|
|
|