Projet

Général

Profil

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

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

1 85ad3d82 Assos Assos
<?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 b42754b9 Assos Assos
  public $accountsWithSameEmailDescription;
37
  public $accountsWithSameEmailOptions;
38
39 85ad3d82 Assos Assos
  public $acctCreationDescription = '';
40
  public $acctCreationDefault = LDAP_USER_ACCT_CREATION_LDAP_BEHAVIOR_DEFAULT;
41
  public $acctCreationOptions;
42
43
44
  public $errorMsg = NULL;
45
  public $hasError = FALSE;
46
  public $errorName = NULL;
47
48
  public function clearError() {
49
    $this->hasError = FALSE;
50
    $this->errorMsg = NULL;
51
    $this->errorName = NULL;
52
  }
53
54
  public function save() {
55
    foreach ($this->saveable as $property) {
56
      $save[$property] = $this->{$property};
57
    }
58
    variable_set('ldap_user_conf', $save);
59
    ldap_user_conf_cache_clear();
60
  }
61
62
  static public function uninstall() {
63
    variable_del('ldap_user_conf');
64
  }
65
66
  public function __construct() {
67
    parent::__construct();
68
    $this->setTranslatableProperties();
69
70
    if ($servers = ldap_servers_get_servers(NULL, 'enabled')) {
71
      $this->drupalAcctProvisionServerOptions[LDAP_USER_AUTH_SERVER_SID] = t('Use server which performed the authentication. Useful for multi-domain environments.');
72
      foreach ($servers as $sid => $ldap_server) {
73
        $enabled = ($ldap_server->status) ? 'Enabled' : 'Disabled';
74
        $this->drupalAcctProvisionServerOptions[$sid] = $ldap_server->name . ' (' . $ldap_server->address . ') Status: ' . $enabled;
75
        $this->ldapEntryProvisionServerOptions[$sid] = $ldap_server->name . ' (' . $ldap_server->address . ') Status: ' . $enabled;
76
      }
77
    }
78
    $this->drupalAcctProvisionServerOptions['none'] = t('None');
79
    $this->ldapEntryProvisionServerOptions['none'] = t('None');
80
81
  }
82
83
84
/**
85
 * generate admin form for ldapUserConf object
86
 *
87
 * @return array $form as drupal form api form array
88
 */
89
  public function drupalForm() {
90
    if (count($this->drupalAcctProvisionServerOptions) == 0) {
91
      $message = ldap_servers_no_enabled_servers_msg('configure LDAP User');
92
      $form['intro'] = array(
93
        '#type' => 'item',
94
        '#markup' => t('<h1>LDAP User Settings</h1>') . $message,
95
      );
96
      return $form;
97
    }
98
    $form['#storage'] = array();
99
    $form['#theme'] = 'ldap_user_conf_form';
100
101
    $form['intro'] = array(
102
      '#type' => 'item',
103
      '#markup' => t('<h1>LDAP User Settings</h1>'),
104
    );
105
106
    $form['manual_drupal_account_editing'] = array(
107
      '#type' => 'fieldset',
108
      '#title' => t('Manual Drupal Account Creation and Updates'),
109
      '#collapsible' => TRUE,
110
      '#collapsed' => FALSE,
111
    );
112
113
    $form['manual_drupal_account_editing']['manualAccountConflict'] = array(
114
      '#type' => 'radios',
115
      '#options' => $this->manualAccountConflictOptions,
116
      '#title' => t('How to resolve LDAP conflicts with manually  created Drupal accounts.'),
117
      '#description' => t('This applies only to accounts created manually through admin/people/create
118
        for which an LDAP entry can be found on the LDAP server selected in "LDAP Servers Providing Provisioning Data"'),
119
      '#default_value' => $this->manualAccountConflict,
120
    );
121
122
    $form['basic_to_drupal'] = array(
123
      '#type' => 'fieldset',
124
      '#title' => t('Basic Provisioning to Drupal Account Settings'),
125
      '#collapsible' => TRUE,
126
      '#collapsed' => FALSE,
127
    );
128
129
    $default_value = ($this->drupalAcctProvisionServer) ? $this->drupalAcctProvisionServer : 'none';
130
    $form['basic_to_drupal']['drupalAcctProvisionServer'] = array(
131
      '#type' => 'radios',
132
      '#title' => t('LDAP Servers Providing Provisioning Data'),
133
      '#required' => 1,
134
      '#default_value' => $default_value,
135
      '#options' => $this->drupalAcctProvisionServerOptions,
136
      '#description' => $this->drupalAcctProvisionServerDescription,
137
      '#states' => array(
138
        'enabled' => array(   // action to take.
139
          ':input[name=drupalAcctProvisionTriggers]' => array('value' => LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE),
140
        ),
141
      ),
142
    );
143
144
145
    $form['basic_to_drupal']['drupalAcctProvisionTriggers'] = array(
146
      '#type' => 'checkboxes',
147
      '#title' => t('Drupal Account Provisioning Events'),
148
      '#required' => FALSE,
149
      '#default_value' => $this->drupalAcctProvisionTriggers,
150
      '#options' => $this->drupalAccountProvisionEventsOptions,
151
      '#description' => $this->drupalAccountProvisionEventsDescription,
152
    );
153
154
    $form['basic_to_drupal']['disableAdminPasswordField'] = array(
155
      '#type' => 'checkbox',
156
      '#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.'),
157
      '#default_value' => $this->disableAdminPasswordField,
158
    );
159
160
    $form['basic_to_drupal']['userConflictResolve'] = array(
161
      '#type' => 'radios',
162
      '#title' => t('Existing Drupal User Account Conflict'),
163
      '#required' => 1,
164
      '#default_value' => $this->userConflictResolve,
165
      '#options' => $this->userConflictOptions,
166
      '#description' => t( $this->userConflictResolveDescription),
167
    );
168
169 b42754b9 Assos Assos
    $form['basic_to_drupal']['accountsWithSameEmail'] = array(
170
      '#type' => 'radios',
171
      '#title' => t('Existing Account with Same Email Address'),
172
      '#default_value' => $this->accountsWithSameEmail,
173
      '#options' => $this->accountsWithSameEmailOptions,
174
      '#description' => t($this->accountsWithSameEmailDescription),
175
      '#disabled' => (module_exists('sharedemail') === FALSE),
176
    );
177
178 85ad3d82 Assos Assos
    $form['basic_to_drupal']['acctCreation'] = array(
179
      '#type' => 'radios',
180
      '#title' => t('Application of Drupal Account settings to LDAP Authenticated Users'),
181
      '#required' => 1,
182
      '#default_value' => $this->acctCreation,
183
      '#options' => $this->acctCreationOptions,
184
      '#description' => t($this->acctCreationDescription),
185
    );
186
187
    $account_options = array();
188
    $account_options['ldap_user_orphan_do_not_check'] = t('Do not check for orphaned Drupal accounts.');
189
    $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.)');
