Projet

Général

Profil

Paste
Télécharger (42,9 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_user / LdapUserConfAdmin.class.php @ 59ae487e

1
<?php
2

    
3
/**
4
 * @file
5
 * This classextends by LdapUserConf for configuration and other admin functions
6
 */
7

    
8
module_load_include('php', 'ldap_user', 'LdapUserConf.class');
9
module_load_include('inc', 'user', 'user.pages');
10

    
11
class LdapUserConfAdmin extends LdapUserConf {
12

    
13
  /**
14
   * basic settings
15
   */
16

    
17
  protected $drupalAcctProvisionServerDescription;
18
  protected $drupalAcctProvisionServerOptions = array();
19
  protected $ldapEntryProvisionServerOptions = array();
20

    
21
  protected $drupalAccountProvisionEventsDescription;
22
  protected $drupalAccountProvisionEventsOptions = array();
23

    
24
  protected $ldapEntryProvisionTriggersDescription;
25
  protected $ldapEntryProvisionTriggersOptions = array();
26

    
27
  protected $synchFormRow = 0;
28

    
29
  /*
30
   * 3. Drupal Account Provisioning and Syncing
31
   */
32
  public $userConflictResolveDescription;
33
  public $userConflictResolveDefault = LDAP_USER_CONFLICT_RESOLVE_DEFAULT;
34
  public $userConflictOptions;
35

    
36
  public $acctCreationDescription = '';
37
  public $acctCreationDefault = LDAP_USER_ACCT_CREATION_LDAP_BEHAVIOR_DEFAULT;
38
  public $acctCreationOptions;
39

    
40

    
41
  public $errorMsg = NULL;
42
  public $hasError = FALSE;
43
  public $errorName = NULL;
44

    
45
  public function clearError() {
46
    $this->hasError = FALSE;
47
    $this->errorMsg = NULL;
48
    $this->errorName = NULL;
49
  }
50

    
51
  public function save() {
52
    foreach ($this->saveable as $property) {
53
      $save[$property] = $this->{$property};
54
    }
55
    variable_set('ldap_user_conf', $save);
56
    ldap_user_conf_cache_clear();
57
  }
58

    
59
  static public function uninstall() {
60
    variable_del('ldap_user_conf');
61
  }
62

    
63
  public function __construct() {
64
    parent::__construct();
65
    $this->setTranslatableProperties();
66

    
67
    if ($servers = ldap_servers_get_servers(NULL, 'enabled')) {
68
      $this->drupalAcctProvisionServerOptions[LDAP_USER_AUTH_SERVER_SID] = t('Use server which performed the authentication. Useful for multi-domain environments.');
69
      foreach ($servers as $sid => $ldap_server) {
70
        $enabled = ($ldap_server->status) ? 'Enabled' : 'Disabled';
71
        $this->drupalAcctProvisionServerOptions[$sid] = $ldap_server->name . ' (' . $ldap_server->address . ') Status: ' . $enabled;
72
        $this->ldapEntryProvisionServerOptions[$sid] = $ldap_server->name . ' (' . $ldap_server->address . ') Status: ' . $enabled;
73
      }
74
    }
75
    $this->drupalAcctProvisionServerOptions['none'] = t('None');
76
    $this->ldapEntryProvisionServerOptions['none'] = t('None');
77

    
78
  }
79

    
80

    
81
/**
82
 * generate admin form for ldapUserConf object
83
 *
84
 * @return array $form as drupal form api form array
85
 */
86
  public function drupalForm() {
87
    if (count($this->drupalAcctProvisionServerOptions) == 0) {
88
      $message = ldap_servers_no_enabled_servers_msg('configure LDAP User');
89
      $form['intro'] = array(
90
        '#type' => 'item',
91
        '#markup' => t('<h1>LDAP User Settings</h1>') . $message,
92
      );
93
      return $form;
94
    }
95
    $form['#storage'] = array();
96
    $form['#theme'] = 'ldap_user_conf_form';
97

    
98
    $form['intro'] = array(
99
      '#type' => 'item',
100
      '#markup' => t('<h1>LDAP User Settings</h1>'),
101
    );
102

    
103
    $form['manual_drupal_account_editing'] = array(
104
      '#type' => 'fieldset',
105
      '#title' => t('Manual Drupal Account Creation and Updates'),
106
      '#collapsible' => TRUE,
107
      '#collapsed' => FALSE,
108
    );
109

    
110
    $form['manual_drupal_account_editing']['manualAccountConflict'] = array(
111
      '#type' => 'radios',
112
      '#options' => $this->manualAccountConflictOptions,
113
      '#title' => t('How to resolve LDAP conflicts with manually  created Drupal accounts.'),
114
      '#description' => t('This applies only to accounts created manually through admin/people/create
115
        for which an LDAP entry can be found on the LDAP server selected in "LDAP Servers Providing Provisioning Data"'),
116
      '#default_value' => $this->manualAccountConflict,
117
    );
118

    
119
    $form['basic_to_drupal'] = array(
120
      '#type' => 'fieldset',
121
      '#title' => t('Basic Provisioning to Drupal Account Settings'),
122
      '#collapsible' => TRUE,
123
      '#collapsed' => FALSE,
124
    );
125

    
126
    $default_value = ($this->drupalAcctProvisionServer) ? $this->drupalAcctProvisionServer : 'none';
127
    $form['basic_to_drupal']['drupalAcctProvisionServer'] = array(
128
      '#type' => 'radios',
129
      '#title' => t('LDAP Servers Providing Provisioning Data'),
130
      '#required' => 1,
131
      '#default_value' => $default_value,
132
      '#options' => $this->drupalAcctProvisionServerOptions,
133
      '#description' => $this->drupalAcctProvisionServerDescription,
134
      '#states' => array(
135
        'enabled' => array(   // action to take.
136
          ':input[name=drupalAcctProvisionTriggers]' => array('value' => LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE),
137
        ),
138
      ),
139
    );
140

    
141

    
142
    $form['basic_to_drupal']['drupalAcctProvisionTriggers'] = array(
143
      '#type' => 'checkboxes',
144
      '#title' => t('Drupal Account Provisioning Events'),
145
      '#required' => FALSE,
146
      '#default_value' => $this->drupalAcctProvisionTriggers,
147
      '#options' => $this->drupalAccountProvisionEventsOptions,
148
      '#description' => $this->drupalAccountProvisionEventsDescription,
149
    );
150

    
151
    $form['basic_to_drupal']['disableAdminPasswordField'] = array(
152
      '#type' => 'checkbox',
153
      '#title' => t('Disable the password fields at /admin/create/people since the password is going to be randomly generated anyway. This is useful if you are synching data to Drupal from LDAP, and not bringing the user password from LDAP.'),
154
      '#default_value' => $this->disableAdminPasswordField,
155
    );
156

    
157
    $form['basic_to_drupal']['userConflictResolve'] = array(
158
      '#type' => 'radios',
159
      '#title' => t('Existing Drupal User Account Conflict'),
160
      '#required' => 1,
161
      '#default_value' => $this->userConflictResolve,
162
      '#options' => $this->userConflictOptions,
163
      '#description' => t( $this->userConflictResolveDescription),
164
    );
165

    
166
    $form['basic_to_drupal']['acctCreation'] = array(
167
      '#type' => 'radios',
168
      '#title' => t('Application of Drupal Account settings to LDAP Authenticated Users'),
169
      '#required' => 1,
170
      '#default_value' => $this->acctCreation,
171
      '#options' => $this->acctCreationOptions,
172
      '#description' => t($this->acctCreationDescription),
173
    );
174

    
175
    $account_options = array();
176
    $account_options['ldap_user_orphan_do_not_check'] = t('Do not check for orphaned Drupal accounts.');
177
    $account_options['ldap_user_orphan_email'] = t('Perform no action, but email list of orphaned accounts. (All the other options will send email summaries also.)');
178
    foreach (user_cancel_methods() as $option_name => $option) {
179
      $account_options[$option_name] = $option['#title'];
180
    }
181

    
182
    //@todo these 2 options are removed until this feature is better tested in
183
    // actual production environments; it has potentially disastrous effects
184
    unset($account_options['user_cancel_reassign']);
185
    unset($account_options['user_cancel_delete']);
186

    
187
    $form['basic_to_drupal']['orphanedDrupalAcctBehavior'] = array(
188
      '#type' => 'radios',
189
      '#title' => t('Action to perform on Drupal account that no longer have a
190
        corresponding LDAP entry'),
191
      '#required' => 0,
192
      '#default_value' => $this->orphanedDrupalAcctBehavior,
193
      '#options' => $account_options,
194
      '#description' => t($this->orphanedDrupalAcctBehaviorDescription),
195
    );
196

    
197

    
198
    $form['basic_to_drupal']['orphanedCheckQty'] = array(
199
      '#type' => 'textfield',
200
      '#size' => 10,
201
      '#title' => t('Number of users to check each cron run.'),
202
      '#description' => t(''),
203
      '#default_value' => $this->orphanedCheckQty,
204
      '#required' => FALSE,
205
    );
206

    
207

    
208
    $form['basic_to_ldap'] = array(
209
      '#type' => 'fieldset',
210
      '#title' => t('Basic Provisioning to LDAP Settings'),
211
      '#collapsible' => TRUE,
212
      '#collapsed' => !($this->ldapEntryProvisionServer),
213
    );
214

    
215
    $default_value = ($this->ldapEntryProvisionServer) ? $this->ldapEntryProvisionServer : 'none';
216
    $form['basic_to_ldap']['ldapEntryProvisionServer'] = array(
217
      '#type' => 'radios',
218
      '#title' => t('LDAP Servers to Provision LDAP Entries on'),
219
      '#required' => 1,
220
      '#default_value' => $default_value,
221
      '#options' => $this->ldapEntryProvisionServerOptions,
222
      '#description' => $this->ldapEntryProvisionServerDescription,
223
    );
224

    
225
    $form['basic_to_ldap']['ldapEntryProvisionTriggers'] = array(
226
      '#type' => 'checkboxes',
227
      '#title' => t('LDAP Entry Provisioning Events'),
228
      '#required' => FALSE,
229
      '#default_value' => $this->ldapEntryProvisionTriggers,
230
      '#options' => $this->ldapEntryProvisionTriggersOptions,
231
      '#description' => $this->ldapEntryProvisionTriggersDescription
232
    );
233

    
234
/**
235
    $form['ws'] = array(
236
      '#type' => 'fieldset',
237
      '#title' => t('[Untested and Unfinished Code] REST Webservice for Provisioning and Synching.'),
238
      '#collapsible' => TRUE,
239
      '#collapsed' => !$this->wsEnabled,
240
      '#description' => t('Once configured, this webservice can be used to trigger creation, synching, deletion, etc of an LDAP associated Drupal account.'),
241
    );
242

243
    $form['ws']['wsEnabled'] = array(
244
      '#type' => 'checkbox',
245
      '#title' => t('Enable REST Webservice'),
246
      '#required' => FALSE,
247
      '#default_value' => $this->wsEnabled,
248
    );
249

250
    $form['ws']['wsUserIps'] = array(
251
      '#type' => 'textarea',
252
      '#title' => t('Allowed IP Addresses to request webservice.'),
253
      '#required' => FALSE,
254
      '#default_value' => join("\n", $this->wsUserIps),
255
      '#description' => t('One Per Line. The current server address is LOCAL_ADDR and the client ip requesting this page is REMOTE_ADDR .', $_SERVER),
256
      '#cols' => 20,
257
      '#rows' => 2,
258
      '#states' => array(
259
        'visible' => array(   // action to take.
260
          ':input[name="wsEnabled"]' => array('checked' => TRUE),
261
        ),
262
      ),
263
    );
264

265
    if (!$this->wsKey) {
266
      $urls = t('URLs are not available until a key is create a key and urls will be generated');
267
    }
268
    else {
269
      $urls = theme('item_list',
270
        array(
271
          'items' => ldap_user_ws_urls_item_list(),
272
          'title' => 'REST urls',
273
          'type' => 'ul',
274
        ));
275
    }
276

277
    $form['ws']['wsKey'] = array(
278
      '#type' => 'textfield',
279
      '#title' => t('Key for webservice'),
280
      '#required' => FALSE,
281
      '#default_value' => $this->wsKey,
282
      '#description' => t('Any random string of characters.') . $urls,
283
      '#states' => array(
284
        'visible' => array(   // action to take.
285
          ':input[name="wsEnabled"]' => array('checked' => TRUE),
286
        ),
287
      ),
288
    );
289
*/
290

    
291
    $form['basic_to_drupal']['server_mapping_preamble'] = array(
292
      '#type' => 'markup',
293
      '#markup' => t('
294
The relationship between a Drupal user and an LDAP entry is defined within the LDAP server configurations.
295

296

297
The mappings below are for user fields, properties, and profile2 data that are not automatically mapped elsewhere.
298
Mappings such as username or email address that are configured elsewhere are shown at the top for clarity.
299
When more than one ldap server is enabled for provisioning data (or simply more than one configuration for the same ldap server),
300
mappings need to be setup for each server.  If no tables are listed below, you have not enabled any provisioning servers at
301
the top of this form.
302
'),
303
    );
304

    
305
    foreach (array(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) as $direction) {
306
      $sid = $this->provisionSidFromDirection[$direction];
307
      $ldap_server = ($sid) ? ldap_servers_get_servers($sid, NULL, TRUE) : FALSE;
308
      $ldap_server_selected = (boolean)$ldap_server;
309

    
310
      if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
311
        $parent_fieldset = 'basic_to_drupal';
312
        $description =  t('Provisioning from LDAP to Drupal Mappings:');
313
      }
314
      elseif ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
315
        $parent_fieldset = 'basic_to_ldap';
316
        $description =   t('Provisioning from Drupal to LDAP Mappings:');
317
      }
318

    
319
      $form[$parent_fieldset]['mappings__' . $direction] = array(
320
        '#type' => 'fieldset',
321
        '#title' =>  $description,
322
        '#collapsible' => TRUE,
323
        '#collapsed' => FALSE,
324
        '#description' => '',
325
        'table__' . $direction => array(
326
          '#type' => 'markup',
327
          '#markup' => '[replace_with_table__' . $direction . ']',
328
        ),
329
      );
330

    
331

    
332
$password_notes = '<h3>' . t('Password Tokens') . '</h3><ul>' .
333
'<li>' . t('Pwd: Random -- Uses a random Drupal generated password') . '</li>' .
334
'<li>' . t('Pwd: User or Random -- Uses password supplied on user forms.
335
  If none available uses random password.') . '</li></ul>' .
336
'<h3>' . t('Password Concerns') . '</h3>' .
337
'<ul>' .
338
'<li>' . t('Provisioning passwords to LDAP means passwords must meet the LDAP\'s
339
password requirements.  Password Policy module can be used to add requirements.') . '</li>' .
340
'<li>' . t('Some LDAPs require a user to reset their password if it has been changed
341
by someone other that user.  Consider this when provisioning LDAP passwords.') . '</li>' .
342
'</ul></p>';
343

    
344

    
345
      $source_drupal_token_notes = <<<EOT
346
<p>Examples in form: Source Drupal User token => Target LDAP Token (notes)</p>
347
<ul>
348
<li>Source Drupal User token => Target LDAP Token</li>
349
<li>cn=[property.name],ou=test,dc=ad,dc=mycollege,dc=edu => [dn] (example of token and constants)</li>
350
<li>top => [objectclass:0] (example of constants mapped to multivalued attribute)</li>
351
<li>person => [objectclass:1] (example of constants mapped to multivalued attribute)</li>
352
<li>organizationalPerson => [objectclass:2] (example of constants mapped to multivalued attribute)</li>
353
<li>user => [objectclass:3] (example of constants mapped to multivalued attribute)</li>
354
<li>Drupal Provisioned LDAP Account => [description] (example of constant)</li>
355
<li>[field.field_lname] => [sn]</li>
356

357
</ul>
358
EOT;
359

    
360
      if ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) { // add some password notes
361
        $form[$parent_fieldset]['password_notes'] = array(
362
          '#type' => 'fieldset',
363
          '#title' =>  t('Password Notes'),
364
          '#collapsible' => TRUE,
365
          '#collapsed' => TRUE,
366
          'directions' => array(
367
            '#type' => 'markup',
368
            '#markup' => $password_notes,
369
          ),
370
        );
371
        $form[$parent_fieldset]['source_drupal_token_notes'] = array(
372
          '#type' => 'fieldset',
373
          '#title' =>  t('Source Drupal User Tokens and Corresponding Target LDAP Tokens'),
374
          '#collapsible' => TRUE,
375
          '#collapsed' => TRUE,
376
          'directions' => array(
377
            '#type' => 'markup',
378
            '#markup' => $source_drupal_token_notes,
379
          ),
380
        );
381
      }
382
      $this->addServerMappingFields($form, $direction);
383
    }
384

    
385
    foreach (array('orphanedCheckQty', 'orphanedDrupalAcctBehavior', 'acctCreation', 'userConflictResolve', 'drupalAcctProvisionTriggers', 'mappings__' . LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) as $input_name) {
386
      $form['basic_to_drupal'][$input_name]['#states']['invisible'] =
387
        array(
388
          ':input[name=drupalAcctProvisionServer]' => array('value' => 'none'),
389
        );
390
    }
391

    
392
    foreach (array('ldapEntryProvisionTriggers', 'password_notes', 'source_drupal_token_notes', 'mappings__' . LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) as $input_name) {
393
      $form['basic_to_ldap'][$input_name]['#states']['invisible'] =
394
        array(
395
          ':input[name=ldapEntryProvisionServer]' => array('value' => 'none'),
396
        );
397
    }
398

    
399
    $form['submit'] = array(
400
      '#type' => 'submit',
401
      '#value' => 'Save',
402
    );
403

    
404
  return $form;
405
}
406

    
407

    
408

    
409
/**
410
 * validate submitted form
411
 *
412
 * @param array $values as $form_state['values'] from drupal form api
413
 * @param array $storage as $form_state['storage'] from drupal form api
414
 *
415
 * @return array in form array($errors, $warnings)to be thrown by form api
416
 */
417
  public function drupalFormValidate($values, $storage)  {
418
    $this->populateFromDrupalForm($values, $storage);
419
    list($errors, $warnings) = $this->validate($values);
420

    
421
    // since failed mapping rows in form, don't populate ->ldapUserSynchMappings, need to validate these from values
422
    foreach ($values as $field => $value) {
423
      $parts = explode('__', $field);
424
      // since synch mapping fields are in n-tuples, process entire n-tuple at once (on field == configurable_to_drupal)
425
      if (count($parts) != 4 || $parts[1] !== 'sm' || $parts[2] != 'configurable_to_drupal') {
426
        continue;
427
      }
428
      list($direction, $discard, $column_name, $i) = $parts;
429
      $action = $storage['synch_mapping_fields'][$direction][$i]['action'];
430
      $tokens = array();
431
      $row_mappings = array();
432
      foreach (array('remove', 'configurable_to_drupal', 'configurable_to_ldap', 'convert', 'direction', 'ldap_attr', 'user_attr', 'user_tokens') as $column_name) {
433
        $input_name = join('__', array('sm', $column_name, $i));
434
        $row_mappings[$column_name] = isset($values[$input_name]) ? $values[$input_name] : NULL;
435
      }
436

    
437
      $has_values = $row_mappings['ldap_attr'] || $row_mappings['user_attr'];
438
      if ($has_values) {
439
        $tokens['%ldap_attr'] = $row_mappings['ldap_attr'];
440
        $row_descriptor = t("server %sid row mapping to ldap attribute %ldap_attr", $tokens);
441
        $tokens['!row_descriptor'] = $row_descriptor;
442
        if (!$row_mappings['direction']) {
443
          $input_name = join('__', array('sm', 'direction', $i));
444
          $errors[$input_name] = t('No mapping direction given in !row_descriptor', $tokens);
445
        }
446
        if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER && $row_mappings['user_attr'] == 'user_tokens') {
447
          $input_name = join('__', array('sm', 'user_attr', $i));
448
          $errors[$input_name] =  t('User tokens not allowed when mapping to Drupal user.  Location: !row_descriptor', $tokens);
449
        }
450
        if (!$row_mappings['ldap_attr']) {
451
          $input_name = join('__', array('sm', 'ldap_attr', $i));
452
          $errors[$input_name] = t('No ldap attribute given in !row_descriptor', $tokens);
453
        }
454
        if (!$row_mappings['user_attr']) {
455
          $input_name = join('__', array('sm', 'user_attr', $i));
456
          $errors[$input_name] = t('No user attribute given in !row_descriptor', $tokens);
457
        }
458
      }
459

    
460
    }
461
    return array($errors, $warnings);
462
  }
463

    
464
/**
465
 * validate object, not form
466
 * @param array $values as $form_state['values'] from drupal form api
467
 * @return array in form array($errors, $warnings)to be thrown by form api
468
 *
469
 * @todo validate that a user field exists, such as field.field_user_lname
470
 *
471
 */
472
  public function validate($values) {
473
    $errors = array();
474
    $warnings = array();
475
    $tokens = array();
476

    
477
    $has_drupal_acct_prov_servers  = (boolean)($this->drupalAcctProvisionServer);
478
    $has_drupal_acct_prov_settings_options  = (count(array_filter($this->drupalAcctProvisionTriggers)) > 0);
479

    
480
    if (!$has_drupal_acct_prov_servers && $has_drupal_acct_prov_settings_options) {
481
      $warnings['drupalAcctProvisionServer'] =  t('No Servers are enabled to provide provisioning to Drupal, but Drupal Account Provisioning Options are selected.', $tokens);
482
    }
483
    if ($has_drupal_acct_prov_servers && !$has_drupal_acct_prov_settings_options) {
484
      $warnings['drupalAcctProvisionTriggers'] =  t('Servers are enabled to provide provisioning to Drupal, but no Drupal Account Provisioning Options are selected.  This will result in no synching happening.', $tokens);
485
    }
486

    
487
    $has_ldap_prov_servers = (boolean)($this->ldapEntryProvisionServer);
488
    $has_ldap_prov_settings_options = (count(array_filter($this->ldapEntryProvisionTriggers)) > 0);
489
    if (!$has_ldap_prov_servers && $has_ldap_prov_settings_options) {
490
      $warnings['ldapEntryProvisionServer'] =  t('No Servers are enabled to provide provisioning to ldap, but LDAP Entry Options are selected.', $tokens);
491
    }
492
    if ($has_ldap_prov_servers && !$has_ldap_prov_settings_options) {
493
      $warnings['ldapEntryProvisionTriggers'] =  t('Servers are enabled to provide provisioning to ldap, but no LDAP Entry Options are selected.  This will result in no synching happening.', $tokens);
494
    }
495

    
496
    if (isset($this->ldapUserSynchMappings)) {
497
      $to_ldap_entries_mappings_exist = FALSE;
498
      foreach ($this->ldapUserSynchMappings as $synch_direction => $mappings) {
499
        $map_index = array();
500
        $tokens = array(); // array('%sid' => $sid);
501
        $to_drupal_user_mappings_exist = FALSE;
502
        $to_ldap_entries_mappings_exist = FALSE;
503

    
504
        foreach ($mappings as $target_attr => $mapping) {
505
          if ($mapping['direction'] == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
506
            $attr_value = $mapping['user_attr'];
507
            $attr_name = 'user_attr';
508
          }
509
          if ($mapping['direction'] == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
510
            $attr_value = $mapping['ldap_attr'];
511
            $attr_name = 'ldap_attr';
512
          }
513
          foreach ($values as $field => $value) {
514
            $parts = explode('__', $field);
515
            if (count($parts) == 4 && $parts[2] == $attr_name && $value == $attr_value) {
516
              $map_index[$attr_value] = $parts[3];
517
            }
518
          }
519
        }
520

    
521
        foreach ($mappings as $target_attr => $mapping) {
522
          foreach ($mapping as $key => $value) {
523
            if (is_scalar($value)) {
524
              $tokens['%' . $key] = $value;
525
            }
526
          }
527
          $row_descriptor = t("server %sid row mapping to ldap attribute %ldap_attr", $tokens);
528
          $tokens['!row_descriptor'] = $row_descriptor;
529
          $ldap_attribute_maps_in_token = array();
530
          ldap_servers_token_extract_attributes($ldap_attribute_maps_in_token, $mapping['ldap_attr']);
531

    
532
          if ($mapping['direction'] == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
533
            $row_id = $map_index[$mapping['user_attr']];
534
            $to_drupal_user_mappings_exist = TRUE;
535
          //  if (!$is_drupal_user_prov_server) {
536
           //   $errors['mappings__'. $sid] =  t('Mapping rows exist for provisioning to drupal user, but server %sid is not enabled for provisioning
537
            //    to drupal users.', $tokens);
538
          //  }
539
          }
540
          if ($mapping['direction'] == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
541
            $row_id = $map_index[$mapping['ldap_attr']];
542
            $to_ldap_entries_mappings_exist = TRUE;
543
           // if (!$is_ldap_entry_prov_server) {
544
            //  $errors['mappings__'. $sid] =  t('Mapping rows exist for provisioning to ldap entries,
545
            //    but server %sid is not enabled for provisioning
546
             //   to ldap entries.', $tokens);
547
           // }
548

    
549
            if (count(array_keys($ldap_attribute_maps_in_token)) != 1) {
550
              $token_field_id = join('__', array('sm', 'user_tokens', $row_id));
551
              $errors[$token_field_id] =  t('When provisioning to ldap, ldap attribute column must be singular token such as [cn]. %ldap_attr is not.
552
                Do not use compound tokens such as "[displayName] [sn]" or literals such as "physics". Location: !row_descriptor', $tokens);
553
            }
554

    
555
          }
556
          $ldap_attr_field_id = join('__', array('sm', 'ldap_attr', $row_id));
557
          $user_attr_field_id = join('__', array('sm', 'user_attr', $row_id));
558
          $first_context_field_id = join('__', array('sm', 1, $row_id));
559
          $user_tokens_field_id = join('__', array('sm', 'user_tokens', $row_id));
560

    
561
          if (!$mapping['ldap_attr']) {
562
            $errors[$ldap_attr_field_id] =  t('No LDAP Attribute given in !row_descriptor', $tokens);
563
          }
564
          if ($mapping['user_attr'] == 'user_tokens' && !$mapping['user_tokens']) {
565
            $errors[$user_tokens_field_id] =  t('User tokens selected in !row_descriptor, but user tokens column empty.', $tokens);
566
          }
567

    
568
          if (isset($mapping['prov_events']) && count($mapping['prov_events']) == 0) {
569
            $warnings[$first_context_field_id] =  t('No synchronization events checked in !row_descriptor.
570
              This field will not be synchronized until some are checked.', $tokens);
571
          }
572
        }
573
      }
574
      if ($to_ldap_entries_mappings_exist && !isset($mappings['[dn]'])) {
575
        $errors['mappings__' . $synch_direction] =  t('Mapping rows exist for provisioning to ldap, but no ldap attribute is targetted for [dn].
576
          One row must map to [dn].  This row will have a user token like cn=[property.name],ou=users,dc=ldap,dc=mycompany,dc=com');
577
      }
578
    }
579
    return array($errors, $warnings);
580
  }
581

    
582
  /**
583
   * populate object with data from form values
584
   *
585
   * @param array $values as $form_state['values'] from drupal form api
586
   * @param array $storage as $form_state['storage'] from drupal form api
587
   */
588
  protected function populateFromDrupalForm($values, $storage) {
589
    $this->drupalAcctProvisionServer = ($values['drupalAcctProvisionServer'] == 'none') ? 0 : $values['drupalAcctProvisionServer'];
590
    $this->ldapEntryProvisionServer = ($values['ldapEntryProvisionServer']  == 'none') ? 0 : $values['ldapEntryProvisionServer'];
591

    
592
    $this->drupalAcctProvisionTriggers = $values['drupalAcctProvisionTriggers'];
593
    $this->ldapEntryProvisionTriggers = $values['ldapEntryProvisionTriggers'];
594
    $this->orphanedDrupalAcctBehavior = $values['orphanedDrupalAcctBehavior'];
595
    $this->orphanedCheckQty = $values['orphanedCheckQty'];
596

    
597
    $this->manualAccountConflict = $values['manualAccountConflict'];
598
    $this->userConflictResolve  = ($values['userConflictResolve']) ? (int)$values['userConflictResolve'] : NULL;
599
    $this->acctCreation  = ($values['acctCreation']) ? (int)$values['acctCreation'] : NULL;
600
    $this->disableAdminPasswordField = $values['disableAdminPasswordField'];
601
   // $this->wsKey  = ($values['wsKey']) ? $values['wsKey'] : NULL;
602

    
603
   // $this->wsUserIps  = ($values['wsUserIps']) ? explode("\n", $values['wsUserIps']) : array();
604
  //  foreach ($this->wsUserIps as $i => $ip) {
605
  //    $this->wsUserIps[$i] = trim($ip);
606
  //  }
607
   // $this->wsEnabled  = ($values['wsEnabled']) ? (int)$values['wsEnabled'] : 0;
608

    
609
    $this->ldapUserSynchMappings = $this->synchMappingsFromForm($values, $storage);
610

    
611
  }
612

    
613

    
614

    
615
/**
616
 *  Extract synch mappings array from mapping table in admin form.
617
 *
618
 * @param array $values as $form_state['values'] from drupal form api
619
 * @param array $storage as $form_state['storage'] from drupal form api
620
 *
621
 * $values input names in form:
622
 *   1__sm__configurable__5,
623
 *   1__sm__remove__5,
624
 *   1__sm__ldap_attr__5,
625
 *   1__sm__convert__5,
626
 *   1__sm__direction__5,
627
 *   1__sm__user_attr__5,
628
 *   1__sm__user_tokens__5
629
 *   1__sm__1__5,
630
 *   1__sm__2__5,
631
    ...where
632
      -- first arg is direction, eg 1 or 2 LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY
633
      -- second arg is discarded ('sm')
634
      -- third part is field, e.g. user_attr
635
      -- fourth is the row in the configuration form, e.g. 5
636

637
   where additiond data is in $form['#storage'][<direction>]['synch_mapping_fields'][N]
638
    $form['#storage']['synch_mapping_fields'][<direction>][N] = array(
639
      'sid' => $sid,
640
      'action' => 'add',
641
    );
642
 */
643
  private function synchMappingsFromForm($values, $storage) {
644

    
645
    $mappings = array();
646
    foreach ($values as $field => $value) {
647

    
648
      $parts = explode('__', $field);
649
      // since synch mapping fields are in n-tuples, process entire n-tuple at once
650
      if (count($parts) != 4 || $parts[1] !== 'sm') {
651
        continue;
652
      }
653

    
654
      list($direction, $discard, $column_name, $i) = $parts;
655
      $action = $storage['synch_mapping_fields'][$direction][$i]['action'];
656

    
657
      $row_mappings = array();
658
      foreach (array('remove', 'configurable_to_drupal', 'configurable_to_ldap', 'convert', 'ldap_attr', 'user_attr', 'user_tokens') as $column_name) {
659
        $input_name = join('__', array($direction, 'sm', $column_name, $i));
660
        $row_mappings[$column_name] = isset($values[$input_name]) ? $values[$input_name] : NULL;
661
      }
662

    
663
      if ($row_mappings['remove']) {
664
        continue;
665
      }
666

    
667
      $key = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? $row_mappings['user_attr'] : $row_mappings['ldap_attr'];
668
      if ($row_mappings['configurable_to_drupal'] && $row_mappings['ldap_attr'] && $row_mappings['user_attr']) {
669
        $mappings[$direction][$key] = array(
670
          'ldap_attr' => $row_mappings['ldap_attr'],
671
          'user_attr' => $row_mappings['user_attr'],
672
          'convert' => $row_mappings['convert'],
673
          'direction' => $direction,
674
          'user_tokens' => $row_mappings['user_tokens'],
675
          'config_module' => 'ldap_user',
676
          'prov_module' => 'ldap_user',
677
          'enabled' => 1,
678
          );
679

    
680
        $synchEvents = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? $this->provisionsDrupalEvents : $this->provisionsLdapEvents;
681
        foreach ($synchEvents as $prov_event => $discard) {
682
          $input_name = join('__', array($direction, 'sm', $prov_event, $i));
683
          if (isset($values[$input_name]) && $values[$input_name]) {
684
            $mappings[$direction][$key]['prov_events'][] = $prov_event;
685
          }
686
        }
687
      }
688
    }
689

    
690
    return $mappings;
691
  }
692

    
693
  /**
694
   * method to respond to successfully validated form submit.
695
   *
696
   * @param array $values as $form_state['values'] from drupal form api
697
   * @param array $storage as $form_state['storage'] from drupal form api
698
   *
699
   * @return by reference to $form array
700
   */
701
  public function drupalFormSubmit($values, $storage) {
702

    
703
    $this->populateFromDrupalForm($values, $storage);
704

    
705
    try {
706
      $save_result = $this->save();
707
    }
708
    catch (Exception $e) {
709
      $this->errorName = 'Save Error';
710
      $this->errorMsg = t('Failed to save object.  Your form data was not saved.');
711
      $this->hasError = TRUE;
712
    }
713

    
714
  }
715

    
716
  /**
717
   * add existing mappings to ldap user provisioning mapping admin form table
718
   *
719
   * @param drupal form array $form
720
   * @param enum $direction LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY
721
   *
722
   * @return by reference to $form array
723
   */
724

    
725
  private function addServerMappingFields(&$form, $direction) {
726

    
727
    if ($direction == LDAP_USER_PROV_DIRECTION_NONE) {
728
      return;
729
    }
730

    
731
    $text = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? 'target' : 'source';
732
    $user_attr_options = array('0' => t('Select') . ' ' . $text);
733

    
734
    if (!empty($this->synchMapping[$direction])) {
735
      foreach ($this->synchMapping[$direction] as $target_id => $mapping) {
736
        if (!isset($mapping['name']) || isset($mapping['exclude_from_mapping_ui']) && $mapping['exclude_from_mapping_ui']) {
737
          continue;
738
        }
739
        if (
740
          (isset($mapping['configurable_to_drupal']) && $mapping['configurable_to_drupal'] && $direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER)
741
          ||
742
          (isset($mapping['configurable_to_ldap']) && $mapping['configurable_to_ldap']  && $direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY)
743
          ) {
744
          $user_attr_options[$target_id] = substr($mapping['name'], 0, 25);
745
        }
746
      }
747
    }
748
    $user_attr_options['user_tokens'] = '-- user tokens --';
749

    
750
    $row = 0;
751

    
752
    // 1. non configurable mapping rows
753
    foreach ($this->synchMapping[$direction] as $target_id => $mapping) {
754
      if (isset($mapping['exclude_from_mapping_ui']) && $mapping['exclude_from_mapping_ui']) {
755
        continue;
756
      }
757
      if ( !$this->isMappingConfigurable($mapping, 'ldap_user') && ($mapping['direction'] == $direction || $mapping['direction'] == LDAP_USER_PROV_DIRECTION_ALL)) { // is configurable by ldap_user module (not direction to ldap_user)
758
        $this->addSynchFormRow($form, 'nonconfigurable', $direction, $mapping, $user_attr_options, $row);
759
        $row++;
760
      }
761
    }
762

    
763
    // 2. existing configurable mappings rows
764
    if (!empty($this->ldapUserSynchMappings[$direction])) {
765
      foreach ($this->ldapUserSynchMappings[$direction] as $target_attr_token => $mapping) {  // key could be ldap attribute name or user attribute name
766
        if (isset($mapping['enabled']) && $mapping['enabled'] && $this->isMappingConfigurable($this->synchMapping[$direction][$target_attr_token], 'ldap_user')) {
767
          $this->addSynchFormRow($form, 'update', $direction, $mapping, $user_attr_options, $row);
768
          $row++;
769
        }
770
      }
771
    }
772

    
773
    // 3. leave 4 rows for adding more mappings
774
    for ($i=0; $i<4; $i++) {
775
      $this->addSynchFormRow($form, 'add', $direction, NULL, $user_attr_options, $row);
776
      $row++;
777
    }
778

    
779
  }
780

    
781
  /**
782
   * add mapping form row to ldap user provisioning mapping admin form table
783
   *
784
   * @param drupal form array $form
785
   * @param string $action is 'add', 'update', or 'nonconfigurable'
786
   * @param enum $direction LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY
787
   * @param array $mapping is current setting for updates or nonconfigurable items
788
   * @param array $user_attr_options of drupal user target options
789
   * @param int $row is current row in table
790

791
   *
792
   * @return by reference to $form
793
   */
794
  private function addSynchFormRow(&$form, $action, $direction, $mapping, $user_attr_options, $row) {
795

    
796
    $id_prefix = $direction . '__';
797

    
798
    $id = $id_prefix . 'sm__remove__' . $row;
799
    $form[$id] = array(
800
      '#id' => $id,
801
      '#row' => $row,
802
      '#col' => 0,
803
      '#type' => 'checkbox',
804
      '#default_value' => NULL,
805
      '#disabled' => ($action == 'add' || $action == 'nonconfigurable'),
806
    );
807

    
808
    $id =  $id_prefix . 'sm__convert__' . $row;
809
    $form[$id] = array(
810
      '#id' => $id,
811
      '#row' => $row,
812
      '#col' => ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? 2 : 3,
813
      '#type' => 'checkbox',
814
      '#default_value' =>  isset($mapping['convert']) ? $mapping['convert'] : '',
815
      '#disabled' => ($action == 'nonconfigurable'),
816
      '#attributes' => array('class' => array('convert')),
817
    );
818

    
819
    $id =  $id_prefix . 'sm__ldap_attr__' . $row;
820
    $col = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? 1 : 4;
821
    if ($action == 'nonconfigurable') {
822
      $form[$id] = array(
823
        '#id' => $id,
824
        '#row' => $row,
825
        '#col' => $col,
826
        '#type' => 'item',
827
        '#markup' => isset($mapping['source']) ? $mapping['source'] : '?',
828
        '#attributes' => array('class' => array('source')),
829
      );
830
    }
831
    else {
832
      $form[$id] = array(
833
        '#id' => $id,
834
        '#row' => $row,
835
        '#col' => $col,
836
        '#type' => 'textfield',
837
        '#default_value' => isset($mapping['ldap_attr']) ? $mapping['ldap_attr'] : '',
838
        '#size' => 20,
839
        '#maxlength' => 255,
840
        '#attributes' => array('class' => array('ldap-attr')),
841
      );
842
    }
843

    
844
    $user_attr_input_id =  $id_prefix . 'sm__user_attr__' . $row;
845
    $col = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? 3 : 1;
846
    if ($action == 'nonconfigurable') {
847
      $form[$user_attr_input_id] = array(
848
        '#id' => $user_attr_input_id,
849
        '#row' => $row,
850
        '#col' => $col,
851
        '#type' => 'item',
852
        '#markup' => isset($mapping['name']) ? $mapping['name'] : '?',
853
      );
854
    }
855
    else {
856
      $form[$user_attr_input_id] = array(
857
        '#id' => $user_attr_input_id,
858
        '#row' => $row,
859
        '#col' => $col,
860
        '#type' => 'select',
861
        '#default_value' => isset($mapping['user_attr']) ? $mapping['user_attr'] : '',
862
        '#options' => $user_attr_options,
863
      );
864
    }
865

    
866
    if ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
867
      $id =  $id_prefix . 'sm__user_tokens__' . $row;
868
      $form[$id] = array(
869
        '#id' => $id,
870
        '#row' => $row,
871
        '#col' =>  2,
872
        '#type' => 'textfield',
873
        '#default_value' => isset($mapping['user_tokens']) ? $mapping['user_tokens'] : '',
874
        '#size' => 40,
875
        '#maxlength' => 255,
876
        '#disabled' => ($action == 'nonconfigurable'),
877
        '#states' => array(
878
          'visible' => array(   // action to take.
879
            ':input[name="' . $user_attr_input_id . '"]' => array('value' => 'user_tokens'),
880
          )
881
        ),
882
        '#attributes' => array('class' => array('tokens')),
883
      );
884
    }
885

    
886
    $form['#storage']['synch_mapping_fields'][$direction][$row] = array(
887
      'action' => $action,
888
      'direction' => $direction,
889
    );
890

    
891
    $id = $id_prefix . 'sm__configurable_to_drupal__' . $row;
892
    $form[$id] = array(
893
      '#id' => $id,
894
      '#type' => 'hidden',
895
      '#default_value' => ($action != 'nonconfigurable'),
896
    );
897

    
898

    
899
    $col = ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) ? 5 : 4;
900
    $synchEvents = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? $this->provisionsDrupalEvents : $this->provisionsLdapEvents;
901

    
902
    foreach ($synchEvents as $prov_event => $prov_event_name) {
903
      $col++;
904
      $id =  $id_prefix . join('__', array('sm', $prov_event, $row));
905
      $form[$id] = array(
906
        '#id' => $id ,
907
        '#type' => 'checkbox',
908
        '#default_value' => isset($mapping['prov_events']) ? (int)(in_array($prov_event, $mapping['prov_events'])) : '',
909
        '#row' => $row,
910
        '#col' => $col,
911
        '#disabled' => (!$this->provisionEventConfigurable($prov_event, $mapping) || ($action == 'nonconfigurable')),
912
        '#attributes' => array('class' => array('synch-method')),
913
      );
914
    }
915
  }
916

    
917
  /**
918
   * Is a mapping configurable by a given module?
919
   *
920
   * @param array $mapping as mapping configuration for field, attribute, property, etc.
921
   * @param string $module machine name such as ldap_user
922
   *
923
   * @return boolean
924
   */
925
  private function isMappingConfigurable($mapping = NULL, $module = 'ldap_user') {
926
    $configurable = (
927
      (
928
        (!isset($mapping['configurable_to_drupal']) && !isset($mapping['configurable_to_ldap'])) ||
929
        (isset($mapping['configurable_to_drupal']) && $mapping['configurable_to_drupal']) ||
930
        (isset($mapping['configurable_to_ldap']) && $mapping['configurable_to_ldap'])
931
      )
932
      &&
933
      (
934
        !isset($mapping['config_module']) ||
935
        (isset($mapping['config_module']) && $mapping['config_module'] == $module)
936
      )
937
    );
938
    return $configurable;
939
  }
940

    
941

    
942
  /**
943
   * Is a particular synch method viable for a given mapping?
944
   * That is, Can it be enabled in the UI by admins?
945
   *
946
   * @param int $prov_event
947
   * @param array $mapping is array of mapping configuration.
948
   *
949
   * @return boolean
950
   */
951

    
952
  private function provisionEventConfigurable($prov_event, $mapping = NULL) {
953

    
954
    if ($mapping) {
955
      if ($prov_event == LDAP_USER_EVENT_CREATE_LDAP_ENTRY || $prov_event == LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY) {
956
        $configurable = (boolean)(!isset($mapping['configurable_to_ldap']) || $mapping['configurable_to_ldap']);
957
      }
958
      elseif ($prov_event == LDAP_USER_EVENT_CREATE_DRUPAL_USER || $prov_event == LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER) {
959
        $configurable = (boolean)(!isset($mapping['configurable_to_drupal']) || $mapping['configurable_to_drupal']);
960
      }
961
    }
962
    else {
963
      $configurable = TRUE;
964
    }
965

    
966
    return $configurable;
967
  }
968

    
969
  protected function setTranslatableProperties() {
970

    
971
    $values['drupalAcctProvisionServerDescription'] = t('Check ONE LDAP server configuration to use
972
      in provisioning Drupal users and their user fields.');
973
    $values['ldapEntryProvisionServerDescription'] = t('Check ONE LDAP server configuration to create ldap entries on.');
974

    
975
    $values['drupalAccountProvisionEventsDescription'] = t('Which user fields and properties are synched on create or synch is determined in the
976
      "Provisioning from LDAP to Drupal mappings" table below in the right two columns. If you are synching only from LDAP to Drupal, and not 
977
      retrieving the user password from LDAP into their Drupal account, a 20 character random password will be generated automatically for
978
      the user\'s Drupal account since Drupal requires a password for the "users" table. Check the watchdog at /admin/reports/dblog to
979
      confirm that a random password was generated when the user account was created.');
980

    
981
    $values['drupalAccountProvisionEventsOptions'] = array(
982
      LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE => t('Create or Synch to Drupal user on successful authentication with LDAP
983
        credentials. (Requires LDAP Authentication module).'),
984
      LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE => t('Create or Synch to Drupal user anytime a Drupal user account
985
        is created or updated. Requires a server with binding method of "Service Account Bind" or "Anonymous Bind".'),
986
      );
987

    
988
    $values['ldapEntryProvisionTriggersDescription'] = t('Which LDAP attributes are synched on create or synch is determined in the
989
      "Provisioning from Drupal to LDAP mappings" table below in the right two columns.');
990

    
991
    $values['ldapEntryProvisionTriggersOptions'] = array(
992
      LDAP_USER_LDAP_ENTRY_PROV_ON_USER_UPDATE_CREATE => t('Create or Synch to LDAP entry when a Drupal account is created or updated.
993
        Only applied to accounts with a status of approved.'),
994
      LDAP_USER_LDAP_ENTRY_PROV_ON_AUTHENTICATE => t('Create or Synch to LDAP entry when a user authenticates.'),
995
      LDAP_USER_LDAP_ENTRY_DELETE_ON_USER_DELETE => t('Delete LDAP entry when the corresponding Drupal Account is deleted.  This only applies when the LDAP entry was provisioned by Drupal by the LDAP User module.'),
996
      LDAP_USER_DRUPAL_USER_PROV_ON_ALLOW_MANUAL_CREATE => t('Provide option on admin/people/create to create corresponding LDAP Entry.'),
997

    
998
    );
999

    
1000
    $values['orphanedDrupalAcctBehaviorDescription'] = t('It is highly recommended to use the "Perform no action, but email list of orphaned accounts" for some time before considering switching to "Disable the account" options.');
1001

    
1002

    
1003
    $values['manualAccountConflictOptions'] =  array(
1004
      LDAP_USER_MANUAL_ACCT_CONFLICT_REJECT => t('Reject manual creation of Drupal accounts that conflict with LDAP Accounts. This only applies to accounts created on user logon;  Account conflicts can still be generated by manually creating users that conflict with ldap users and these users will have their data synched with LDAP data.'),
1005
      LDAP_USER_MANUAL_ACCT_CONFLICT_LDAP_ASSOCIATE => t('Associate manually created Drupal accounts with related LDAP Account if one exists.'),
1006
      LDAP_USER_MANUAL_ACCT_CONFLICT_SHOW_OPTION_ON_FORM => t('Show option on user create form to determine how account conflict is resolved.'),
1007
    );
1008

    
1009
    /**
1010
    *  Drupal Account Provisioning and Synching
1011
    */
1012
    $values['userConflictResolveDescription'] = t('What should be done if a local Drupal or other external
1013
      user account already exists with the same login name.');
1014
    $values['userConflictOptions'] = array(
1015
      LDAP_USER_CONFLICT_LOG => t('Don\'t associate Drupal account with LDAP.  Require user to use Drupal password. Log the conflict'),
1016
      LDAP_USER_CONFLICT_RESOLVE => t('Associate Drupal account with the LDAP entry.  This option
1017
      is useful for creating accounts and assigning roles before an LDAP user authenticates.'),
1018
      );
1019

    
1020
    $values['acctCreationOptions'] = array(
1021
      LDAP_USER_ACCT_CREATION_LDAP_BEHAVIOR => t('Account creation settings at
1022
        /admin/config/people/accounts/settings do not affect "LDAP Associated" Drupal accounts.'),
1023
      LDAP_USER_ACCT_CREATION_USER_SETTINGS_FOR_LDAP => t('Account creation policy
1024
         at /admin/config/people/accounts/settings applies to both Drupal and LDAP Authenticated users.
1025
         "Visitors" option automatically creates and account when they successfully LDAP authenticate.
1026
         "Admin" and "Admin with approval" do not allow user to authenticate until the account is approved.'),
1027

    
1028
      );
1029

    
1030
      foreach ($values as $property => $default_value) {
1031
        $this->$property = $default_value;
1032
      }
1033
    }
1034

    
1035
}