-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimplesamlphp_auth.module
702 lines (604 loc) · 22.9 KB
/
simplesamlphp_auth.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
<?php
/**
* @file
* simpleSAMLphp authentication module for Drupal.
*
* This authentication module is based on the shibboleth authentication module,
* with changes to adapt to use simpleSAMLphp.
*
* ISSUES and TODOs:
* ISSUE: User is always dropped on user page after login, instead of where
* they were when they clicked "Federated Log In". Because of this, deep
* linking to access controlled content does not work. Usability would
* be considerably increased if this were resolved.
* FYI: Drupal now requires knowledge of the local user password in order to
* change e-mail address, etc. This could be an issue for users of
* accounts that are auto-provisioned by this module, though Drupal does
* give users the ability to reset their password to something they know
* via the Request new password feature.
* KLUDGE: Drupal does not kill the session on logout, even with
* drupal_session_destroy_uid(), so I had to use session_destroy().
* @todo Rework the default login limitation logic to use a drupal permission
* rather than a list of UIDs.
* @todo When denying access because the administrator has chosen not to allow
* the module to register/create accounts, the user is told to contact
* the administrator; the message should provide the contact information.
* ISSUE: Until Drupal issue #754560 is resolved users will not see logout
* notices.
*/
/**
* Implements hook_menu().
*/
function simplesamlphp_auth_menu() {
$login_path = variable_get('simplesamlphp_auth_login_path', 'saml_login');
$items = array();
$items['admin/config/people/simplesamlphp_auth'] = array(
'title' => 'SimpleSAMLphp Auth Settings',
'description' => 'Control the various settings of the simpleSAMLphp authentication module',
'page callback' => 'drupal_get_form',
'page arguments' => array('simplesamlphp_auth_settings_basic'),
'access arguments' => array('administer simpleSAMLphp authentication'),
'file' => 'simplesamlphp_auth.admin.inc',
'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
);
$items['admin/config/people/simplesamlphp_auth/basic'] = array(
'title' => 'Basic settings',
'description' => 'Control the various settings of the simpleSAMLphp authentication module',
'page callback' => 'drupal_get_form',
'page arguments' => array('simplesamlphp_auth_settings_basic'),
'access arguments' => array('administer simpleSAMLphp authentication'),
'file' => 'simplesamlphp_auth.admin.inc',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/config/people/simplesamlphp_auth/sync'] = array(
'title' => 'User info and syncing',
'description' => 'Control the various settings of the simpleSAMLphp authentication module',
'page callback' => 'drupal_get_form',
'page arguments' => array('simplesamlphp_auth_settings_sync'),
'access arguments' => array('administer simpleSAMLphp authentication'),
'file' => 'simplesamlphp_auth.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/config/people/simplesamlphp_auth/local'] = array(
'title' => 'Local authentication',
'description' => 'Configure local only authentication options',
'page callback' => 'drupal_get_form',
'page arguments' => array('simplesamlphp_auth_settings_local'),
'access arguments' => array('administer simpleSAMLphp authentication'),
'file' => 'simplesamlphp_auth.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items[$login_path] = array(
'title' => 'Logon to the site',
'description' => 'Provides a site login page',
'page callback' => 'simplesamlphp_auth_loginpage',
'access callback' => '_simplesamlphp_auth_isEnabled',
'file' => 'simplesamlphp_auth.pages.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_menu_site_status_alter().
*/
function simplesamlphp_auth_menu_site_status_alter(&$menu_site_status, $path) {
// Allow access to authenticate even if site is in offline mode.
$login_path = variable_get('simplesamlphp_auth_login_path', 'saml_login');
if ($menu_site_status == MENU_SITE_OFFLINE && user_is_anonymous() && $path == $login_path) {
$menu_site_status = MENU_SITE_ONLINE;
}
}
/**
* Implements hook_help().
*/
function simplesamlphp_auth_help($path, $arg) {
switch ($path) {
case 'admin/config/people/simplesamlphp_auth':
$output = '<p>' . t('This module integrates Drupal with a SimpleSAMLphp Service Point (SP), effectively federating Drupal.') . '</p>';
return $output;
}
}
/**
* Implements hook_permission().
*/
function simplesamlphp_auth_permission() {
return array(
'administer simpleSAMLphp authentication' => array(
'title' => t('Administer simpleSAMLphp authentication'),
'restrict access' => TRUE,
),
'change saml authentication setting' => array(
'title' => t('Change SAML authentication setting for individual accounts'),
'description' => t('Allow users to enable or disable SAML authentication per user on user edit forms.'),
'restrict access' => TRUE,
),
);
}
/**
* Loads simplesamlphp class and initializes global variables.
*/
function _simplesaml_auth_autoload() {
if (!_simplesamlphp_auth_isEnabled()) {
return FALSE;
}
global $_simplesamlphp_auth_as;
global $_simplesamlphp_auth_saml_attributes;
global $_simplesamlphp_auth_saml_config;
global $_simplesamlphp_auth_saml_version;
// Get the simplesamlphp session.
if (!class_exists('SimpleSAML_Configuration')) {
// Register SimpleSAMLphp autoloader (only if needed)
$basedir = variable_get('simplesamlphp_auth_installdir', '/usr/share/simplesamlphp');
if (file_exists($basedir . '/lib/_autoload.php')) {
require_once $basedir . '/lib/_autoload.php';
}
else {
return FALSE;
}
}
$_simplesamlphp_auth_saml_config = SimpleSAML_Configuration::getInstance();
$_simplesamlphp_auth_saml_version = $_simplesamlphp_auth_saml_config->getVersion();
// Load simpleSAMLphp, configuration and metadata.
$_simplesamlphp_auth_as = new SimpleSAML_Auth_Simple(variable_get('simplesamlphp_auth_authsource', 'default-sp'));
$_simplesamlphp_auth_saml_attributes = $_simplesamlphp_auth_as->getAttributes();
return TRUE;
}
/**
* Implements hook_init().
*
* If the user has logged out via SAML, log out the user in Drupal as well.
*/
function simplesamlphp_auth_init() {
if (user_is_anonymous()) {
return FALSE;
}
if (!_simplesaml_auth_autoload()) {
return FALSE;
}
global $user;
global $_simplesamlphp_auth_as;
global $_simplesamlphp_auth_saml_attributes;
// Get users that are allowed default login.
$allowed_default_login_users = variable_get('simplesamlphp_auth_allowdefaultloginusers', '');
$allowed_uids = explode(",", $allowed_default_login_users);
// Get roles that are allowed default login.
$allowed_default_login_roles = variable_get('simplesamlphp_auth_allowdefaultloginroles', array());
// Check if user is allowed default login.
$user_allowed_default_login_roles = array_intersect_key($user->roles, $allowed_default_login_roles);
if (variable_get('simplesamlphp_auth_allowdefaultlogin', TRUE) &&
(in_array($user->uid, $allowed_uids) || !empty($user_allowed_default_login_roles))) {
$user_allowed_default_login = TRUE;
}
// Logs out user if not SAML authenticated and not allowed default login.
if (!$_simplesamlphp_auth_as->isAuthenticated() && !$user_allowed_default_login) {
module_load_include('pages.inc', 'user');
user_logout();
}
}
/**
* Implements hook_user_insert().
*/
function simplesamlphp_auth_user_insert(&$edit, $account, $category = NULL) {
global $_simplesamlphp_auth_as;
global $_simplesamlphp_auth_saml_attributes;
if (!_simplesaml_auth_autoload()) {
// Exit without initializing.
return;
}
if ($category == 'account') {
// If user registration has a valid session...
if ($_simplesamlphp_auth_as->isAuthenticated() && _simplesamlphp_auth_get_authname() == $account->init) {
// Get name from default attributes.
try {
if (variable_get('simplesamlphp_auth_debug', 0)) {
watchdog('simplesamlphp_auth', 'Registering user [%acctname]', array('%acctname' => $account->name), WATCHDOG_DEBUG);
}
$account->name = _simplesamlphp_auth_get_default_name($account->uid);
}
catch (Exception $e) {
drupal_set_message(t('Your user name was not provided by your identity provider (IDP).'), "error");
watchdog('simplesamlphp_auth', $e->getMessage(), NULL, WATCHDOG_CRITICAL);
}
module_load_include('inc', 'simplesamlphp_auth');
// Update username and email address.
// @todo Make this conditional.
_simplesaml_auth_user_update($account);
if (module_exists('rules')) {
rules_invoke_all('simplesamlphp_auth_rules_event_register', $account);
}
// Reload the user object to ensure that all properties are populated.
$user = user_load($account->uid);
_simplesaml_auth_user_login($user);
}
}
}
/**
* Implements hook_user_logout().
*/
function simplesamlphp_auth_user_logout($account) {
global $user;
global $_simplesamlphp_auth_as;
global $_simplesamlphp_auth_saml_attributes;
global $base_url;
_simplesaml_auth_autoload();
if (!empty($_simplesamlphp_auth_saml_attributes)) {
$config = SimpleSAML_Configuration::getInstance();
// KLUDGE: for some reason Drupal is not killing the session, even if I
// were to call drupal_session_destroy_uid() here.
session_destroy();
$gotourl = base_path();
if (variable_get('simplesamlphp_auth_logoutgotourl', '')) {
$gotourl = variable_get('simplesamlphp_auth_logoutgotourl', '');
}
// Allow modules to alter $gotourl.
drupal_alter('simplesamlphp_auth_logout_gotourl', $gotourl, $account);
$_simplesamlphp_auth_as->logout($gotourl);
}
}
/**
* Implements hook_user_delete().
*/
function simplesamlphp_auth_user_delete($account) {
db_delete('authmap')
->condition('uid', $account->uid)
->condition('authname', $account->name)
->execute();
}
/**
* Implements hook_form_alter().
*/
function simplesamlphp_auth_form_alter(&$form, $form_state, $form_id) {
if (!_simplesamlphp_auth_isEnabled()) {
// Exit without executing.
return;
}
$is_user_profile_account_form = (($form_id == 'user_profile_form') && ($form['#user_category'] == 'account'));
$login_path = variable_get('simplesamlphp_auth_login_path', 'saml_login');
$login_name = variable_get('simplesamlphp_auth_login_link_display_name', t('Federated Log In'));
$destination = drupal_get_destination();
$link = l($login_name, $login_path, array('query' => $destination));
// Add SAML login link to user login form.
if ($form_id == 'user_login_block' || $form_id == 'user_account_form') {
$links = $form['links']['#markup'];
$links = str_replace('</ul>', '<li class="saml">' . $link . '</li></ul>', $links);
$form['links']['#markup'] = $links;
}
if ($form_id == 'user_login') {
$form['links']['#markup'] = $link;
}
if (($form_id == 'user_register_form' || $is_user_profile_account_form) && user_access('change saml authentication setting')) {
$form['saml'] = array(
'#type' => 'checkbox',
'#title' => t('Enable this user to leverage SAML authentication'),
'#default_value' => $form_id == 'user_register_form' ? TRUE : (bool) user_get_authmaps($form['#user']->name),
);
$form['#submit'][] = 'simplesaml_auth_user_profile_form_submit';
}
// If the user has a simplesamlphp_auth authmap record, then don't require
// them to know their Drupal password. This will allow them to change their
// e-mail address, and set a Drupal password if they want to (and are
// allowed).
if ($is_user_profile_account_form && (isset($form['#user']->init) && $form['#user']->init) && _simplesaml_auth_user_has_authmap($form['#user']->name)) {
unset($form['account']['current_pass']);
unset($form['account']['current_pass_required_values']);
$form['#validate'] = array_diff($form['#validate'], array('user_validate_current_pass'));
// If the user is a simplesamlphp_auth user and is NOT allowed to set their
// Drupal password, remove the fields from the form.
if (!variable_get('simplesamlphp_auth_allowsetdrupalpwd')) {
unset($form['account']['pass']);
}
}
}
/**
* Submit callback to enable SAML authentication for a given user.
*/
function simplesaml_auth_user_profile_form_submit(&$form, $form_state) {
$values = $form_state['values'];
if (isset($values['saml'])) {
// Enter this username into the authmap table.
if ($values['saml']) {
db_merge('authmap')
->key(array(
'uid' => $values['uid'],
'module' => 'simplesamlphp_auth',
))
->fields(array(
'authname' => $values['name'],
))
->execute();
}
// Remove this username from the authmap table.
else {
db_delete('authmap')
->condition('uid', $values['uid'])
->execute();
}
}
}
/**
* Implements hook_block_view().
*/
function simplesamlphp_auth_block_view($delta = '') {
if (!_simplesaml_auth_autoload()) {
// Exit without executing.
return;
}
$block = array();
switch ($delta) {
case 0:
$block = array(
'subject' => t('simpleSAMLphp login'),
'content' => _simplesamlphp_auth_generate_block_text(),
);
break;
}
return $block;
}
/**
* Implements hook_block_info().
*/
function simplesamlphp_auth_block_info() {
$block = array(
array(
'info' => t('simpleSAMLphp authentication'),
'cache' => DRUPAL_NO_CACHE,
),
);
return $block;
}
/****************************************************************************
* Private functions ********************************************************
****************************************************************************/
/**
* Checks if authentication via SimpleSAMLphp should be activated.
*
* @param bool $show_inactive_msg
* Whether to display the "module not activated" message
*
* @return bool
* TRUE if simplesamlphp_auth is enabled.
*/
function _simplesamlphp_auth_isEnabled($show_inactive_msg = FALSE) {
global $user;
$failure = NULL;
$is_activated = variable_get('simplesamlphp_auth_activate');
$basedir = variable_get('simplesamlphp_auth_installdir', '/usr/share/simplesamlphp');
if ($is_activated) {
// Make sure we know where SimpleSAMLphp is.
if (!file_exists($basedir)) {
$failure = t('SimpleSAMLphp could not be found at %basedir . The simplesamlphp_auth module cannot function until the path to the local SimpleSAMLphp instance is configured.', array('%basedir' => $basedir));
watchdog('simplesamlphp_auth', $failure, NULL, WATCHDOG_WARNING);
}
}
else {
$failure = t('SimpleSAMLphp auth is not yet activated.');
}
// If there were no failures, then it should be activated.
if (!$failure) {
return TRUE;
}
else {
// Communicate but don't be too annoying.
if ($show_inactive_msg && (1 == $user->uid || user_access('access administration pages')) && (preg_match('/admin\/people/', request_uri()) || preg_match('/admin\/modules/', request_uri()) || preg_match('/admin\/config/', request_uri()))) {
drupal_set_message($failure);
}
}
return FALSE;
}
/**
* Gets the authname attribute from the SAML assertion.
*
* @return string
* The authname attribute.
*
* @throws Exception
* Throws an exception if no valid unique id attribute is set in SAML session.
*/
function _simplesamlphp_auth_get_authname() {
global $_simplesamlphp_auth_saml_attributes;
$authname = '';
// Check if valid local session exists.
if (isset($_simplesamlphp_auth_saml_attributes)) {
if (variable_get('simplesamlphp_auth_debug', 0)) {
watchdog('simplesamlphp_auth', '_simplesamlphp_auth_get_authname: Valid local SAML session exists', NULL, WATCHDOG_DEBUG);
}
if (isset($_simplesamlphp_auth_saml_attributes[variable_get('simplesamlphp_auth_unique_id', 'eduPersonPrincipalName')])) {
$authname = $_simplesamlphp_auth_saml_attributes[variable_get('simplesamlphp_auth_unique_id', 'eduPersonPrincipalName')][0];
}
else {
throw new Exception(t('Error in simplesamlphp_auth.module: no valid unique id attribute set.'));
}
}
return $authname;
}
/**
* Gets the default name attribute from the SAML assertion.
*
* @return string
* The name attribute.
*/
function _simplesamlphp_auth_get_default_name($account) {
global $_simplesamlphp_auth_as;
global $_simplesamlphp_auth_saml_attributes;
$default_name = '';
// Check if valid local session exists..
if ($_simplesamlphp_auth_as->isAuthenticated()) {
$auth_user_name_attr = variable_get('simplesamlphp_auth_user_name', 'eduPersonPrincipalName');
if ((!isset($_simplesamlphp_auth_saml_attributes[$auth_user_name_attr])) ||
(!isset($_simplesamlphp_auth_saml_attributes[$auth_user_name_attr][0])) ||
($_simplesamlphp_auth_saml_attributes[$auth_user_name_attr][0] == '')
) {
throw new Exception(t('There was no set attribute named "%auth_user_name_attr" returned for user %uid.',
array(
'%auth_user_name_attr' => $auth_user_name_attr,
'%uid' => $account,
)));
}
$default_name = $_simplesamlphp_auth_saml_attributes[$auth_user_name_attr][0];
}
return $default_name;
}
/**
* Gets the mail attribute.
*
* @return string
* The mail attribute.
*/
function _simplesamlphp_auth_get_mail() {
global $_simplesamlphp_auth_as;
global $_simplesamlphp_auth_saml_attributes;
$mail_address = '';
// Check if valid local session exists..
if ($_simplesamlphp_auth_as->isAuthenticated()) {
if (isset($_simplesamlphp_auth_saml_attributes[variable_get('simplesamlphp_auth_mailattr', 'mail')])) {
$mail_address = $_simplesamlphp_auth_saml_attributes[variable_get('simplesamlphp_auth_mailattr', 'mail')][0];
}
else {
throw new Exception(t('Error in simplesamlphp_auth.module: No valid mail attribute set.'));
}
}
return $mail_address;
}
/**
* Generates the text for the log in block.
*/
function _simplesamlphp_auth_generate_block_text() {
global $_simplesamlphp_auth_as;
$block_content = '';
global $user;
if (!_simplesamlphp_auth_isEnabled()) {
// Exit without executing.
return;
}
// Check if valid local session exists..
if ($_simplesamlphp_auth_as->isAuthenticated()) {
$block_content .= '<p>' . t('Logged in as: @username', array('@username' => $user->name))
. '<br />' . l(t('Log Out'), 'user/logout') . '</p>';
}
else {
$login_path = variable_get('simplesamlphp_auth_login_path', 'saml_login');
$login_name = variable_get('simplesamlphp_auth_login_link_display_name', t('Federated Log In'));
$block_content .= '<p>' . l($login_name, $login_path) . '</p>';
}
return $block_content;
}
/**
* Evaluates a role rule.
*
* The rules work as follows:
* = does an exact match on an attribute and will iterate over array values if
* the array is multivalued.
* @= matches the domain portion of an email address. It assumes the attribute
* is a string, and will not iterate over an array (but take the first value).
* ~= does a partial string match on the attribute, and does iterate over
* multiple values, returning true if any of the values match.
*
* @param array $roleruleevaluation
* An array containing the role rule to evaluate.
* @param array $attributes
* An array containing the identity attributes.
*
* @return array
* An array containing role value and the attribute, or FALSE.
*/
function _simplesamlphp_auth_evaulaterolerule($roleruleevaluation, $attributes) {
if (variable_get('simplesamlphp_auth_debug', 0)) {
watchdog('simplesamlphp_auth', 'Evaluate rule (key=%key,operator=%op,value=%val)', array(
'%key' => $roleruleevaluation[0],
'%op' => $roleruleevaluation[1],
'%val' => $roleruleevaluation[2],
), WATCHDOG_DEBUG);
}
if (!array_key_exists($roleruleevaluation[0], $attributes)) {
return FALSE;
}
$attribute = $attributes[$roleruleevaluation[0]];
switch ($roleruleevaluation[1]) {
case '=':
return in_array($roleruleevaluation[2], $attribute);
case '@=':
$dc = explode('@', $attribute[0]);
if (count($dc) != 2) {
return FALSE;
}
return $dc[1] == $roleruleevaluation[2];
case '~=':
foreach ($attribute as $subattr) {
$pos = strpos($subattr, $roleruleevaluation[2]);
if ($pos !== FALSE) {
return TRUE;
}
}
return FALSE;
}
return FALSE;
}
/**
* Performs role population.
*
* @param array $rolemap
* A string containing the role map.
*
* @return array
* An array containing user's roles.
*/
function _simplesamlphp_auth_rolepopulation($rolemap) {
global $_simplesamlphp_auth_as;
global $_simplesamlphp_auth_saml_attributes;
$roles = array();
if (variable_get('simplesamlphp_auth_debug', 0)) {
watchdog('simplesamlphp_auth', 'Rolemap: %rolemap', array('%rolemap' => $rolemap), WATCHDOG_DEBUG);
}
// Check if valid local session exists..
if (!empty($rolemap) && $_simplesamlphp_auth_as->isAuthenticated()) {
$attributes = $_simplesamlphp_auth_saml_attributes;
if (variable_get('simplesamlphp_auth_debug', 0)) {
watchdog('simplesamlphp_auth', 'Evaluate rolemap: %rolemap', array('%rolemap' => $rolemap), WATCHDOG_DEBUG);
}
$rolerules = explode('|', $rolemap);
foreach ($rolerules as $rolerule) {
if (variable_get('simplesamlphp_auth_debug', 0)) {
watchdog('simplesamlphp_auth', 'Evaluate role rule: %rolerule', array('%rolerule' => $rolerule), WATCHDOG_DEBUG);
}
$roleruledecompose = explode(':', $rolerule, 2);
$roleid = $roleruledecompose[0];
$roleruleevaluations = explode(';', $roleruledecompose[1]);
$addnew = TRUE;
foreach ($roleruleevaluations as $roleruleevaluation) {
if (variable_get('simplesamlphp_auth_debug', 0)) {
watchdog('simplesamlphp_auth', 'Evaluate role evaulation: %roleruleeval', array('%roleruleeval' => $roleruleevaluation), WATCHDOG_DEBUG);
}
$roleruleevaluationdc = str_getcsv($roleruleevaluation);
if (!_simplesamlphp_auth_evaulaterolerule($roleruleevaluationdc, $attributes)) {
$addnew = FALSE;
}
}
if ($addnew) {
$roles[$roleid] = $roleid;
if (variable_get('simplesamlphp_auth_debug', 0)) {
watchdog('simplesamlphp_auth', 'Add new role: %roleid', array('%roleid' => $roleid), WATCHDOG_DEBUG);
}
}
}
}
drupal_alter('simplesamlphp_auth_user_roles', $roles);
return $roles;
}
/**
* See if the user has an authmap record for simplesamlphp_auth.
*/
function _simplesaml_auth_user_has_authmap($authname) {
$authmaps = user_get_authmaps($authname);
$return = 0;
if (is_array($authmaps)) {
$return = in_array('simplesamlphp_auth', array_keys($authmaps));
}
return $return;
}
/**
* Logs out a user who has an active Drupal session but not with simpleSAML.
*/
function _simplesamlphp_auth_destroy_drupal_session() {
module_load_include('pages.inc', 'user');
user_logout();
}