190
    foreach (user_cancel_methods() as $option_name => $option) {
191
      $account_options[$option_name] = $option['#title'];
192
    }
193
194
    //@todo these 2 options are removed until this feature is better tested in
195
    // actual production environments; it has potentially disastrous effects
196
    unset($account_options['user_cancel_reassign']);
197
    unset($account_options['user_cancel_delete']);
198
199
    $form['basic_to_drupal']['orphanedDrupalAcctBehavior'] = array(
200
      '#type' => 'radios',
201
      '#title' => t('Action to perform on Drupal account that no longer have a
202
        corresponding LDAP entry'),
203
      '#required' => 0,
204
      '#default_value' => $this->orphanedDrupalAcctBehavior,
205
      '#options' => $account_options,
206
      '#description' => t($this->orphanedDrupalAcctBehaviorDescription),
207
    );
208
209
210
    $form['basic_to_drupal']['orphanedCheckQty'] = array(
211
      '#type' => 'textfield',
212
      '#size' => 10,
213
      '#title' => t('Number of users to check each cron run.'),
214
      '#description' => t(''),
215
      '#default_value' => $this->orphanedCheckQty,
216
      '#required' => FALSE,
217
    );
218
219
220
    $form['basic_to_ldap'] = array(
221
      '#type' => 'fieldset',
222
      '#title' => t('Basic Provisioning to LDAP Settings'),
223
      '#collapsible' => TRUE,
224
      '#collapsed' => !($this->ldapEntryProvisionServer),
225
    );
226
227
    $default_value = ($this->ldapEntryProvisionServer) ? $this->ldapEntryProvisionServer : 'none';
228
    $form['basic_to_ldap']['ldapEntryProvisionServer'] = array(
229
      '#type' => 'radios',
230
      '#title' => t('LDAP Servers to Provision LDAP Entries on'),
231
      '#required' => 1,
232
      '#default_value' => $default_value,
233
      '#options' => $this->ldapEntryProvisionServerOptions,
234
      '#description' => $this->ldapEntryProvisionServerDescription,
235
    );
236
237
    $form['basic_to_ldap']['ldapEntryProvisionTriggers'] = array(
238
      '#type' => 'checkboxes',
239
      '#title' => t('LDAP Entry Provisioning Events'),
240
      '#required' => FALSE,
241
      '#default_value' => $this->ldapEntryProvisionTriggers,
242
      '#options' => $this->ldapEntryProvisionTriggersOptions,
243
      '#description' => $this->ldapEntryProvisionTriggersDescription
244
    );
245
246
/**
247
    $form['ws'] = array(
248
      '#type' => 'fieldset',
249
      '#title' => t('[Untested and Unfinished Code] REST Webservice for Provisioning and Synching.'),
250
      '#collapsible' => TRUE,
251
      '#collapsed' => !$this->wsEnabled,
252
      '#description' => t('Once configured, this webservice can be used to trigger creation, synching, deletion, etc of an LDAP associated Drupal account.'),
253
    );
254

255
    $form['ws']['wsEnabled'] = array(
256
      '#type' => 'checkbox',
257
      '#title' => t('Enable REST Webservice'),
258
      '#required' => FALSE,
259
      '#default_value' => $this->wsEnabled,
260
    );
261

262
    $form['ws']['wsUserIps'] = array(
263
      '#type' => 'textarea',
264
      '#title' => t('Allowed IP Addresses to request webservice.'),
265
      '#required' => FALSE,
266
      '#default_value' => join("\n", $this->wsUserIps),
267
      '#description' => t('One Per Line. The current server address is LOCAL_ADDR and the client ip requesting this page is REMOTE_ADDR .', $_SERVER),
268
      '#cols' => 20,
269
      '#rows' => 2,
270
      '#states' => array(
271
        'visible' => array(   // action to take.
272
          ':input[name="wsEnabled"]' => array('checked' => TRUE),
273
        ),
274
      ),
275
    );
276

277
    if (!$this->wsKey) {
278
      $urls = t('URLs are not available until a key is create a key and urls will be generated');
279
    }
280
    else {
281
      $urls = theme('item_list',
282
        array(
283
          'items' => ldap_user_ws_urls_item_list(),
284
          'title' => 'REST urls',
285
          'type' => 'ul',
286
        ));
287
    }
288

289
    $form['ws']['wsKey'] = array(
290
      '#type' => 'textfield',
291
      '#title' => t('Key for webservice'),
292
      '#required' => FALSE,
293
      '#default_value' => $this->wsKey,
294
      '#description' => t('Any random string of characters.') . $urls,
295
      '#states' => array(
296
        'visible' => array(   // action to take.
297
          ':input[name="wsEnabled"]' => array('checked' => TRUE),
298
        ),
299
      ),
300
    );
301
*/
302
303 5136ce55 Assos Assos
    $form['basic_to_drupal']['server_mapping_preamble'] = array(
304 85ad3d82 Assos Assos
      '#type' => 'markup',
305
      '#markup' => t('
306
The relationship between a Drupal user and an LDAP entry is defined within the LDAP server configurations.
307

308

309
The mappings below are for user fields, properties, and profile2 data that are not automatically mapped elsewhere.
310
Mappings such as username or email address that are configured elsewhere are shown at the top for clarity.
311
When more than one ldap server is enabled for provisioning data (or simply more than one configuration for the same ldap server),
312
mappings need to be setup for each server.  If no tables are listed below, you have not enabled any provisioning servers at
313
the top of this form.
314
'),
315
    );
316
317
    foreach (array(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) as $direction) {
318
      $sid = $this->provisionSidFromDirection[$direction];
319
      $ldap_server = ($sid) ? ldap_servers_get_servers($sid, NULL, TRUE) : FALSE;
320
      $ldap_server_selected = (boolean)$ldap_server;
321
322
      if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
323
        $parent_fieldset = 'basic_to_drupal';
324 bc175c27 Assos Assos
        $description = t('Provisioning from LDAP to Drupal Mappings:');
325 85ad3d82 Assos Assos
      }
326
      elseif ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
327
        $parent_fieldset = 'basic_to_ldap';
328 bc175c27 Assos Assos
        $description = t('Provisioning from Drupal to LDAP Mappings:');
329 85ad3d82 Assos Assos
      }
330
331
      $form[$parent_fieldset]['mappings__' . $direction] = array(
332
        '#type' => 'fieldset',
333 bc175c27 Assos Assos
        '#title' => $description,
334 85ad3d82 Assos Assos
        '#collapsible' => TRUE,
335
        '#collapsed' => FALSE,
336
        '#description' => '',
337
        'table__' . $direction => array(
338
          '#type' => 'markup',
339
          '#markup' => '[replace_with_table__' . $direction . ']',
340
        ),
341
      );
342
343
344
$password_notes = '<h3>' . t('Password Tokens') . '</h3><ul>' .
345
'<li>' . t('Pwd: Random -- Uses a random Drupal generated password') . '</li>' .
346
'<li>' . t('Pwd: User or Random -- Uses password supplied on user forms.
347
  If none available uses random password.') . '</li></ul>' .
348
'<h3>' . t('Password Concerns') . '</h3>' .
349
'<ul>' .
350
'<li>' . t('Provisioning passwords to LDAP means passwords must meet the LDAP\'s
351
password requirements.  Password Policy module can be used to add requirements.') . '</li>' .
352
'<li>' . t('Some LDAPs require a user to reset their password if it has been changed
353
by someone other that user.  Consider this when provisioning LDAP passwords.') . '</li>' .
354
'</ul></p>';
355
356
357
      $source_drupal_token_notes = <<<EOT
358
<p>Examples in form: Source Drupal User token => Target LDAP Token (notes)</p>
359
<ul>
360
<li>Source Drupal User token => Target LDAP Token</li>
361
<li>cn=[property.name],ou=test,dc=ad,dc=mycollege,dc=edu => [dn] (example of token and constants)</li>
362
<li>top => [objectclass:0] (example of constants mapped to multivalued attribute)</li>
363
<li>person => [objectclass:1] (example of constants mapped to multivalued attribute)</li>
364
<li>organizationalPerson => [objectclass:2] (example of constants mapped to multivalued attribute)</li>
365
<li>user => [objectclass:3] (example of constants mapped to multivalued attribute)</li>
366
<li>Drupal Provisioned LDAP Account => [description] (example of constant)</li>
367
<li>[field.field_lname] => [sn]</li>
368

369
</ul>
370
EOT;
371
372
      if ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) { // add some password notes
373
        $form[$parent_fieldset]['password_notes'] = array(
374
          '#type' => 'fieldset',
375 bc175c27 Assos Assos
          '#title' => t('Password Notes'),
376 85ad3d82 Assos Assos
          '#collapsible' => TRUE,
377
          '#collapsed' => TRUE,
378
          'directions' => array(
379
            '#type' => 'markup',
380
            '#markup' => $password_notes,
381
          ),
382
        );
383
        $form[$parent_fieldset]['source_drupal_token_notes'] = array(
384
          '#type' => 'fieldset',
385 bc175c27 Assos Assos
          '#title' => t('Source Drupal User Tokens and Corresponding Target LDAP Tokens'),
386 85ad3d82 Assos Assos
          '#collapsible' => TRUE,
387
          '#collapsed' => TRUE,
388
          'directions' => array(
389
            '#type' => 'markup',
390
            '#markup' => $source_drupal_token_notes,
391
          ),
392
        );
393
      }
394
      $this->addServerMappingFields($form, $direction);
395
    }
396
397 b42754b9 Assos Assos
    foreach (array('orphanedCheckQty', 'orphanedDrupalAcctBehavior', 'acctCreation', 'userConflictResolve', 'accountsWithSameEmail', 'drupalAcctProvisionTriggers', 'mappings__' . LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) as $input_name) {
398 85ad3d82 Assos Assos
      $form['basic_to_drupal'][$input_name]['#states']['invisible'] =
399
        array(
400
          ':input[name=drupalAcctProvisionServer]' => array('value' => 'none'),
401
        );
402
    }
403
404
    foreach (array('ldapEntryProvisionTriggers', 'password_notes', 'source_drupal_token_notes', 'mappings__' . LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) as $input_name) {
405
      $form['basic_to_ldap'][$input_name]['#states']['invisible'] =
406
        array(
407
          ':input[name=ldapEntryProvisionServer]' => array('value' => 'none'),
408
        );
409
    }
410
411
    $form['submit'] = array(
412
      '#type' => 'submit',
413
      '#value' => 'Save',
414
    );
415
416
  return $form;
417
}
418
419 bc175c27 Assos Assos
  /**
420
   * @param $sid
421
   * @param $orphan_handling
422
   */
423
  private function checkPuidOrphans($sid, $orphan_handling) {
424
    $ldap_server = ldap_servers_get_servers($sid, NULL, TRUE);
425
    if ($ldap_server && empty($ldap_server->unique_persistent_attr)
426
      && $orphan_handling != 'ldap_user_orphan_do_not_check') {
427
      drupal_set_message(t('You\'ve configured the orphan check but are missing the required persistent user ID property.'), 'error');
428
    }
429
  }
430 85ad3d82 Assos Assos
431
/**
432
 * validate submitted form
433
 *
434
 * @param array $values as $form_state['values'] from drupal form api
435
 * @param array $storage as $form_state['storage'] from drupal form api
436
 *
437
 * @return array in form array($errors, $warnings)to be thrown by form api
438
 */
439
  public function drupalFormValidate($values, $storage)  {
440
    $this->populateFromDrupalForm($values, $storage);
441
    list($errors, $warnings) = $this->validate($values);
442
443 bc175c27 Assos Assos
    $this->checkPuidOrphans($values['drupalAcctProvisionServer'], $values['orphanedDrupalAcctBehavior']);
444
445 85ad3d82 Assos Assos
    // since failed mapping rows in form, don't populate ->ldapUserSynchMappings, need to validate these from values
446
    foreach ($values as $field => $value) {
447
      $parts = explode('__', $field);
448
      // since synch mapping fields are in n-tuples, process entire n-tuple at once (on field == configurable_to_drupal)
449
      if (count($parts) != 4 || $parts[1] !== 'sm' || $parts[2] != 'configurable_to_drupal') {
450
        continue;
451
      }
452
      list($direction, $discard, $column_name, $i) = $parts;
453
      $action = $storage['synch_mapping_fields'][$direction][$i]['action'];
454
      $tokens = array();
455
      $row_mappings = array();
456
      foreach (array('remove', 'configurable_to_drupal', 'configurable_to_ldap', 'convert', 'direction', 'ldap_attr', 'user_attr', 'user_tokens') as $column_name) {
457
        $input_name = join('__', array('sm', $column_name, $i));
458
        $row_mappings[$column_name] = isset($values[$input_name]) ? $values[$input_name] : NULL;
459
      }
460
461
      $has_values = $row_mappings['ldap_attr'] || $row_mappings['user_attr'];
462
      if ($has_values) {
463
        $tokens['%ldap_attr'] = $row_mappings['ldap_attr'];
464
        $row_descriptor = t("server %sid row mapping to ldap attribute %ldap_attr", $tokens);
465
        $tokens['!row_descriptor'] = $row_descriptor;
466
        if (!$row_mappings['direction']) {
467
          $input_name = join('__', array('sm', 'direction', $i));
468
          $errors[$input_name] = t('No mapping direction given in !row_descriptor', $tokens);
469
        }
470
        if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER && $row_mappings['user_attr'] == 'user_tokens') {
471
          $input_name = join('__', array('sm', 'user_attr', $i));
472 bc175c27 Assos Assos
          $errors[$input_name] = t('User tokens not allowed when mapping to Drupal user.  Location: !row_descriptor', $tokens);
473 85ad3d82 Assos Assos
        }
474
        if (!$row_mappings['ldap_attr']) {
475
          $input_name = join('__', array('sm', 'ldap_attr', $i));
476
          $errors[$input_name] = t('No ldap attribute given in !row_descriptor', $tokens);
477
        }
478
        if (!$row_mappings['user_attr']) {
479
          $input_name = join('__', array('sm', 'user_attr', $i));
480
          $errors[$input_name] = t('No user attribute given in !row_descriptor', $tokens);
481
        }
482
      }
483
484
    }
485
    return array($errors, $warnings);
486
  }
