-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuiowa_auth.install
92 lines (74 loc) · 2.21 KB
/
uiowa_auth.install
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
<?php
/**
* @file
* Install tasks.
*/
use Drupal\user\Entity\User;
/**
* Flush all caches to rebuild service container.
*/
function uiowa_auth_update_8001() {
drupal_flush_all_caches();
}
/**
* Update active configuration to reflect role mapping data structure change.
*/
function uiowa_auth_update_8002() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('uiowa_auth.settings');
$mappings = $config->get('role_mappings');
if (!array_key_exists(0, $mappings)) {
$new = [];
foreach ($mappings as $rid => $dn) {
$new[] = "{$rid}|{$dn}";
\Drupal::logger('uiowa_auth')->notice('Updated role mapping configuration for @mapping.', [
'@mapping' => "{$rid} -> {$dn}",
]);
}
$config
->set('role_mappings', $new)
->save();
}
}
/**
* Update configuration to use new rid|attr|value format.
*/
function uiowa_auth_update_8003() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('uiowa_auth.settings');
$attr = $config->get('member_of_attribute');
$mappings = [];
foreach ($config->get('role_mappings') as $mapping) {
[$rid, $value] = explode('|', $mapping);
$mappings[] = "{$rid}|{$attr}|{$value}";
}
$config->set('role_mappings', $mappings);
$config->clear('member_of_attribute');
$config->save();
}
/**
* Dedupe role mapping data in authmap table.
*/
function uiowa_auth_update_8004() {
/** @var \Drupal\externalauth\Authmap $authmap */
$authmap = \Drupal::service('externalauth.authmap');
foreach (User::loadMultiple() as $user) {
$data = $authmap->getAuthData($user->id(), 'samlauth');
if ($data) {
$authname = $data['authname'];
// Allowed classes disabled post-update as per PHPCS.
$data = unserialize($data['data'], ['allowed_classes' => FALSE]);
$deduped = [
'uiowa_auth_mappings' => [],
];
if (isset($data['uiowa_auth_mappings'])) {
foreach ($data['uiowa_auth_mappings'] as $rid) {
if (!in_array($rid, $deduped['uiowa_auth_mappings'])) {
$deduped['uiowa_auth_mappings'][] = $rid;
}
}
$authmap->save($user, 'samlauth', $authname, $deduped);
}
}
}
}