Projet

Général

Profil

Révision 32700c57

Ajouté par Assos Assos il y a environ 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ldap/ldap_authentication/LdapAuthenticationConfAdmin.class.php
2 2

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

  
8 8
ldap_servers_module_load_include('php', 'ldap_authentication', 'LdapAuthenticationConf.class');
9

  
9
/**
10
 *
11
 */
10 12
class LdapAuthenticationConfAdmin extends LdapAuthenticationConf {
11 13

  
14
  /**
15
   *
16
   */
12 17
  protected function setTranslatableProperties() {
13 18

  
14 19
    /**
15 20
     * 0.  Logon Options
16 21
     */
17 22

  
18
    $values['authenticationModeOptions']  = array(
23
    $values['authenticationModeOptions'] = [
19 24
      LDAP_AUTHENTICATION_MIXED => t('Mixed mode. Drupal authentication is tried first.  On failure, LDAP authentication is performed.'),
20 25
      LDAP_AUTHENTICATION_EXCLUSIVE => t('Only LDAP Authentication is allowed except for user 1.
21 26
        If selected, (1) reset password links will be replaced with links to ldap end user documentation below.
22 27
        (2) The reset password form will be left available at user/password for user 1; but no links to it
23 28
        will be provided to anonymous users.
24 29
        (3) Password fields in user profile form will be removed except for user 1.'),
25
      );
30
    ];
26 31

  
27 32
    $values['authenticationServersDescription'] = t('Check all LDAP server configurations to use in authentication.
28 33
     Each will be tested for authentication until successful or
......
41 46
     passwords etc. Should be of form http://domain.com/. Could be the institutions ldap password support page
42 47
     or a page within this drupal site that is available to anonymous users.');
43 48

  
44
    $values['ldapUserHelpLinkTextDescription']  = t('Text for above link e.g. Account Help or Campus Password Help Page');
45

  
49
    $values['ldapUserHelpLinkTextDescription'] = t('Text for above link e.g. Account Help or Campus Password Help Page');
46 50

  
47 51
    /**
48 52
     * LDAP User Restrictions
......
68 72
    * Email
69 73
    */
70 74

  
71
    $values['emailOptionOptions'] = array(
75
    $values['emailOptionOptions'] = [
72 76
      LDAP_AUTHENTICATION_EMAIL_FIELD_REMOVE => t('Don\'t show an email field on user forms. LDAP derived email will be used for user and cannot be changed by user.'),
73 77
      LDAP_AUTHENTICATION_EMAIL_FIELD_DISABLE => t('Show disabled email field on user forms with LDAP derived email. LDAP derived email will be used for user and cannot be changed by user.'),
74 78
      LDAP_AUTHENTICATION_EMAIL_FIELD_ALLOW => t('Leave email field on user forms enabled. Generally used when provisioning to LDAP or not using email derived from LDAP.'),
75
      );
79
    ];
76 80

  
77
    $values['emailUpdateOptions'] = array(
81
    $values['emailUpdateOptions'] = [
78 82
      LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE_NOTIFY => t('Update stored email if LDAP email differs at login and notify user.'),
79 83
      LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE => t('Update stored email if LDAP email differs at login but don\'t notify user.'),
80 84
      LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_DISABLE => t('Don\'t update stored email if LDAP email differs at login.'),
81
      );
82
    $values['emailTemplateHandlingOptions'] = array(
85
    ];
86
    $values['emailTemplateHandlingOptions'] = [
83 87
      LDAP_AUTHENTICATION_EMAIL_TEMPLATE_NONE => t('Never use the template.'),
84 88
      LDAP_AUTHENTICATION_EMAIL_TEMPLATE_IF_EMPTY => t('Use the template if no email address was provided by the LDAP server.'),
85 89
      LDAP_AUTHENTICATION_EMAIL_TEMPLATE_ALWAYS => t('Always use the template.'),
86
    );
87

  
90
    ];
88 91

  
89 92
    /**
90 93
    * Password
91 94
    */
92 95

  
93
    $values['passwordUpdateOptions'] = array(
96
    $values['passwordUpdateOptions'] = [
94 97
      LDAP_AUTHENTICATION_PASSWORD_FIELD_SHOW => t('Display password field disabled (Prevents password updates).'),
95 98
      LDAP_AUTHENTICATION_PASSWORD_FIELD_HIDE => t('Don\'t show password field on user forms except login form.'),
96 99
      LDAP_AUTHENTICATION_PASSWORD_FIELD_ALLOW => t('Display password field and allow updating it. In order to change password in LDAP, LDAP provisioning for this field must be enabled.'),
97
      );
100
    ];
98 101

  
99 102
    /**
100 103
     *  Single Sign-On / Seamless Sign-On
101 104
     */
102 105

  
103
      $values['ldapImplementationOptions'] = array(
104
        'mod_auth_sspi' => t('mod_auth_sspi'),
105
        'mod_auth_kerb' => t('mod_auth_kerb'),
106
        );
106
    $values['ldapImplementationOptions'] = [
107
      'mod_auth_sspi' => t('mod_auth_sspi'),
108
      'mod_auth_kerb' => t('mod_auth_kerb'),
109
    ];
107 110

  
108
      $values['cookieExpirePeriod'] = array(-1 => t('Session'), 0 => t('Immediately')) +
109
        drupal_map_assoc(array(3600, 86400, 604800, 2592000, 31536000, 315360000, 630720000), 'format_interval');
111
    $values['cookieExpirePeriod'] = [-1 => t('Session'), 0 => t('Immediately')] +
112
        drupal_map_assoc([3600, 86400, 604800, 2592000, 31536000, 315360000, 630720000], 'format_interval');
110 113

  
111
      $values['ssoEnabledDescription'] = '<strong>' . t('Single Sign on is enabled.') .
114
    $values['ssoEnabledDescription'] = '<strong>' . t('Single Sign on is enabled.') .
112 115
        '</strong> ' . t('To disable it, disable the LDAP SSO Module on the') . ' ' . l(t('Modules Form'), 'admin/modules') . '.<p>' .
113 116
        t('Single Sign-On enables ' .
114 117
        'users of this site to be authenticated by visiting the URL ' .
115 118
        '"user/login/sso, or automatically if selecting "automated ' .
116 119
        'single sign-on" below. Set up of LDAP authentication must be ' .
117
        'performed on the web server. Please review the readme file of the '.
120
        'performed on the web server. Please review the readme file of the ' .
118 121
        'ldap_sso module for more information.')
119 122
        . '</p>';
120 123

  
121
      $values['ssoExcludedPathsDescription'] = '<p>' .
124
    $values['ssoExcludedPathsDescription'] = '<p>' .
122 125
        t("Which paths will not check for SSO? cron.php is common example.  Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard.
123 126
          Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.",
124
          array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
125
        '</p>';
127
          ['%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>']);
128
    '</p>';
126 129

  
127
      $values['ssoExcludedHostsDescription'] = '<p>' .
130
    $values['ssoExcludedHostsDescription'] = '<p>' .
128 131
        t('If your site is accessible via multiple hostnames, you may only want
129 132
          the LDAP SSO module to authenticate against some of them. To exclude
130 133
          any hostnames from SSO, enter them here. Enter one host per line.');
131
        '</p>';
134
    '</p>';
132 135

  
133
      $values['ssoRemoteUserStripDomainNameDescription'] = t('Useful when the ' .
136
    $values['ssoRemoteUserStripDomainNameDescription'] = t('Useful when the ' .
134 137
        'WWW server provides authentication in the form of user@realm and you ' .
135 138
        'want to have both SSO and regular forms based authentication ' .
136 139
        'available. Otherwise duplicate accounts with conflicting e-mail ' .
137 140
        'addresses may be created.');
138
      $values['ssoNotifyAuthenticationDescription'] = t('This displays a message to the ' .
141
    $values['ssoNotifyAuthenticationDescription'] = t('This displays a message to the ' .
139 142
        'user after they have succesfully authenticated using single sign on');
140
      $values['seamlessLogInDescription'] = t('This requires that you ' .
143
    $values['seamlessLogInDescription'] = t('This requires that you ' .
141 144
        'have operational NTLM or Kerberos authentication turned on for at least ' .
142 145
        'the path user/login/sso, or for the whole domain.');
143
      $values['cookieExpireDescription'] = t('If using the automated/seamless login, a ' .
146
    $values['cookieExpireDescription'] = t('If using the automated/seamless login, a ' .
144 147
        'cookie is necessary to prevent automatic login after a user ' .
145 148
        'manually logs out. Select the lifetime of the cookie.');
146
      $values['ldapImplementationDescription'] = t('Select the type of ' .
149
    $values['ldapImplementationDescription'] = t('Select the type of ' .
147 150
        'authentication mechanism you are using.');
148 151

  
149
      foreach ($values as $property => $default_value) {
150
        $this->$property = $default_value;
151
      }
152
    foreach ($values as $property => $default_value) {
153
      $this->$property = $default_value;
152 154
    }
155
  }
153 156

  
154 157
  /**
155
   * 0.  Logon Options
158
   * 0.  Logon Options.
156 159
   */
157 160
  public $authenticationModeDefault = LDAP_AUTHENTICATION_MIXED;
158 161
  public $authenticationModeOptions;
159 162

  
160 163
  protected $authenticationServersDescription;
161
  protected $authenticationServersOptions = array();
164
  protected $authenticationServersOptions = [];
162 165

  
163 166
  /**
164
   * 1.  User Login Interface
167
   * 1.  User Login Interface.
165 168
   */
166 169
  protected $loginUIUsernameTxtDescription;
167 170
  protected $loginUIPasswordTxtDescription;
......
170 173

  
171 174

  
172 175
  /**
173
   * 2.  LDAP User Restrictions
176
   * 2.  LDAP User Restrictions.
174 177
   */
175 178

  
176 179
  protected $allowOnlyIfTextInDnDescription;
177 180
  protected $excludeIfTextInDnDescription;
178 181
  protected $allowTestPhpDescription;
179 182

  
180
   /**
181
   * 4. Email
183
  /**
184
   * 4. Email.
182 185
   */
183 186

  
184 187
  public $emailOptionDefault = LDAP_AUTHENTICATION_EMAIL_FIELD_REMOVE;
......
186 189

  
187 190
  public $emailUpdateDefault = LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE_NOTIFY;
188 191
  public $emailUpdateOptions;
189
  
192

  
190 193
  public $emailTemplateHandlingDefault = LDAP_AUTHENTICATION_EMAIL_TEMPLATE_DEFAULT;
191 194
  public $emailTemplateHandlingOptions;
192
  
195

  
193 196
  public $emailTemplateDefault = LDAP_AUTHENTICATION_DEFAULT_TEMPLATE;
194
  
197

  
195 198
  public $templateUsagePromptUserDefault = LDAP_AUTHENTICATION_TEMPLATE_USAGE_PROMPT_USER_DEFAULT;
196
  
199

  
197 200
  public $templateUsagePromptRegexDefault = LDAP_AUTHENTICATION_DEFAULT_TEMPLATE_REGEX;
198
  
201

  
199 202
  public $templateUsageNeverUpdateDefault = LDAP_AUTHENTICATION_TEMPLATE_USAGE_NEVER_UPDATE_DEFAULT;
200 203

  
201
   /**
202
   * 5. Single Sign-On / Seamless Sign-On
204
  /**
205
   * 5. Single Sign-On / Seamless Sign-On.
203 206
   */
204 207

  
205 208
  public $ssoEnabledDescription;
......
215 218
  public $hasError = FALSE;
216 219
  public $errorName = NULL;
217 220

  
221
  /**
222
   *
223
   */
218 224
  public function clearError() {
219 225
    $this->hasError = FALSE;
220 226
    $this->errorMsg = NULL;
221 227
    $this->errorName = NULL;
222 228
  }
223 229

  
230
  /**
231
   *
232
   */
224 233
  public function save() {
225 234
    foreach ($this->saveable as $property) {
226 235
      $save[$property] = $this->{$property};
......
229 238
    $this->load();
230 239
  }
231 240

  
232
  static public function getSaveableProperty($property) {
233
    $ldap_authentication_conf = variable_get('ldap_authentication_conf', array());
241
  /**
242
   *
243
   */
244
  public static function getSaveableProperty($property) {
245
    $ldap_authentication_conf = variable_get('ldap_authentication_conf', []);
234 246
    return isset($ldap_authentication_conf[$property]) ? $ldap_authentication_conf[$property] : FALSE;
235 247

  
236 248
  }
237 249

  
238
  static public function uninstall() {
250
  /**
251
   *
252
   */
253
  public static function uninstall() {
239 254
    variable_del('ldap_authentication_conf');
240 255
  }
241 256

  
257
  /**
258
   *
259
   */
242 260
  public function __construct() {
243 261
    parent::__construct();
244 262
    $this->setTranslatableProperties();
......
250 268
    }
251 269
  }
252 270

  
253

  
271
  /**
272
   *
273
   */
254 274
  public function drupalForm() {
255 275

  
256 276
    if (count($this->authenticationServersOptions) == 0) {
257 277
      $message = ldap_servers_no_enabled_servers_msg('configure LDAP Authentication');
258
      $form['intro'] = array(
278
      $form['intro'] = [
259 279
        '#type' => 'item',
260 280
        '#markup' => t('<h1>LDAP Authentication Settings</h1>') . $message,
261
      );
281
      ];
262 282
      return $form;
263 283
    }
264 284

  
265
    $tokens = array();  // not sure what the tokens would be for this form?
285
    // Not sure what the tokens would be for this form?
286
    $tokens = [];
266 287

  
267
    $form['intro'] = array(
268
        '#type' => 'item',
269
        '#markup' => t('<h1>LDAP Authentication Settings</h1>'),
270
    );
288
    $form['intro'] = [
289
      '#type' => 'item',
290
      '#markup' => t('<h1>LDAP Authentication Settings</h1>'),
291
    ];
271 292

  
272
    $form['logon'] = array(
293
    $form['logon'] = [
273 294
      '#type' => 'fieldset',
274 295
      '#title' => t('Logon Options'),
275 296
      '#collapsible' => TRUE,
276 297
      '#collapsed' => FALSE,
277
    );
298
    ];
278 299

  
279
    $form['logon']['authenticationMode'] = array(
300
    $form['logon']['authenticationMode'] = [
280 301
      '#type' => 'radios',
281 302
      '#title' => t('Allowable Authentications'),
282 303
      '#required' => 1,
283 304
      '#default_value' => $this->authenticationMode,
284 305
      '#options' => $this->authenticationModeOptions,
285
    );
306
    ];
286 307

  
287
    $form['logon']['authenticationServers'] = array(
308
    $form['logon']['authenticationServers'] = [
288 309
      '#type' => 'checkboxes',
289 310
      '#title' => t('Authentication LDAP Server Configurations'),
290 311
      '#required' => FALSE,
291 312
      '#default_value' => $this->sids,
292 313
      '#options' => $this->authenticationServersOptions,
293
      '#description' => $this->authenticationServersDescription
294
    );
314
      '#description' => $this->authenticationServersDescription,
315
    ];
295 316

  
296
    $form['login_UI'] = array(
317
    $form['login_UI'] = [
297 318
      '#type' => 'fieldset',
298 319
      '#title' => t('User Login Interface'),
299 320
      '#collapsible' => TRUE,
300 321
      '#collapsed' => FALSE,
301
    );
322
    ];
302 323

  
303
    $form['login_UI']['loginUIUsernameTxt'] = array(
324
    $form['login_UI']['loginUIUsernameTxt'] = [
304 325
      '#type' => 'textfield',
305 326
      '#title' => t('Username Description Text'),
306 327
      '#required' => 0,
307 328
      '#default_value' => $this->loginUIUsernameTxt,
308 329
      '#description' => $this->loginUIUsernameTxtDescription,
309
    );
330
    ];
310 331

  
311
    $form['login_UI']['loginUIPasswordTxt'] = array(
332
    $form['login_UI']['loginUIPasswordTxt'] = [
312 333
      '#type' => 'textfield',
313 334
      '#title' => t('Password Description Text'),
314 335
      '#required' => 0,
315 336
      '#default_value' => $this->loginUIPasswordTxt,
316 337
      '#description' => $this->loginUIPasswordTxtDescription,
317
    );
338
    ];
318 339

  
319
    $form['login_UI']['ldapUserHelpLinkUrl'] = array(
340
    $form['login_UI']['ldapUserHelpLinkUrl'] = [
320 341
      '#type' => 'textfield',
321 342
      '#title' => t('LDAP Account User Help URL'),
322 343
      '#required' => 0,
323 344
      '#default_value' => $this->ldapUserHelpLinkUrl,
324 345
      '#description' => $this->ldapUserHelpLinkUrlDescription,
325
    );
326

  
346
    ];
327 347

  
328
    $form['login_UI']['ldapUserHelpLinkText'] = array(
348
    $form['login_UI']['ldapUserHelpLinkText'] = [
329 349
      '#type' => 'textfield',
330 350
      '#title' => t('LDAP Account User Help Link Text'),
331 351
      '#required' => 0,
332 352
      '#default_value' => $this->ldapUserHelpLinkText,
333 353
      '#description' => $this->ldapUserHelpLinkTextDescription,
334
    );
354
    ];
335 355

  
336
    $form['restrictions'] = array(
356
    $form['restrictions'] = [
337 357
      '#type' => 'fieldset',
338 358
      '#title' => t('LDAP User "Whitelists" and Restrictions'),
339 359
      '#collapsible' => TRUE,
340 360
      '#collapsed' => FALSE,
341
    );
361
    ];
342 362

  
343

  
344
    $form['restrictions']['allowOnlyIfTextInDn'] = array(
363
    $form['restrictions']['allowOnlyIfTextInDn'] = [
345 364
      '#type' => 'textarea',
346 365
      '#title' => t('Allow Only Text Test'),
347 366
      '#default_value' => $this->arrayToLines($this->allowOnlyIfTextInDn),
348 367
      '#cols' => 50,
349 368
      '#rows' => 3,
350 369
      '#description' => t($this->allowOnlyIfTextInDnDescription, $tokens),
351
    );
370
    ];
352 371

  
353
    $form['restrictions']['excludeIfTextInDn'] = array(
372
    $form['restrictions']['excludeIfTextInDn'] = [
354 373
      '#type' => 'textarea',
355 374
      '#title' => t('Excluded Text Test'),
356 375
      '#default_value' => $this->arrayToLines($this->excludeIfTextInDn),
357 376
      '#cols' => 50,
358 377
      '#rows' => 3,
359 378
      '#description' => t($this->excludeIfTextInDnDescription, $tokens),
360
    );
379
    ];
361 380

  
362
    $form['restrictions']['allowTestPhp'] = array(
381
    $form['restrictions']['allowTestPhp'] = [
363 382
      '#type' => 'textarea',
364 383
      '#title' => t('PHP to Test for Allowed LDAP Users'),
365 384
      '#default_value' => $this->allowTestPhp,
366 385
      '#cols' => 50,
367 386
      '#rows' => 3,
368 387
      '#description' => t($this->allowTestPhpDescription, $tokens),
369
      '#disabled' => (boolean)(!module_exists('php')),
370
    );
388
      '#disabled' => (boolean) (!module_exists('php')),
389
    ];
371 390

  
372 391
    if (!module_exists('php')) {
373 392
      $form['restrictions']['allowTestPhp']['#title'] .= ' <em>' . t('php module currently disabled') . '</em>';
374 393
    }
375 394

  
376
    $form['restrictions']['excludeIfNoAuthorizations'] = array(
395
    $form['restrictions']['excludeIfNoAuthorizations'] = [
377 396
      '#type' => 'checkbox',
378 397
      '#title' => t('Deny access to users without Ldap Authorization Module
379 398
        authorization mappings such as Drupal roles.
380 399
        Requires LDAP Authorization to be enabled and configured!'),
381 400
      '#default_value' => $this->excludeIfNoAuthorizations,
382 401
      '#description' => t($this->excludeIfNoAuthorizationsDescription, $tokens),
383
      '#disabled' => (boolean)(!module_exists('ldap_authorization')),
384
    );
402
      '#disabled' => (boolean) (!module_exists('ldap_authorization')),
403
    ];
385 404

  
386
    $form['email'] = array(
405
    $form['email'] = [
387 406
      '#type' => 'fieldset',
388 407
      '#title' => t('Email'),
389 408
      '#collapsible' => TRUE,
390 409
      '#collapsed' => FALSE,
391
    );
410
    ];
392 411

  
393
    $form['email']['emailOption'] = array(
412
    $form['email']['emailOption'] = [
394 413
      '#type' => 'radios',
395 414
      '#title' => t('Email Behavior'),
396 415
      '#required' => 1,
397 416
      '#default_value' => $this->emailOption,
398 417
      '#options' => $this->emailOptionOptions,
399
    );
418
    ];
400 419

  
401
    $form['email']['emailUpdate'] = array(
420
    $form['email']['emailUpdate'] = [
402 421
      '#type' => 'radios',
403 422
      '#title' => t('Email Update'),
404 423
      '#required' => 1,
405 424
      '#default_value' => $this->emailUpdate,
406 425
      '#options' => $this->emailUpdateOptions,
407
      );
408
    
409
    $form['email']['template'] = array(
426
    ];
427

  
428
    $form['email']['template'] = [
410 429
      '#type' => 'fieldset',
411 430
      '#collapsible' => TRUE,
412 431
      '#title' => t('Email Templates'),
413
    );
414
    
415
    $form['email']['template']['emailTemplateHandling'] = array(
432
    ];
433

  
434
    $form['email']['template']['emailTemplateHandling'] = [
416 435
      '#type' => 'radios',
417 436
      '#title' => t('Email Template Handling'),
418 437
      '#required' => 1,
419 438
      '#default_value' => $this->emailTemplateHandling,
420
      '#options' => $this->emailTemplateHandlingOptions
421
    );
422
    
423
    $form['email']['template']['emailTemplate'] = array(
439
      '#options' => $this->emailTemplateHandlingOptions,
440
    ];
441

  
442
    $form['email']['template']['emailTemplate'] = [
424 443
      '#type' => 'textfield',
425 444
      '#title' => t('Email Template'),
426 445
      '#required' => 0,
427 446
      '#default_value' => $this->emailTemplate,
428
    );
429
    
430
    $form['email']['template']['templateUsageResolveConflict'] = array(
447
    ];
448

  
449
    $form['email']['template']['templateUsageResolveConflict'] = [
431 450
      '#type' => 'checkbox',
432 451
      '#title' => t('If a Drupal account already exists with the same email, but different account name, use the email template instead of the LDAP email.'),
433 452
      '#default_value' => $this->templateUsageResolveConflict,
434
    );
435
    
436
    $form['email']['template']['templateUsageNeverUpdate'] = array(
453
    ];
454

  
455
    $form['email']['template']['templateUsageNeverUpdate'] = [
437 456
      '#type' => 'checkbox',
438 457
      '#title' => t('Ignore the Email Update settings and never update the stored email if the template is used.'),
439 458
      '#default_value' => $this->templateUsageNeverUpdate,
440
    );
441
    
442
    $form['email']['prompts'] = array(
459
    ];
460

  
461
    $form['email']['prompts'] = [
443 462
      '#type' => 'fieldset',
444 463
      '#collapsible' => TRUE,
445 464
      '#title' => t('User Email Prompt'),
446
      '#description' => t('These settings allow the user to fill in their email address after logging in if the template was used to generate their email address.'),      
447
    );
448
    
449
    $form['email']['prompts']['templateUsagePromptUser'] = array(
465
      '#description' => t('These settings allow the user to fill in their email address after logging in if the template was used to generate their email address.'),
466
    ];
467

  
468
    $form['email']['prompts']['templateUsagePromptUser'] = [
450 469
      '#type' => 'checkbox',
451 470
      '#title' => t('Prompt user for email on every page load.'),
452 471
      '#default_value' => $this->templateUsagePromptUser,
453
    );
454
    
455
    $form['email']['prompts']['templateUsageRedirectOnLogin'] = array(
472
    ];
473

  
474
    $form['email']['prompts']['templateUsageRedirectOnLogin'] = [
456 475
      '#type' => 'checkbox',
457 476
      '#title' => t('Redirect the user to the form after logging in.'),
458 477
      '#default_value' => $this->templateUsageRedirectOnLogin,
459
    );
460
    
461
    $form['email']['prompts']['templateUsagePromptRegex'] = array(
478
    ];
479

  
480
    $form['email']['prompts']['templateUsagePromptRegex'] = [
462 481
      '#type' => 'textfield',
463 482
      '#default_value' => $this->templateUsagePromptRegex,
464 483
      '#title' => t('Template Regex'),
465 484
      '#description' => t('This regex will be used to determine if the template was used to create an account.'),
466
    );
467
    
485
    ];
468 486

  
469
    $form['password'] = array(
487
    $form['password'] = [
470 488
      '#type' => 'fieldset',
471 489
      '#title' => t('Password'),
472 490
      '#collapsible' => TRUE,
473 491
      '#collapsed' => FALSE,
474
    );
475
    $form['password']['passwordOption'] = array(
492
    ];
493
    $form['password']['passwordOption'] = [
476 494
      '#type' => 'radios',
477 495
      '#title' => t('Password Behavior'),
478 496
      '#required' => 1,
479 497
      '#default_value' => $this->passwordOption,
480 498
      '#options' => $this->passwordUpdateOptions,
481
    );
499
    ];
482 500

  
483 501
    /**
484 502
     * Begin single sign-on settings
485 503
     */
486
    $form['sso'] = array(
504
    $form['sso'] = [
487 505
      '#type' => 'fieldset',
488 506
      '#title' => t('Single Sign-On'),
489 507
      '#collapsible' => TRUE,
490
      '#collapsed' => (boolean)(!$this->ssoEnabled),
491
    );
508
      '#collapsed' => (boolean) (!$this->ssoEnabled),
509
    ];
492 510

  
493 511
    if ($this->ssoEnabled) {
494
      $form['sso']['enabled'] = array(
512
      $form['sso']['enabled'] = [
495 513
        '#type' => 'markup',
496 514
        '#markup' => $this->ssoEnabledDescription,
497
      );
515
      ];
498 516
    }
499 517
    else {
500
      $form['sso']['disabled'] = array(
518
      $form['sso']['disabled'] = [
501 519
        '#type' => 'markup',
502 520
        '#markup' => '<p><em>' . t('LDAP Single Sign-On module must be enabled for options below to work.')
503 521
        . ' ' . t('It is currently disabled.')
504 522
        . ' ' . l(t('See modules form'), 'admin/modules') . '</p></em>',
505
      );
523
      ];
506 524
    }
507 525

  
508
    $form['sso']['ssoRemoteUserStripDomainName'] = array(
526
    $form['sso']['ssoRemoteUserStripDomainName'] = [
509 527
      '#type' => 'checkbox',
510 528
      '#title' => t('Strip REMOTE_USER domain name'),
511 529
      '#description' => t($this->ssoRemoteUserStripDomainNameDescription),
512 530
      '#default_value' => $this->ssoRemoteUserStripDomainName,
513
      '#disabled' => (boolean)(!$this->ssoEnabled),
514
    );
531
      '#disabled' => (boolean) (!$this->ssoEnabled),
532
    ];
515 533

  
516
    $form['sso']['seamlessLogin'] = array(
534
    $form['sso']['seamlessLogin'] = [
517 535
      '#type' => 'checkbox',
518 536
      '#title' => t('Turn on automated/seamless single sign-on'),
519 537
      '#description' => t($this->seamlessLogInDescription),
520 538
      '#default_value' => $this->seamlessLogin,
521
      '#disabled' => (boolean)(!$this->ssoEnabled),
522
      );
539
      '#disabled' => (boolean) (!$this->ssoEnabled),
540
    ];
523 541

  
524
    $form['sso']['ssoNotifyAuthentication'] = array(
542
    $form['sso']['ssoNotifyAuthentication'] = [
525 543
      '#type' => 'checkbox',
526 544
      '#title' => t('Notify user of successful authentication'),
527 545
      '#description' => t($this->ssoNotifyAuthenticationDescription),
528 546
      '#default_value' => $this->ssoNotifyAuthentication,
529
      '#disabled' => (boolean)(!$this->ssoEnabled),
530
      );
547
      '#disabled' => (boolean) (!$this->ssoEnabled),
548
    ];
531 549

  
532
    $form['sso']['cookieExpire'] = array(
550
    $form['sso']['cookieExpire'] = [
533 551
      '#type' => 'select',
534 552
      '#title' => t('Cookie Lifetime'),
535 553
      '#description' => t($this->cookieExpireDescription),
536 554
      '#default_value' => $this->cookieExpire,
537 555
      '#options' => $this->cookieExpirePeriod,
538
      '#disabled' => (boolean)(!$this->ssoEnabled),
539
    );
556
      '#disabled' => (boolean) (!$this->ssoEnabled),
557
    ];
540 558

  
541
    $form['sso']['ldapImplementation'] = array(
559
    $form['sso']['ldapImplementation'] = [
542 560
      '#type' => 'select',
543 561
      '#title' => t('Authentication Mechanism'),
544 562
      '#description' => t($this->ldapImplementationDescription),
545 563
      '#default_value' => $this->ldapImplementation,
546 564
      '#options' => $this->ldapImplementationOptions,
547
      '#disabled' => (boolean)(!$this->ssoEnabled),
548
    );
565
      '#disabled' => (boolean) (!$this->ssoEnabled),
566
    ];
549 567

  
550
    $form['sso']['ssoExcludedPaths'] = array(
568
    $form['sso']['ssoExcludedPaths'] = [
551 569
      '#type' => 'textarea',
552 570
      '#title' => t('SSO Excluded Paths'),
553 571
      '#description' => t($this->ssoExcludedPathsDescription),
554 572
      '#default_value' => $this->arrayToLines($this->ssoExcludedPaths),
555
      '#disabled' => (boolean)(!$this->ssoEnabled),
556
    );
573
      '#disabled' => (boolean) (!$this->ssoEnabled),
574
    ];
557 575

  
558
    $form['sso']['ssoExcludedHosts'] = array(
576
    $form['sso']['ssoExcludedHosts'] = [
559 577
      '#type' => 'textarea',
560 578
      '#title' => t('SSO Excluded Hosts'),
561 579
      '#description' => t($this->ssoExcludedHostsDescription),
562 580
      '#default_value' => $this->arrayToLines($this->ssoExcludedHosts),
563
      '#disabled' => (boolean)(!$this->ssoEnabled),
564
    );
581
      '#disabled' => (boolean) (!$this->ssoEnabled),
582
    ];
565 583

  
566
    $form['submit'] = array(
584
    $form['submit'] = [
567 585
      '#type' => 'submit',
568 586
      '#value' => 'Save',
569
    );
587
    ];
570 588

  
571
  return $form;
572
}
589
    return $form;
590
  }
573 591

  
574
/**
575
 * validate form, not object
576
 */
577
  public function drupalFormValidate($values)  {
592
  /**
593
   * Validate form, not object.
594
   */
595
  public function drupalFormValidate($values) {
578 596

  
579 597
    $this->populateFromDrupalForm($values);
580 598

  
......
583 601
    return $errors;
584 602
  }
585 603

  
586
/**
587
 * validate object, not form
588
 */
604
  /**
605
   * Validate object, not form.
606
   */
589 607
  public function validate() {
590
    $errors = array();
608
    $errors = [];
591 609

  
592 610
    $enabled_servers = ldap_servers_get_servers(NULL, 'enabled');
593 611
    if ($this->ssoEnabled) {
594 612
      foreach ($this->sids as $sid => $discard) {
595 613
        if ($enabled_servers[$sid]->bind_method == LDAP_SERVERS_BIND_METHOD_USER || $enabled_servers[$sid]->bind_method == LDAP_SERVERS_BIND_METHOD_ANON_USER) {
596
          $methods = array(
614
          $methods = [
597 615
            LDAP_SERVERS_BIND_METHOD_USER => 'Bind with Users Credentials',
598 616
            LDAP_SERVERS_BIND_METHOD_ANON_USER => 'Anonymous Bind for search, then Bind with Users Credentials',
599
          );
600
          $tokens = array(
617
          ];
618
          $tokens = [
601 619
            '!edit' => l($enabled_servers[$sid]->name, LDAP_SERVERS_INDEX_BASE_PATH . '/edit/' . $sid),
602 620
            '%sid' => $sid,
603 621
            '%bind_method' => $methods[$enabled_servers[$sid]->bind_method],
604
          );
622
          ];
605 623

  
606 624
          $errors['ssoEnabled'] = t('Single Sign On is not valid with the server !edit (id=%sid) because that server configuration uses %bind_method.  Since the user\'s credentials are never available to this module with single sign on enabled, there is no way for the ldap module to bind to the ldap server with credentials.', $tokens);
607 625
        }
......
610 628
    return $errors;
611 629
  }
612 630

  
631
  /**
632
   *
633
   */
613 634
  protected function populateFromDrupalForm($values) {
614 635

  
615
    $this->authenticationMode = ($values['authenticationMode']) ? (int)$values['authenticationMode'] : NULL;
636
    $this->authenticationMode = ($values['authenticationMode']) ? (int) $values['authenticationMode'] : NULL;
616 637
    $this->sids = $values['authenticationServers'];
617 638
    $this->allowOnlyIfTextInDn = $this->linesToArray($values['allowOnlyIfTextInDn']);
618 639
    $this->excludeIfTextInDn = $this->linesToArray($values['excludeIfTextInDn']);
619 640
    $this->allowTestPhp = $values['allowTestPhp'];
620
    $this->loginUIUsernameTxt = ($values['loginUIUsernameTxt']) ? (string)$values['loginUIUsernameTxt'] : NULL;
621
    $this->loginUIPasswordTxt = ($values['loginUIPasswordTxt']) ? (string)$values['loginUIPasswordTxt'] : NULL;
622
    $this->ldapUserHelpLinkUrl = ($values['ldapUserHelpLinkUrl']) ? (string)$values['ldapUserHelpLinkUrl'] : NULL;
623
    $this->ldapUserHelpLinkText = ($values['ldapUserHelpLinkText']) ? (string)$values['ldapUserHelpLinkText'] : NULL;
624
    $this->excludeIfNoAuthorizations = ($values['excludeIfNoAuthorizations']) ? (int)$values['excludeIfNoAuthorizations'] : NULL;
625
    $this->emailOption  = ($values['emailOption']) ? (int)$values['emailOption'] : NULL;
626
    $this->emailUpdate  = ($values['emailUpdate']) ? (int)$values['emailUpdate'] : NULL;
627
    $this->passwordOption  = ($values['passwordOption']) ? (int)$values['passwordOption'] : NULL;
641
    $this->loginUIUsernameTxt = ($values['loginUIUsernameTxt']) ? (string) $values['loginUIUsernameTxt'] : NULL;
642
    $this->loginUIPasswordTxt = ($values['loginUIPasswordTxt']) ? (string) $values['loginUIPasswordTxt'] : NULL;
643
    $this->ldapUserHelpLinkUrl = ($values['ldapUserHelpLinkUrl']) ? (string) $values['ldapUserHelpLinkUrl'] : NULL;
644
    $this->ldapUserHelpLinkText = ($values['ldapUserHelpLinkText']) ? (string) $values['ldapUserHelpLinkText'] : NULL;
645
    $this->excludeIfNoAuthorizations = ($values['excludeIfNoAuthorizations']) ? (int) $values['excludeIfNoAuthorizations'] : NULL;
646
    $this->emailOption = ($values['emailOption']) ? (int) $values['emailOption'] : NULL;
647
    $this->emailUpdate = ($values['emailUpdate']) ? (int) $values['emailUpdate'] : NULL;
648
    $this->passwordOption = ($values['passwordOption']) ? (int) $values['passwordOption'] : NULL;
628 649
    $this->ssoExcludedPaths = $this->linesToArray($values['ssoExcludedPaths']);
629 650
    $this->ssoExcludedHosts = $this->linesToArray($values['ssoExcludedHosts']);
630
    $this->ssoRemoteUserStripDomainName = ($values['ssoRemoteUserStripDomainName']) ? (int)$values['ssoRemoteUserStripDomainName'] : NULL;
631
    $this->seamlessLogin = ($values['seamlessLogin']) ? (int)$values['seamlessLogin'] : NULL;
632
    $this->ssoNotifyAuthentication = ($values['ssoNotifyAuthentication']) ? (int)$values['ssoNotifyAuthentication'] : NULL;
633
    $this->cookieExpire = ($values['cookieExpire']) ? (int)$values['cookieExpire'] : NULL;
634
    $this->ldapImplementation = ($values['ldapImplementation']) ? (string)$values['ldapImplementation'] : NULL;
651
    $this->ssoRemoteUserStripDomainName = ($values['ssoRemoteUserStripDomainName']) ? (int) $values['ssoRemoteUserStripDomainName'] : NULL;
652
    $this->seamlessLogin = ($values['seamlessLogin']) ? (int) $values['seamlessLogin'] : NULL;
653
    $this->ssoNotifyAuthentication = ($values['ssoNotifyAuthentication']) ? (int) $values['ssoNotifyAuthentication'] : NULL;
654
    $this->cookieExpire = ($values['cookieExpire']) ? (int) $values['cookieExpire'] : NULL;
655
    $this->ldapImplementation = ($values['ldapImplementation']) ? (string) $values['ldapImplementation'] : NULL;
635 656
    $this->emailTemplateHandling = ($values['emailTemplateHandling']) ? (int) $values['emailTemplateHandling'] : NULL;
636 657
    $this->emailTemplate = ($values['emailTemplate']) ? $values['emailTemplate'] : '';
637 658
    $this->templateUsagePromptUser = ($values['templateUsagePromptUser']) ? 1 : 0;
......
641 662
    $this->templateUsageNeverUpdate = ($values['templateUsageNeverUpdate']) ? 1 : 0;
642 663
  }
643 664

  
665
  /**
666
   *
667
   */
644 668
  public function drupalFormSubmit($values) {
645 669

  
646 670
    $this->populateFromDrupalForm($values);
......
655 679

  
656 680
  }
657 681

  
682
  /**
683
   *
684
   */
658 685
  protected function arrayToLines($array) {
659
        $lines = "";
660
        if (is_array($array)) {
661
          $lines = join("\n", $array);
662
        }
663
        elseif (is_array(@unserialize($array))) {
664
          $lines = join("\n", unserialize($array));
665
        }
666
        return $lines;
667
      }
686
    $lines = "";
687
    if (is_array($array)) {
688
      $lines = join("\n", $array);
689
    }
690
    elseif (is_array(@unserialize($array))) {
691
      $lines = join("\n", unserialize($array));
692
    }
693
    return $lines;
694
  }
668 695

  
696
  /**
697
   *
698
   */
669 699
  protected function linesToArray($lines) {
670 700
    $lines = trim($lines);
671 701

  
......
676 706
      }
677 707
    }
678 708
    else {
679
      $array = array();
709
      $array = [];
680 710
    }
681 711
    return $array;
682 712
  }

Formats disponibles : Unified diff