487
488
/**
489
 * validate object, not form
490
 * @param array $values as $form_state['values'] from drupal form api
491
 * @return array in form array($errors, $warnings)to be thrown by form api
492
 *
493
 * @todo validate that a user field exists, such as field.field_user_lname
494
 *
495
 */
496
  public function validate($values) {
497
    $errors = array();
498
    $warnings = array();
499
    $tokens = array();
500
501
    $has_drupal_acct_prov_servers  = (boolean)($this->drupalAcctProvisionServer);
502
    $has_drupal_acct_prov_settings_options  = (count(array_filter($this->drupalAcctProvisionTriggers)) > 0);
503
504
    if (!$has_drupal_acct_prov_servers && $has_drupal_acct_prov_settings_options) {
505 bc175c27 Assos Assos
      $warnings['drupalAcctProvisionServer'] = t('No Servers are enabled to provide provisioning to Drupal, but Drupal Account Provisioning Options are selected.', $tokens);
506 85ad3d82 Assos Assos
    }
507
    if ($has_drupal_acct_prov_servers && !$has_drupal_acct_prov_settings_options) {
508 bc175c27 Assos Assos
      $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);
509 85ad3d82 Assos Assos
    }
510
511
    $has_ldap_prov_servers = (boolean)($this->ldapEntryProvisionServer);
