Projet

Général

Profil

Paste
Télécharger (26,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_authentication / LdapAuthenticationConfAdmin.class.php @ 7547bb19

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * This classextends by LdapAuthenticationConf for configuration and other admin functions
6
 */
7
8
ldap_servers_module_load_include('php', 'ldap_authentication', 'LdapAuthenticationConf.class');
9
10
class LdapAuthenticationConfAdmin extends LdapAuthenticationConf {
11
12
  protected function setTranslatableProperties() {
13
14
    /**
15
     * 0.  Logon Options
16
     */
17
18
    $values['authenticationModeOptions']  = array(
19
      LDAP_AUTHENTICATION_MIXED => t('Mixed mode. Drupal authentication is tried first.  On failure, LDAP authentication is performed.'),
20
      LDAP_AUTHENTICATION_EXCLUSIVE => t('Only LDAP Authentication is allowed except for user 1.
21
        If selected, (1) reset password links will be replaced with links to ldap end user documentation below.
22
        (2) The reset password form will be left available at user/password for user 1; but no links to it
23
        will be provided to anonymous users.
24
        (3) Password fields in user profile form will be removed except for user 1.'),
25
      );
26
27
    $values['authenticationServersDescription'] = t('Check all LDAP server configurations to use in authentication.
28
     Each will be tested for authentication until successful or
29
     until each is exhausted.  In most cases only one server configuration is selected.');
30
31
    /**
32
     * User Login Interface
33
     */
34
    $values['loginUIUsernameTxtDescription'] = t('Text to be displayed to user below the username field of
35
     the user login screen.');
36
37
    $values['loginUIPasswordTxtDescription'] = t('Text to be displayed to user below the password field of
38
     the user login screen.');
39
40
    $values['ldapUserHelpLinkUrlDescription'] = t('URL to LDAP user help/documentation for users resetting
41
     passwords etc. Should be of form http://domain.com/. Could be the institutions ldap password support page
42
     or a page within this drupal site that is available to anonymous users.');
43
44
    $values['ldapUserHelpLinkTextDescription']  = t('Text for above link e.g. Account Help or Campus Password Help Page');
45
46
47
    /**
48
     * LDAP User Restrictions
49
     */
50
51
    $values['allowOnlyIfTextInDnDescription'] = t('A list of text such as ou=education
52
      or cn=barclay that at least one of be found in user\'s dn string.  Enter one per line
53
      such as <pre>ou=education') . "\n" . t('ou=engineering</pre>   This test will be case insensitive.');
54
55
    $values['excludeIfTextInDnDescription'] = t('A list of text such as ou=evil
56
      or cn=bad that if found in a user\'s dn, exclude them from ldap authentication.
57
      Enter one per line such as <pre>ou=evil') . "\n" . t('cn=bad</pre> This test will be case insensitive.');
58
59
    $values['allowTestPhpDescription'] = t('PHP code which should print 1
60
        for allowing ldap authentication or 0 for not allowed.  Available variables are:
61
        $_name and $_ldap_user_entry  See readme.txt for more info.');
62
63
    $values['excludeIfNoAuthorizationsDescription'] = t('If the user is not granted any drupal roles,
64
      organic groups, etc. by LDAP Authorization, login will be denied.  LDAP Authorization must be
65
      enabled for this to work.');
66
67
    /**
68
    * Email
69
    */
70
71
    $values['emailOptionOptions'] = array(
72 7547bb19 Assos Assos
      LDAP_AUTHENTICATION_EMAIL_FIELD_REMOVE => t('Don\'t show an email field on user forms. LDAP derived email will be used for user and cannot be changed by user.'),
73
      LDAP_AUTHENTICATION_EMAIL_FIELD_DISABLE => t('Show disabled email field on user forms with LDAP derived email. LDAP derived email will be used for user and cannot be changed by user.'),
74
      LDAP_AUTHENTICATION_EMAIL_FIELD_ALLOW => t('Leave email field on user forms enabled. Generally used when provisioning to LDAP or not using email derived from LDAP.'),
75 85ad3d82 Assos Assos
      );
76
77
    $values['emailUpdateOptions'] = array(
78
      LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE_NOTIFY => t('Update stored email if LDAP email differs at login and notify user.'),
79
      LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE => t('Update stored email if LDAP email differs at login but don\'t notify user.'),
80
      LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_DISABLE => t('Don\'t update stored email if LDAP email differs at login.'),
81
      );
82 dd54aff9 Assos Assos
    $values['emailTemplateHandlingOptions'] = array(
83
      LDAP_AUTHENTICATION_EMAIL_TEMPLATE_NONE => t('Never use the template.'),
84
      LDAP_AUTHENTICATION_EMAIL_TEMPLATE_IF_EMPTY => t('Use the template if no email address was provided by the LDAP server.'),
85
      LDAP_AUTHENTICATION_EMAIL_TEMPLATE_ALWAYS => t('Always use the template.'),
86
    );
87 85ad3d82 Assos Assos
88
89
    /**
90
    * Password
91
    */
92
93
    $values['passwordUpdateOptions'] = array(
94
      LDAP_AUTHENTICATION_PASSWORD_FIELD_SHOW => t('Display password field disabled (Prevents password updates).'),
95
      LDAP_AUTHENTICATION_PASSWORD_FIELD_HIDE => t('Don\'t show password field on user forms except login form.'),
96
      LDAP_AUTHENTICATION_PASSWORD_FIELD_ALLOW => t('Display password field and allow updating it. In order to change password in LDAP, LDAP provisioning for this field must be enabled.'),
97
      );
98
99
    /**
100
     *  Single Sign-On / Seamless Sign-On
101
     */
102
103
      $values['ldapImplementationOptions'] = array(
104
        'mod_auth_sspi' => t('mod_auth_sspi'),
105
        'mod_auth_kerb' => t('mod_auth_kerb'),
106
        );
107
108
      $values['cookieExpirePeriod'] = array(-1 => t('Session'), 0 => t('Immediately')) +
109
        drupal_map_assoc(array(3600, 86400, 604800, 2592000, 31536000, 315360000, 630720000), 'format_interval');
110
111
      $values['ssoEnabledDescription'] = '<strong>' . t('Single Sign on is enabled.') .
112
        '</strong> ' . t('To disable it, disable the LDAP SSO Module on the') . ' ' . l(t('Modules Form'), 'admin/modules') . '.<p>' .
113
        t('Single Sign-On enables ' .
114
        'users of this site to be authenticated by visiting the URL ' .
115
        '"user/login/sso, or automatically if selecting "automated ' .
116
        'single sign-on" below. Set up of LDAP authentication must be ' .
117
        'performed on the web server. Please review the !readme file ' .
118
        'for more information.', array('!readme' =>
119
        l(t('README.txt'), drupal_get_path('module', 'ldap_sso') . '/README.txt')))
120
        . '</p>';
121
122
      $values['ssoExcludedPathsDescription'] = '<p>' .
123
        t("Which paths will not check for SSO? cron.php is common example.  Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard.
124
          Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.",
125
          array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
126
        '</p>';
127
128
      $values['ssoExcludedHostsDescription'] = '<p>' .
129
        t('If your site is accessible via multiple hostnames, you may only want
130
          the LDAP SSO module to authenticate against some of them. To exclude
131
          any hostnames from SSO, enter them here. Enter one host per line.');
132
        '</p>';
133
134
      $values['ssoRemoteUserStripDomainNameDescription'] = t('Useful when the ' .
135
        'WWW server provides authentication in the form of user@realm and you ' .
136
        'want to have both SSO and regular forms based authentication ' .
137
        'available. Otherwise duplicate accounts with conflicting e-mail ' .
138
        'addresses may be created.');
139
      $values['ssoNotifyAuthenticationDescription'] = t('This displays a message to the ' .
140
        'user after they have succesfully authenticated using single sign on');
141
      $values['seamlessLogInDescription'] = t('This requires that you ' .
142
        'have operational NTLM or Kerberos authentication turned on for at least ' .
143
        'the path user/login/sso, or for the whole domain.');
144
      $values['cookieExpireDescription'] = t('If using the automated/seamless login, a ' .
145
        'cookie is necessary to prevent automatic login after a user ' .
146
        'manually logs out. Select the lifetime of the cookie.');
147
      $values['ldapImplementationDescription'] = t('Select the type of ' .
148
        'authentication mechanism you are using.');
149
150
      foreach ($values as $property => $default_value) {
151
        $this->$property = $default_value;
152
      }
153
    }
154
155
  /**
156
   * 0.  Logon Options
157
   */
158
  public $authenticationModeDefault = LDAP_AUTHENTICATION_MIXED;
159
  public $authenticationModeOptions;
160
161
  protected $authenticationServersDescription;
162
  protected $authenticationServersOptions = array();
163
164
  /**
165
   * 1.  User Login Interface
166
   */
167
  protected $loginUIUsernameTxtDescription;
168
  protected $loginUIPasswordTxtDescription;
169
  protected $ldapUserHelpLinkUrlDescription;
170
  protected $ldapUserHelpLinkTextDescription;
171
172
173
  /**
174
   * 2.  LDAP User Restrictions
175
   */
176
177
  protected $allowOnlyIfTextInDnDescription;
178
  protected $excludeIfTextInDnDescription;
179
  protected $allowTestPhpDescription;
180
181
   /**
182
   * 4. Email
183
   */
184
185
  public $emailOptionDefault = LDAP_AUTHENTICATION_EMAIL_FIELD_REMOVE;
186
  public $emailOptionOptions;
187
188
  public $emailUpdateDefault = LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE_NOTIFY;
189
  public $emailUpdateOptions;
190 dd54aff9 Assos Assos
  
191
  public $emailTemplateHandlingDefault = LDAP_AUTHENTICATION_EMAIL_TEMPLATE_DEFAULT;
192
  public $emailTemplateHandlingOptions;
193
  
194
  public $emailTemplateDefault = LDAP_AUTHENTICATION_DEFAULT_TEMPLATE;
195
  
196
  public $templateUsagePromptUserDefault = LDAP_AUTHENTICATION_TEMPLATE_USAGE_PROMPT_USER_DEFAULT;
197
  
198
  public $templateUsagePromptRegexDefault = LDAP_AUTHENTICATION_DEFAULT_TEMPLATE_REGEX;
199
  
200
  public $templateUsageNeverUpdateDefault = LDAP_AUTHENTICATION_TEMPLATE_USAGE_NEVER_UPDATE_DEFAULT;
201 85ad3d82 Assos Assos
202
   /**
203
   * 5. Single Sign-On / Seamless Sign-On
204
   */
205
206
  public $ssoEnabledDescription;
207
  public $ssoRemoteUserStripDomainNameDescription;
208
  public $ldapImplementationOptions;
209
  public $cookieExpirePeriod;
210
  public $seamlessLogInDescription;
211
  public $cookieExpireDescription;
212
  public $ldapImplementationDescription;
213
214
215
  public $errorMsg = NULL;
216
  public $hasError = FALSE;
217
  public $errorName = NULL;
218
219
  public function clearError() {
220
    $this->hasError = FALSE;
221
    $this->errorMsg = NULL;
222
    $this->errorName = NULL;
223
  }
224
225
  public function save() {
226
    foreach ($this->saveable as $property) {
227
      $save[$property] = $this->{$property};
228
    }
229
    variable_set('ldap_authentication_conf', $save);
230
    $this->load();
231
  }
232
233
  static public function getSaveableProperty($property) {
234
    $ldap_authentication_conf = variable_get('ldap_authentication_conf', array());
235
    return isset($ldap_authentication_conf[$property]) ? $ldap_authentication_conf[$property] : FALSE;
236
237
  }
238
239
  static public function uninstall() {
240
    variable_del('ldap_authentication_conf');
241
  }
242
243
  public function __construct() {
244
    parent::__construct();
245
    $this->setTranslatableProperties();
246
    if ($servers = ldap_servers_get_servers(NULL, 'enabled')) {
247
      foreach ($servers as $sid => $ldap_server) {
248
        $enabled = ($ldap_server->status) ? 'Enabled' : 'Disabled';
249
        $this->authenticationServersOptions[$sid] = $ldap_server->name . ' (' . $ldap_server->address . ') Status: ' . $enabled;
250
      }
251
    }
252
  }
253
254
255
  public function drupalForm() {
256
257
    if (count($this->authenticationServersOptions) == 0) {
258
      $message = ldap_servers_no_enabled_servers_msg('configure LDAP Authentication');
259
      $form['intro'] = array(
260
        '#type' => 'item',
261
        '#markup' => t('<h1>LDAP Authentication Settings</h1>') . $message,
262
      );
263
      return $form;
264
    }
265
266
    $tokens = array();  // not sure what the tokens would be for this form?
267
268
    $form['intro'] = array(
269
        '#type' => 'item',
270
        '#markup' => t('<h1>LDAP Authentication Settings</h1>'),
271
    );
272
273
    $form['logon'] = array(
274
      '#type' => 'fieldset',
275
      '#title' => t('Logon Options'),
276
      '#collapsible' => TRUE,
277
      '#collapsed' => FALSE,
278
    );
279
280
    $form['logon']['authenticationMode'] = array(
281
      '#type' => 'radios',
282
      '#title' => t('Allowable Authentications'),
283
      '#required' => 1,
284
      '#default_value' => $this->authenticationMode,
285
      '#options' => $this->authenticationModeOptions,
286
    );
287
288
    $form['logon']['authenticationServers'] = array(
289
      '#type' => 'checkboxes',
290
      '#title' => t('Authentication LDAP Server Configurations'),
291
      '#required' => FALSE,
292
      '#default_value' => $this->sids,
293
      '#options' => $this->authenticationServersOptions,
294
      '#description' => $this->authenticationServersDescription
295
    );
296
297
    $form['login_UI'] = array(
298
      '#type' => 'fieldset',
299
      '#title' => t('User Login Interface'),
300
      '#collapsible' => TRUE,
301
      '#collapsed' => FALSE,
302
    );
303
304
    $form['login_UI']['loginUIUsernameTxt'] = array(
305
      '#type' => 'textfield',
306
      '#title' => t('Username Description Text'),
307
      '#required' => 0,
308
      '#default_value' => $this->loginUIUsernameTxt,
309
      '#description' => $this->loginUIUsernameTxtDescription,
310
    );
311
312
    $form['login_UI']['loginUIPasswordTxt'] = array(
313
      '#type' => 'textfield',
314
      '#title' => t('Password Description Text'),
315
      '#required' => 0,
316
      '#default_value' => $this->loginUIPasswordTxt,
317
      '#description' => $this->loginUIPasswordTxtDescription,
318
    );
319
320
    $form['login_UI']['ldapUserHelpLinkUrl'] = array(
321
      '#type' => 'textfield',
322
      '#title' => t('LDAP Account User Help URL'),
323
      '#required' => 0,
324
      '#default_value' => $this->ldapUserHelpLinkUrl,
325
      '#description' => $this->ldapUserHelpLinkUrlDescription,
326
    );
327
328
329
    $form['login_UI']['ldapUserHelpLinkText'] = array(
330
      '#type' => 'textfield',
331
      '#title' => t('LDAP Account User Help Link Text'),
332
      '#required' => 0,
333
      '#default_value' => $this->ldapUserHelpLinkText,
334
      '#description' => $this->ldapUserHelpLinkTextDescription,
335
    );
336
337
    $form['restrictions'] = array(
338
      '#type' => 'fieldset',
339
      '#title' => t('LDAP User "Whitelists" and Restrictions'),
340
      '#collapsible' => TRUE,
341
      '#collapsed' => FALSE,
342
    );
343
344
345
    $form['restrictions']['allowOnlyIfTextInDn'] = array(
346
      '#type' => 'textarea',
347
      '#title' => t('Allow Only Text Test'),
348
      '#default_value' => $this->arrayToLines($this->allowOnlyIfTextInDn),
349
      '#cols' => 50,
350
      '#rows' => 3,
351
      '#description' => t($this->allowOnlyIfTextInDnDescription, $tokens),
352
    );
353
354
    $form['restrictions']['excludeIfTextInDn'] = array(
355
      '#type' => 'textarea',
356
      '#title' => t('Excluded Text Test'),
357
      '#default_value' => $this->arrayToLines($this->excludeIfTextInDn),
358
      '#cols' => 50,
359
      '#rows' => 3,
360
      '#description' => t($this->excludeIfTextInDnDescription, $tokens),
361
    );
362
363
    $form['restrictions']['allowTestPhp'] = array(
364
      '#type' => 'textarea',
365
      '#title' => t('PHP to Test for Allowed LDAP Users'),
366
      '#default_value' => $this->allowTestPhp,
367
      '#cols' => 50,
368
      '#rows' => 3,
369
      '#description' => t($this->allowTestPhpDescription, $tokens),
370
      '#disabled' => (boolean)(!module_exists('php')),
371
    );
372
373
    if (!module_exists('php')) {
374
      $form['restrictions']['allowTestPhp']['#title'] .= ' <em>' . t('php module currently disabled') . '</em>';
375
    }
376
377
    $form['restrictions']['excludeIfNoAuthorizations'] = array(
378
      '#type' => 'checkbox',
379
      '#title' => t('Deny access to users without Ldap Authorization Module
380
        authorization mappings such as Drupal roles.
381
        Requires LDAP Authorization to be enabled and configured!'),
382
      '#default_value' =>  $this->excludeIfNoAuthorizations,
383
      '#description' => t($this->excludeIfNoAuthorizationsDescription, $tokens),
384
      '#disabled' => (boolean)(!module_exists('ldap_authorization')),
385
    );
386
387
    $form['email'] = array(
388
      '#type' => 'fieldset',
389
      '#title' => t('Email'),
390
      '#collapsible' => TRUE,
391
      '#collapsed' => FALSE,
392
    );
393
394
    $form['email']['emailOption'] = array(
395
      '#type' => 'radios',
396
      '#title' => t('Email Behavior'),
397
      '#required' => 1,
398
      '#default_value' => $this->emailOption,
399
      '#options' => $this->emailOptionOptions,
400
    );
401
402
    $form['email']['emailUpdate'] = array(
403
      '#type' => 'radios',
404
      '#title' => t('Email Update'),
405
      '#required' => 1,
406
      '#default_value' => $this->emailUpdate,
407
      '#options' => $this->emailUpdateOptions,
408
      );
409 dd54aff9 Assos Assos
    
410
    $form['email']['template'] = array(
411
      '#type' => 'fieldset',
412
      '#collapsible' => TRUE,
413
      '#title' => t('Email Templates'),
414
    );
415
    
416
    $form['email']['template']['emailTemplateHandling'] = array(
417
      '#type' => 'radios',
418
      '#title' => t('Email Template Handling'),
419
      '#required' => 1,
420
      '#default_value' => $this->emailTemplateHandling,
421
      '#options' => $this->emailTemplateHandlingOptions
422
    );
423
    
424
    $form['email']['template']['emailTemplate'] = array(
425
      '#type' => 'textfield',
426
      '#title' => t('Email Template'),
427
      '#required' => 0,
428
      '#default_value' => $this->emailTemplate,
429
    );
430
    
431
    $form['email']['template']['templateUsageResolveConflict'] = array(
432
      '#type' => 'checkbox',
433
      '#title' => t('If a Drupal account already exists with the same email, but different account name, use the email template instead of the LDAP email.'),
434
      '#default_value' => $this->templateUsageResolveConflict,
435
    );
436
    
437
    $form['email']['template']['templateUsageNeverUpdate'] = array(
438
      '#type' => 'checkbox',
439
      '#title' => t('Ignore the Email Update settings and never update the stored email if the template is used.'),
440
      '#default_value' => $this->templateUsageNeverUpdate,
441
    );
442
    
443
    $form['email']['prompts'] = array(
444
      '#type' => 'fieldset',
445
      '#collapsible' => TRUE,
446
      '#title' => t('User Email Prompt'),
447
      '#description' => t('These settings allow the user to fill in their email address after logging in if the template was used to generate their email address.'),      
448
    );
449
    
450
    $form['email']['prompts']['templateUsagePromptUser'] = array(
451
      '#type' => 'checkbox',
452
      '#title' => t('Prompt user for email on every page load.'),
453
      '#default_value' => $this->templateUsagePromptUser,
454
    );
455
    
456
    $form['email']['prompts']['templateUsageRedirectOnLogin'] = array(
457
      '#type' => 'checkbox',
458
      '#title' => t('Redirect the user to the form after logging in.'),
459
      '#default_value' => $this->templateUsageRedirectOnLogin,
460
    );
461
    
462
    $form['email']['prompts']['templateUsagePromptRegex'] = array(
463
      '#type' => 'textfield',
464
      '#default_value' => $this->templateUsagePromptRegex,
465
      '#title' => t('Template Regex'),
466
      '#description' => t('This regex will be used to determine if the template was used to create an account.'),
467
    );
468
    
469 85ad3d82 Assos Assos
470
    $form['password'] = array(
471
      '#type' => 'fieldset',
472
      '#title' => t('Password'),
473
      '#collapsible' => TRUE,
474
      '#collapsed' => FALSE,
475
    );
476
    $form['password']['passwordOption'] = array(
477
      '#type' => 'radios',
478
      '#title' => t('Password Behavior'),
479
      '#required' => 1,
480
      '#default_value' => $this->passwordOption,
481
      '#options' => $this->passwordUpdateOptions,
482
    );
483
484
    /**
485
     * Begin single sign-on settings
486
     */
487
    $form['sso'] = array(
488
      '#type' => 'fieldset',
489
      '#title' => t('Single Sign-On'),
490
      '#collapsible' => TRUE,
491
      '#collapsed' => (boolean)(!$this->ssoEnabled),
492
    );
493
494
    if ($this->ssoEnabled) {
495
      $form['sso']['enabled'] = array(
496
        '#type' => 'markup',
497
        '#markup' => $this->ssoEnabledDescription,
498
      );
499
    }
500
    else {
501
      $form['sso']['disabled'] = array(
502
        '#type' => 'markup',
503
        '#markup' => '<p><em>' . t('LDAP Single Sign-On module must be enabled for options below to work.')
504
        . ' ' . t('It is currently disabled.')
505
        . ' ' . l(t('See modules form'), 'admin/modules') . '</p></em>',
506
      );
507
    }
508
509
    $form['sso']['ssoRemoteUserStripDomainName'] = array(
510
      '#type' => 'checkbox',
511
      '#title' => t('Strip REMOTE_USER domain name'),
512
      '#description' => t($this->ssoRemoteUserStripDomainNameDescription),
513
      '#default_value' => $this->ssoRemoteUserStripDomainName,
514
      '#disabled' => (boolean)(!$this->ssoEnabled),
515
    );
516
517
    $form['sso']['seamlessLogin'] = array(
518
      '#type' => 'checkbox',
519
      '#title' => t('Turn on automated/seamless single sign-on'),
520
      '#description' => t($this->seamlessLogInDescription),
521
      '#default_value' => $this->seamlessLogin,
522
      '#disabled' => (boolean)(!$this->ssoEnabled),
523
      );
524
525
    $form['sso']['ssoNotifyAuthentication'] = array(
526
      '#type' => 'checkbox',
527
      '#title' => t('Notify user of successful authentication'),
528
      '#description' => t($this->ssoNotifyAuthenticationDescription),
529
      '#default_value' => $this->ssoNotifyAuthentication,
530
      '#disabled' => (boolean)(!$this->ssoEnabled),
531
      );
532
533
    $form['sso']['cookieExpire'] = array(
534
      '#type' => 'select',
535
      '#title' => t('Cookie Lifetime'),
536
      '#description' => t($this->cookieExpireDescription),
537
      '#default_value' => $this->cookieExpire,
538
      '#options' => $this->cookieExpirePeriod,
539
      '#disabled' => (boolean)(!$this->ssoEnabled),
540
    );
541
542
    $form['sso']['ldapImplementation'] = array(
543
      '#type' => 'select',
544
      '#title' => t('Authentication Mechanism'),
545
      '#description' => t($this->ldapImplementationDescription),
546
      '#default_value' => $this->ldapImplementation,
547
      '#options' => $this->ldapImplementationOptions,
548
      '#disabled' => (boolean)(!$this->ssoEnabled),
549
    );
550
551
    $form['sso']['ssoExcludedPaths'] = array(
552
      '#type' => 'textarea',
553
      '#title' => t('SSO Excluded Paths'),
554
      '#description' => t($this->ssoExcludedPathsDescription),
555
      '#default_value' => $this->arrayToLines($this->ssoExcludedPaths),
556
      '#disabled' => (boolean)(!$this->ssoEnabled),
557
    );
558
559
    $form['sso']['ssoExcludedHosts'] = array(
560
      '#type' => 'textarea',
561
      '#title' => t('SSO Excluded Hosts'),
562
      '#description' => t($this->ssoExcludedHostsDescription),
563
      '#default_value' => $this->arrayToLines($this->ssoExcludedHosts),
564
      '#disabled' => (boolean)(!$this->ssoEnabled),
565
    );
566
567
    $form['submit'] = array(
568
      '#type' => 'submit',
569
      '#value' => 'Save',
570
    );
571
572
  return $form;
573
}
574
575
/**
576
 * validate form, not object
577
 */
578
  public function drupalFormValidate($values)  {
579
580
    $this->populateFromDrupalForm($values);
581
582
    $errors = $this->validate();
583
584
    return $errors;
585
  }
586
587
/**
588
 * validate object, not form
589
 */
590
  public function validate() {
591
    $errors = array();
592
593
    $enabled_servers = ldap_servers_get_servers(NULL, 'enabled');
594
    if ($this->ssoEnabled) {
595
      foreach ($this->sids as $sid => $discard) {
596
        if ($enabled_servers[$sid]->bind_method == LDAP_SERVERS_BIND_METHOD_USER || $enabled_servers[$sid]->bind_method == LDAP_SERVERS_BIND_METHOD_ANON_USER) {
597
          $methods = array(
598
            LDAP_SERVERS_BIND_METHOD_USER => 'Bind with Users Credentials',
599
            LDAP_SERVERS_BIND_METHOD_ANON_USER => 'Anonymous Bind for search, then Bind with Users Credentials',
600
          );
601
          $tokens = array(
602
            '!edit' => l($enabled_servers[$sid]->name, LDAP_SERVERS_INDEX_BASE_PATH . '/edit/' . $sid),
603
            '%sid' => $sid,
604
            '%bind_method' => $methods[$enabled_servers[$sid]->bind_method],
605
          );
606
607
          $errors['ssoEnabled'] = t('Single Sign On is not valid with the server !edit (id=%sid) because that server configuration uses %bind_method.  Since the user\'s credentials are never available to this module with single sign on enabled, there is no way for the ldap module to bind to the ldap server with credentials.', $tokens);
608
        }
609
      }
610
    }
611
    return $errors;
612
  }
613
614
  protected function populateFromDrupalForm($values) {
615
616
    $this->authenticationMode = ($values['authenticationMode']) ? (int)$values['authenticationMode'] : NULL;
617
    $this->sids = $values['authenticationServers'];
618
    $this->allowOnlyIfTextInDn = $this->linesToArray($values['allowOnlyIfTextInDn']);
619
    $this->excludeIfTextInDn = $this->linesToArray($values['excludeIfTextInDn']);
620
    $this->allowTestPhp = $values['allowTestPhp'];
621
    $this->loginUIUsernameTxt = ($values['loginUIUsernameTxt']) ? (string)$values['loginUIUsernameTxt'] : NULL;
622
    $this->loginUIPasswordTxt = ($values['loginUIPasswordTxt']) ? (string)$values['loginUIPasswordTxt'] : NULL;
623
    $this->ldapUserHelpLinkUrl = ($values['ldapUserHelpLinkUrl']) ? (string)$values['ldapUserHelpLinkUrl'] : NULL;
624
    $this->ldapUserHelpLinkText = ($values['ldapUserHelpLinkText']) ? (string)$values['ldapUserHelpLinkText'] : NULL;
625
    $this->excludeIfNoAuthorizations = ($values['excludeIfNoAuthorizations']) ? (int)$values['excludeIfNoAuthorizations'] : NULL;
626
    $this->emailOption  = ($values['emailOption']) ? (int)$values['emailOption'] : NULL;
627
    $this->emailUpdate  = ($values['emailUpdate']) ? (int)$values['emailUpdate'] : NULL;
628
    $this->passwordOption  = ($values['passwordOption']) ? (int)$values['passwordOption'] : NULL;
629
    $this->ssoExcludedPaths = $this->linesToArray($values['ssoExcludedPaths']);
630
    $this->ssoExcludedHosts = $this->linesToArray($values['ssoExcludedHosts']);
631
    $this->ssoRemoteUserStripDomainName = ($values['ssoRemoteUserStripDomainName']) ? (int)$values['ssoRemoteUserStripDomainName'] : NULL;
632
    $this->seamlessLogin = ($values['seamlessLogin']) ? (int)$values['seamlessLogin'] : NULL;
633
    $this->ssoNotifyAuthentication = ($values['ssoNotifyAuthentication']) ? (int)$values['ssoNotifyAuthentication'] : NULL;
634
    $this->cookieExpire = ($values['cookieExpire']) ? (int)$values['cookieExpire'] : NULL;
635
    $this->ldapImplementation = ($values['ldapImplementation']) ? (string)$values['ldapImplementation'] : NULL;
636 dd54aff9 Assos Assos
    $this->emailTemplateHandling = ($values['emailTemplateHandling']) ? (int) $values['emailTemplateHandling'] : NULL;
637
    $this->emailTemplate = ($values['emailTemplate']) ? $values['emailTemplate'] : '';
638
    $this->templateUsagePromptUser = ($values['templateUsagePromptUser']) ? 1 : 0;
639
    $this->templateUsageResolveConflict = ($values['templateUsageResolveConflict']) ? 1 : 0;
640
    $this->templateUsagePromptRegex = ($values['templateUsagePromptRegex']) ? $values['templateUsagePromptRegex'] : '';
641
    $this->templateUsageRedirectOnLogin = ($values['templateUsageRedirectOnLogin']) ? 1 : 0;
642
    $this->templateUsageNeverUpdate = ($values['templateUsageNeverUpdate']) ? 1 : 0;
643 85ad3d82 Assos Assos
  }
644
645
  public function drupalFormSubmit($values) {
646
647
    $this->populateFromDrupalForm($values);
648
    try {
649
      $save_result = $this->save();
650
    }
651
    catch (Exception $e) {
652
      $this->errorName = 'Save Error';
653
      $this->errorMsg = t('Failed to save object.  Your form data was not saved.');
654
      $this->hasError = TRUE;
655
    }
656
657
  }
658
659
  protected function arrayToLines($array) {
660
        $lines = "";
661
        if (is_array($array)) {
662
          $lines = join("\n", $array);
663
        }
664
        elseif (is_array(@unserialize($array))) {
665
          $lines = join("\n", unserialize($array));
666
        }
667
        return $lines;
668
      }
669
670
  protected function linesToArray($lines) {
671
    $lines = trim($lines);
672
673
    if ($lines) {
674
      $array = preg_split('/[\n\r]+/', $lines);
675
      foreach ($array as $i => $value) {
676
        $array[$i] = trim($value);
677
      }
678
    }
679
    else {
680
      $array = array();
681
    }
682
    return $array;
683
  }
684
685
}