512
    $has_ldap_prov_settings_options = (count(array_filter($this->ldapEntryProvisionTriggers)) > 0);
513
    if (!$has_ldap_prov_servers && $has_ldap_prov_settings_options) {
514 bc175c27 Assos Assos
      $warnings['ldapEntryProvisionServer'] = t('No Servers are enabled to provide provisioning to ldap, but LDAP Entry Options are selected.', $tokens);
515 85ad3d82 Assos Assos
    }
516
    if ($has_ldap_prov_servers && !$has_ldap_prov_settings_options) {
517 bc175c27 Assos Assos
      $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);
518 85ad3d82 Assos Assos
    }
519
520
    if (isset($this->ldapUserSynchMappings)) {
521
      $to_ldap_entries_mappings_exist = FALSE;
522
      foreach ($this->ldapUserSynchMappings as $synch_direction => $mappings) {
523
        $map_index = array();
524
        $tokens = array(); // array('%sid' => $sid);
525
        $to_drupal_user_mappings_exist = FALSE;
526
        $to_ldap_entries_mappings_exist = FALSE;
527
528
        foreach ($mappings as $target_attr => $mapping) {
529
          if ($mapping['direction'] == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
530
            $attr_value = $mapping['user_attr'];
531
            $attr_name = 'user_attr';
532
          }
533
          if ($mapping['direction'] == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
534
            $attr_value = $mapping['ldap_attr'];
535
            $attr_name = 'ldap_attr';
536
          }
537
          foreach ($values as $field => $value) {
538
            $parts = explode('__', $field);
539
            if (count($parts) == 4 && $parts[2] == $attr_name && $value == $attr_value) {
540
              $map_index[$attr_value] = $parts[3];
541
            }
542
          }
543
        }
544
545
        foreach ($mappings as $target_attr => $mapping) {
546
          foreach ($mapping as $key => $value) {
547
            if (is_scalar($value)) {
548
              $tokens['%' . $key] = $value;
549
            }
550
          }
551
          $row_descriptor = t("server %sid row mapping to ldap attribute %ldap_attr", $tokens);
552
          $tokens['!row_descriptor'] = $row_descriptor;
553
          $ldap_attribute_maps_in_token = array();
554
          ldap_servers_token_extract_attributes($ldap_attribute_maps_in_token, $mapping['ldap_attr']);
555
556
          if ($mapping['direction'] == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
557
            $row_id = $map_index[$mapping['user_attr']];
558
            $to_drupal_user_mappings_exist = TRUE;
559
          //  if (!$is_drupal_user_prov_server) {
560
           //   $errors['mappings__'. $sid] =  t('Mapping rows exist for provisioning to drupal user, but server %sid is not enabled for provisioning
561
            //    to drupal users.', $tokens);
562
          //  }
563
          }
564
          if ($mapping['direction'] == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
565
            $row_id = $map_index[$mapping['ldap_attr']];
566
            $to_ldap_entries_mappings_exist = TRUE;
567
           // if (!$is_ldap_entry_prov_server) {
568
            //  $errors['mappings__'. $sid] =  t('Mapping rows exist for provisioning to ldap entries,
569
            //    but server %sid is not enabled for provisioning
570
             //   to ldap entries.', $tokens);
571
           // }
572
573
            if (count(array_keys($ldap_attribute_maps_in_token)) != 1) {
574
              $token_field_id = join('__', array('sm', 'user_tokens', $row_id));
575 bc175c27 Assos Assos
              $errors[$token_field_id] = t('When provisioning to ldap, ldap attribute column must be singular token such as [cn]. %ldap_attr is not.
576 85ad3d82 Assos Assos
                Do not use compound tokens such as "[displayName] [sn]" or literals such as "physics". Location: !row_descriptor', $tokens);
577
            }
578
579
          }
580
          $ldap_attr_field_id = join('__', array('sm', 'ldap_attr', $row_id));
581
          $user_attr_field_id = join('__', array('sm', 'user_attr', $row_id));
582
          $first_context_field_id = join('__', array('sm', 1, $row_id));
583
          $user_tokens_field_id = join('__', array('sm', 'user_tokens', $row_id));
584
585
          if (!$mapping['ldap_attr']) {
586 bc175c27 Assos Assos
            $errors[$ldap_attr_field_id] = t('No LDAP Attribute given in !row_descriptor', $tokens);
587 85ad3d82 Assos Assos
          }
588
          if ($mapping['user_attr'] == 'user_tokens' && !$mapping['user_tokens']) {
589 bc175c27 Assos Assos
            $errors[$user_tokens_field_id] = t('User tokens selected in !row_descriptor, but user tokens column empty.', $tokens);
590 85ad3d82 Assos Assos
          }
591
592
          if (isset($mapping['prov_events']) && count($mapping['prov_events']) == 0) {
593 bc175c27 Assos Assos
            $warnings[$first_context_field_id] = t('No synchronization events checked in !row_descriptor.
594 85ad3d82 Assos Assos
              This field will not be synchronized until some are checked.', $tokens);
595
          }
596
        }
597
      }
598
      if ($to_ldap_entries_mappings_exist && !isset($mappings['[dn]'])) {
599 bc175c27 Assos Assos
        $errors['mappings__' . $synch_direction] = t('Mapping rows exist for provisioning to ldap, but no ldap attribute is targetted for [dn].
600 85ad3d82 Assos Assos
          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');
601
      }
602
    }
603
    return array($errors, $warnings);
604
  }
605
606
  /**
607
   * populate object with data from form values
608
   *
609
   * @param array $values as $form_state['values'] from drupal form api
610
   * @param array $storage as $form_state['storage'] from drupal form api
611
   */
612
  protected function populateFromDrupalForm($values, $storage) {
613
    $this->drupalAcctProvisionServer = ($values['drupalAcctProvisionServer'] == 'none') ? 0 : $values['drupalAcctProvisionServer'];
614 bc175c27 Assos Assos
    $this->ldapEntryProvisionServer = ($values['ldapEntryProvisionServer'] == 'none') ? 0 : $values['ldapEntryProvisionServer'];
615 85ad3d82 Assos Assos
616
    $this->drupalAcctProvisionTriggers = $values['drupalAcctProvisionTriggers'];
617
    $this->ldapEntryProvisionTriggers = $values['ldapEntryProvisionTriggers'];
618
    $this->orphanedDrupalAcctBehavior = $values['orphanedDrupalAcctBehavior'];
619
    $this->orphanedCheckQty = $values['orphanedCheckQty'];
620
621
    $this->manualAccountConflict = $values['manualAccountConflict'];
622
    $this->userConflictResolve  = ($values['userConflictResolve']) ? (int)$values['userConflictResolve'] : NULL;
623 b42754b9 Assos Assos
    $this->accountsWithSameEmail = ($values['accountsWithSameEmail']) ? (int)$values['accountsWithSameEmail'] : NULL;
624 85ad3d82 Assos Assos
    $this->acctCreation  = ($values['acctCreation']) ? (int)$values['acctCreation'] : NULL;
625
    $this->disableAdminPasswordField = $values['disableAdminPasswordField'];
626
   // $this->wsKey  = ($values['wsKey']) ? $values['wsKey'] : NULL;
627
628
   // $this->wsUserIps  = ($values['wsUserIps']) ? explode("\n", $values['wsUserIps']) : array();
629
  //  foreach ($this->wsUserIps as $i => $ip) {
630
  //    $this->wsUserIps[$i] = trim($ip);
631
  //  }
632
   // $this->wsEnabled  = ($values['wsEnabled']) ? (int)$values['wsEnabled'] : 0;
633
634
    $this->ldapUserSynchMappings = $this->synchMappingsFromForm($values, $storage);
635
636
  }
637
638
639
640
/**
641
 *  Extract synch mappings array from mapping table in admin form.
642
 *
643
 * @param array $values as $form_state['values'] from drupal form api
644
 * @param array $storage as $form_state['storage'] from drupal form api
645
 *
646
 * $values input names in form:
647
 *   1__sm__configurable__5,
648
 *   1__sm__remove__5,
649
 *   1__sm__ldap_attr__5,
650
 *   1__sm__convert__5,
651
 *   1__sm__direction__5,
652
 *   1__sm__user_attr__5,
653
 *   1__sm__user_tokens__5
654
 *   1__sm__1__5,
655
 *   1__sm__2__5,
656
    ...where
657
      -- first arg is direction, eg 1 or 2 LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY
658
      -- second arg is discarded ('sm')
659
      -- third part is field, e.g. user_attr
660
      -- fourth is the row in the configuration form, e.g. 5
661

662
   where additiond data is in $form['#storage'][<direction>]['synch_mapping_fields'][N]
663
    $form['#storage']['synch_mapping_fields'][<direction>][N] = array(
664
      'sid' => $sid,
665
      'action' => 'add',
666
    );
667
 */
668
  private function synchMappingsFromForm($values, $storage) {
669
670
    $mappings = array();
671
    foreach ($values as $field => $value) {
672
673
      $parts = explode('__', $field);
674
      // since synch mapping fields are in n-tuples, process entire n-tuple at once
675
      if (count($parts) != 4 || $parts[1] !== 'sm') {
676
        continue;
677
      }
678
679
      list($direction, $discard, $column_name, $i) = $parts;
680
      $action = $storage['synch_mapping_fields'][$direction][$i]['action'];
681
682
      $row_mappings = array();
683
      foreach (array('remove', 'configurable_to_drupal', 'configurable_to_ldap', 'convert', 'ldap_attr', 'user_attr', 'user_tokens') as $column_name) {
684
        $input_name = join('__', array($direction, 'sm', $column_name, $i));
685
        $row_mappings[$column_name] = isset($values[$input_name]) ? $values[$input_name] : NULL;
686
      }
687
688
      if ($row_mappings['remove']) {
689
        continue;
690
      }
691
692
      $key = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? $row_mappings['user_attr'] : $row_mappings['ldap_attr'];
693
      if ($row_mappings['configurable_to_drupal'] && $row_mappings['ldap_attr'] && $row_mappings['user_attr']) {
694
        $mappings[$direction][$key] = array(
695
          'ldap_attr' => $row_mappings['ldap_attr'],
696
          'user_attr' => $row_mappings['user_attr'],
697
          'convert' => $row_mappings['convert'],
698
          'direction' => $direction,
699
          'user_tokens' => $row_mappings['user_tokens'],
700
          'config_module' => 'ldap_user',
701
          'prov_module' => 'ldap_user',
702
          'enabled' => 1,
703
          );
704
705
        $synchEvents = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? $this->provisionsDrupalEvents : $this->provisionsLdapEvents;
706
        foreach ($synchEvents as $prov_event => $discard) {
707
          $input_name = join('__', array($direction, 'sm', $prov_event, $i));
708
          if (isset($values[$input_name]) && $values[$input_name]) {
709
            $mappings[$direction][$key]['prov_events'][] = $prov_event;
710
          }
711
        }
712
      }
713
    }
714
715
    return $mappings;
716
  }
717
718
  /**
719
   * method to respond to successfully validated form submit.
720
   *
721
   * @param array $values as $form_state['values'] from drupal form api
722
   * @param array $storage as $form_state['storage'] from drupal form api
723
   *
724
   * @return by reference to $form array
725
   */
726
  public function drupalFormSubmit($values, $storage) {
727
728
    $this->populateFromDrupalForm($values, $storage);
729
730
    try {
731
      $save_result = $this->save();
732
    }
733
    catch (Exception $e) {
734
      $this->errorName = 'Save Error';
735
      $this->errorMsg = t('Failed to save object.  Your form data was not saved.');
736
      $this->hasError = TRUE;
737
    }
738
739
  }
740
741
  /**
742
   * add existing mappings to ldap user provisioning mapping admin form table
743
   *
744
   * @param drupal form array $form
745
   * @param enum $direction LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY
746
   *
747
   * @return by reference to $form array
748
   */
749
750
  private function addServerMappingFields(&$form, $direction) {
751
752
    if ($direction == LDAP_USER_PROV_DIRECTION_NONE) {
753
      return;
754
    }
755
756
    $text = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? 'target' : 'source';
757
    $user_attr_options = array('0' => t('Select') . ' ' . $text);
758
759
    if (!empty($this->synchMapping[$direction])) {
760
      foreach ($this->synchMapping[$direction] as $target_id => $mapping) {
761
        if (!isset($mapping['name']) || isset($mapping['exclude_from_mapping_ui']) && $mapping['exclude_from_mapping_ui']) {
762
          continue;
763
        }
764
        if (
765
          (isset($mapping['configurable_to_drupal']) && $mapping['configurable_to_drupal'] && $direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER)
766
          ||
767
          (isset($mapping['configurable_to_ldap']) && $mapping['configurable_to_ldap']  && $direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY)
768
          ) {
769 b42754b9 Assos Assos
          $user_attr_options[$target_id] = substr($target_id, 1, -1);
770 85ad3d82 Assos Assos
        }
771
      }
772
    }
773 b42754b9 Assos Assos
774
    if ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
775
      $user_attr_options['user_tokens'] = '-- user tokens --';
776
    }
777 85ad3d82 Assos Assos
778
    $row = 0;
779
780
    // 1. non configurable mapping rows
781
    foreach ($this->synchMapping[$direction] as $target_id => $mapping) {
782
      if (isset($mapping['exclude_from_mapping_ui']) && $mapping['exclude_from_mapping_ui']) {
783
        continue;
784
      }
785
      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)
786
        $this->addSynchFormRow($form, 'nonconfigurable', $direction, $mapping, $user_attr_options, $row);
787
        $row++;
788
      }
789
    }
790
791
    // 2. existing configurable mappings rows
792
    if (!empty($this->ldapUserSynchMappings[$direction])) {
793
      foreach ($this->ldapUserSynchMappings[$direction] as $target_attr_token => $mapping) {  // key could be ldap attribute name or user attribute name
794
        if (isset($mapping['enabled']) && $mapping['enabled'] && $this->isMappingConfigurable($this->synchMapping[$direction][$target_attr_token], 'ldap_user')) {
795
          $this->addSynchFormRow($form, 'update', $direction, $mapping, $user_attr_options, $row);
796
          $row++;
797
        }
798
      }
799
    }
800
801
    // 3. leave 4 rows for adding more mappings
802 bc175c27 Assos Assos
    for ($i = 0; $i < 4; $i++) {
803 85ad3d82 Assos Assos
      $this->addSynchFormRow($form, 'add', $direction, NULL, $user_attr_options, $row);
804
      $row++;
805
    }
806
807
  }
808
809
  /**
810
   * add mapping form row to ldap user provisioning mapping admin form table
811
   *
812
   * @param drupal form array $form
813
   * @param string $action is 'add', 'update', or 'nonconfigurable'
814
   * @param enum $direction LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY
815
   * @param array $mapping is current setting for updates or nonconfigurable items
816
   * @param array $user_attr_options of drupal user target options
817
   * @param int $row is current row in table
818

819
   *
820
   * @return by reference to $form
821
   */
822
  private function addSynchFormRow(&$form, $action, $direction, $mapping, $user_attr_options, $row) {
823
824
    $id_prefix = $direction . '__';
825
826
    $id = $id_prefix . 'sm__remove__' . $row;
827
    $form[$id] = array(
828
      '#id' => $id,
829
      '#row' => $row,
830
      '#col' => 0,
831
      '#type' => 'checkbox',
832
      '#default_value' => NULL,
833
      '#disabled' => ($action == 'add' || $action == 'nonconfigurable'),
834
    );
835
836 bc175c27 Assos Assos
    $id = $id_prefix . 'sm__convert__' . $row;
837 85ad3d82 Assos Assos
    $form[$id] = array(
838
      '#id' => $id,
839
      '#row' => $row,
840
      '#col' => ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? 2 : 3,
841
      '#type' => 'checkbox',
842 bc175c27 Assos Assos
      '#default_value' => isset($mapping['convert']) ? $mapping['convert'] : '',
843 85ad3d82 Assos Assos
      '#disabled' => ($action == 'nonconfigurable'),
844
      '#attributes' => array('class' => array('convert')),
845
    );
846
847 bc175c27 Assos Assos
    $id = $id_prefix . 'sm__ldap_attr__' . $row;
848 85ad3d82 Assos Assos
    $col = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? 1 : 4;
849
    if ($action == 'nonconfigurable') {
850
      $form[$id] = array(
851
        '#id' => $id,
852
        '#row' => $row,
853
        '#col' => $col,
854
        '#type' => 'item',
855
        '#markup' => isset($mapping['source']) ? $mapping['source'] : '?',
856
        '#attributes' => array('class' => array('source')),
857
      );
858
    }
859
    else {
860
      $form[$id] = array(
861
        '#id' => $id,
862
        '#row' => $row,
863
        '#col' => $col,
864
        '#type' => 'textfield',
865
        '#default_value' => isset($mapping['ldap_attr']) ? $mapping['ldap_attr'] : '',
866
        '#size' => 20,
867
        '#maxlength' => 255,
868
        '#attributes' => array('class' => array('ldap-attr')),
869
      );
870
    }
871
872 bc175c27 Assos Assos
    $user_attr_input_id = $id_prefix . 'sm__user_attr__' . $row;
873 85ad3d82 Assos Assos
    $col = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? 3 : 1;
874
    if ($action == 'nonconfigurable') {
875
      $form[$user_attr_input_id] = array(
876
        '#id' => $user_attr_input_id,
877
        '#row' => $row,
878
        '#col' => $col,
879
        '#type' => 'item',
880
        '#markup' => isset($mapping['name']) ? $mapping['name'] : '?',
881
      );
882
    }
883
    else {
884
      $form[$user_attr_input_id] = array(
885
        '#id' => $user_attr_input_id,
886
        '#row' => $row,
887
        '#col' => $col,
888
        '#type' => 'select',
889
        '#default_value' => isset($mapping['user_attr']) ? $mapping['user_attr'] : '',
890
        '#options' => $user_attr_options,
891
      );
892
    }
893
894
    if ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
895 bc175c27 Assos Assos
      $id = $id_prefix . 'sm__user_tokens__' . $row;
896 85ad3d82 Assos Assos
      $form[$id] = array(
897
        '#id' => $id,
898
        '#row' => $row,
899 bc175c27 Assos Assos
        '#col' => 2,
900 85ad3d82 Assos Assos
        '#type' => 'textfield',
901
        '#default_value' => isset($mapping['user_tokens']) ? $mapping['user_tokens'] : '',
902
        '#size' => 40,
903
        '#maxlength' => 255,
904
        '#disabled' => ($action == 'nonconfigurable'),
905
        '#states' => array(
906
          'visible' => array(   // action to take.
907
            ':input[name="' . $user_attr_input_id . '"]' => array('value' => 'user_tokens'),
908
          )
909
        ),
910
        '#attributes' => array('class' => array('tokens')),
911
      );
912
    }
913
914
    $form['#storage']['synch_mapping_fields'][$direction][$row] = array(
915
      'action' => $action,
916
      'direction' => $direction,
917
    );
918
919
    $id = $id_prefix . 'sm__configurable_to_drupal__' . $row;
920
    $form[$id] = array(
921
      '#id' => $id,
922
      '#type' => 'hidden',
923
      '#default_value' => ($action != 'nonconfigurable'),
924
    );
925
926
927
    $col = ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) ? 5 : 4;
928
    $synchEvents = ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) ? $this->provisionsDrupalEvents : $this->provisionsLdapEvents;
929
930
    foreach ($synchEvents as $prov_event => $prov_event_name) {
931
      $col++;
932 bc175c27 Assos Assos
      $id = $id_prefix . join('__', array('sm', $prov_event, $row));
933 85ad3d82 Assos Assos
      $form[$id] = array(
934
        '#id' => $id ,
935
        '#type' => 'checkbox',
936
        '#default_value' => isset($mapping['prov_events']) ? (int)(in_array($prov_event, $mapping['prov_events'])) : '',
937
        '#row' => $row,
938
        '#col' => $col,
939
        '#disabled' => (!$this->provisionEventConfigurable($prov_event, $mapping) || ($action == 'nonconfigurable')),
940
        '#attributes' => array('class' => array('synch-method')),
941
      );
942
    }
943
  }
944
945
  /**
946
   * Is a mapping configurable by a given module?
947
   *
948
   * @param array $mapping as mapping configuration for field, attribute, property, etc.
949
   * @param string $module machine name such as ldap_user
950
   *
951
   * @return boolean
952
   */
953
  private function isMappingConfigurable($mapping = NULL, $module = 'ldap_user') {
954
    $configurable = (
955
      (
956
        (!isset($mapping['configurable_to_drupal']) && !isset($mapping['configurable_to_ldap'])) ||
957
        (isset($mapping['configurable_to_drupal']) && $mapping['configurable_to_drupal']) ||
958
        (isset($mapping['configurable_to_ldap']) && $mapping['configurable_to_ldap'])
959
      )
960
      &&
961
      (
962
        !isset($mapping['config_module']) ||
963
        (isset($mapping['config_module']) && $mapping['config_module'] == $module)
964
      )
965
    );
966
    return $configurable;
967
  }
968
969
970
  /**
971
   * Is a particular synch method viable for a given mapping?
972
   * That is, Can it be enabled in the UI by admins?
973
   *
974
   * @param int $prov_event
975
   * @param array $mapping is array of mapping configuration.
976
   *
977
   * @return boolean
978
   */
979
980
  private function provisionEventConfigurable($prov_event, $mapping = NULL) {
981
982
    if ($mapping) {
983
      if ($prov_event == LDAP_USER_EVENT_CREATE_LDAP_ENTRY || $prov_event == LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY) {
984
        $configurable = (boolean)(!isset($mapping['configurable_to_ldap']) || $mapping['configurable_to_ldap']);
985
      }
986
      elseif ($prov_event == LDAP_USER_EVENT_CREATE_DRUPAL_USER || $prov_event == LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER) {
987
        $configurable = (boolean)(!isset($mapping['configurable_to_drupal']) || $mapping['configurable_to_drupal']);
988
      }
989
    }
990
    else {
991
      $configurable = TRUE;
992
    }
993
994
    return $configurable;
995
  }
996
997
  protected function setTranslatableProperties() {
998
999
    $values['drupalAcctProvisionServerDescription'] = t('Check ONE LDAP server configuration to use
1000
      in provisioning Drupal users and their user fields.');
1001
    $values['ldapEntryProvisionServerDescription'] = t('Check ONE LDAP server configuration to create ldap entries on.');
1002
1003
    $values['drupalAccountProvisionEventsDescription'] = t('Which user fields and properties are synched on create or synch is determined in the
1004
      "Provisioning from LDAP to Drupal mappings" table below in the right two columns. If you are synching only from LDAP to Drupal, and not 
1005
      retrieving the user password from LDAP into their Drupal account, a 20 character random password will be generated automatically for
1006
      the user\'s Drupal account since Drupal requires a password for the "users" table. Check the watchdog at /admin/reports/dblog to
1007
      confirm that a random password was generated when the user account was created.');
1008
1009
    $values['drupalAccountProvisionEventsOptions'] = array(
1010
      LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE => t('Create or Synch to Drupal user on successful authentication with LDAP
1011
        credentials. (Requires LDAP Authentication module).'),
1012
      LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE => t('Create or Synch to Drupal user anytime a Drupal user account
1013
        is created or updated. Requires a server with binding method of "Service Account Bind" or "Anonymous Bind".'),
1014
      );
1015
1016
    $values['ldapEntryProvisionTriggersDescription'] = t('Which LDAP attributes are synched on create or synch is determined in the
1017
      "Provisioning from Drupal to LDAP mappings" table below in the right two columns.');
1018
1019
    $values['ldapEntryProvisionTriggersOptions'] = array(
1020
      LDAP_USER_LDAP_ENTRY_PROV_ON_USER_UPDATE_CREATE => t('Create or Synch to LDAP entry when a Drupal account is created or updated.
1021
        Only applied to accounts with a status of approved.'),
1022
      LDAP_USER_LDAP_ENTRY_PROV_ON_AUTHENTICATE => t('Create or Synch to LDAP entry when a user authenticates.'),
1023
      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.'),
1024
      LDAP_USER_DRUPAL_USER_PROV_ON_ALLOW_MANUAL_CREATE => t('Provide option on admin/people/create to create corresponding LDAP Entry.'),
1025
1026
    );
1027
1028 be58a50c Assos Assos
    $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.');
1029 85ad3d82 Assos Assos
1030
1031 bc175c27 Assos Assos
    $values['manualAccountConflictOptions'] = array(
1032 85ad3d82 Assos Assos
      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.'),
1033
      LDAP_USER_MANUAL_ACCT_CONFLICT_LDAP_ASSOCIATE => t('Associate manually created Drupal accounts with related LDAP Account if one exists.'),
1034
      LDAP_USER_MANUAL_ACCT_CONFLICT_SHOW_OPTION_ON_FORM => t('Show option on user create form to determine how account conflict is resolved.'),
1035
    );
1036
1037
    /**
1038
    *  Drupal Account Provisioning and Synching
1039
    */
1040
    $values['userConflictResolveDescription'] = t('What should be done if a local Drupal or other external
1041
      user account already exists with the same login name.');
1042
    $values['userConflictOptions'] = array(
1043
      LDAP_USER_CONFLICT_LOG => t('Don\'t associate Drupal account with LDAP.  Require user to use Drupal password. Log the conflict'),
1044
      LDAP_USER_CONFLICT_RESOLVE => t('Associate Drupal account with the LDAP entry.  This option
1045
      is useful for creating accounts and assigning roles before an LDAP user authenticates.'),
1046
      );
1047 b42754b9 Assos Assos
    $values['accountsWithSameEmailDescription'] = t('Allows provisioning a Drupal user account from LDAP regardless of whether another Drupal user account has the same email address. This setting depends on the "sharedemail" contrib module being enabled. ');
1048
    if (!module_exists('sharedemail')) {
1049
      $values['accountsWithSameEmailDescription'] .= t('The module is not currently enabled; you must install/enable it if you want to use this setting.');
1050
    }
1051
    $values['accountsWithSameEmailOptions'] = array(
1052
      LDAP_USER_ACCOUNTS_WITH_SAME_EMAIL_DISABLED => t('Prevent provisioning a user account if an existing account has the same email address.'),
1053
      LDAP_USER_ACCOUNTS_WITH_SAME_EMAIL_ENABLED => t('Allow provisioning a user account that has the same email address as another user account.'),
1054
      );
1055 85ad3d82 Assos Assos
    $values['acctCreationOptions'] = array(
1056
      LDAP_USER_ACCT_CREATION_LDAP_BEHAVIOR => t('Account creation settings at
1057
        /admin/config/people/accounts/settings do not affect "LDAP Associated" Drupal accounts.'),
1058
      LDAP_USER_ACCT_CREATION_USER_SETTINGS_FOR_LDAP => t('Account creation policy
1059
         at /admin/config/people/accounts/settings applies to both Drupal and LDAP Authenticated users.
1060
         "Visitors" option automatically creates and account when they successfully LDAP authenticate.
1061
         "Admin" and "Admin with approval" do not allow user to authenticate until the account is approved.'),
1062
1063
      );
1064
1065
      foreach ($values as $property => $default_value) {
1066
        $this->$property = $default_value;
1067
      }
1068
    }
1069
1070
}