-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplesamlphp_auth.install
94 lines (80 loc) · 2.75 KB
/
simplesamlphp_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
93
94
<?php
/**
* @file
* The install file for the simplesamlphp_auth module.
*/
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Site\Settings;
/**
* Implements hook_install().
*/
function simplesamlphp_auth_install() {
user_role_revoke_permissions(AccountInterface::AUTHENTICATED_ROLE, array('change own password'));
// Disable the open registration to the site and store the original setting.
$user_settings = \Drupal::configFactory()->getEditable('user.settings');
$config = \Drupal::configFactory()->getEditable('simplesamlphp_auth.settings');
$config->set('user_register_original', $user_settings->get('register'));
$user_settings->set('register', 'admin_only');
$user_settings->save();
$config->save();
}
/**
* Implements hook_uninstall().
*/
function simplesamlphp_auth_uninstall() {
// Restore the original user registration directive.
$user_settings = \Drupal::configFactory()->getEditable('user.settings');
$config = \Drupal::config('simplesamlphp_auth.settings');
$user_settings->set('register', $config->get('user_register_original'));
$user_settings->save();
}
/**
* Implements hook_requirements().
*/
function simplesamlphp_auth_requirements($phase) {
$requirements = array();
if ($phase == 'install') {
simplesamlphp_auth_check_library();
if (!class_exists('SimpleSAML_Configuration')) {
$requirements['simplesamlphp_library'] = [
'description' => t('SimpleSAMLphp module requires the simplesamlphp library. See README file for installation instructions.'),
'severity' => REQUIREMENT_ERROR,
];
}
}
if ($phase == 'runtime') {
$config = \Drupal::config('simplesamlphp_auth.settings');
if (!$config->get('activate')) {
$requirements['simplesamlphp_auth'] = array(
'severity' => REQUIREMENT_INFO,
'title' => 'simpleSAMLphp_auth',
'value' => t('SimpleSAMLphp authentication is NOT activated'),
'description' => t('It can be activated on the <a href="@config_page">configuration page</a>.', array('@config_page' => \Drupal::url('simplesamlphp_auth.admin_settings'))),
);
}
}
return $requirements;
}
/**
* Check if the SimpleSAMLphp library can be found.
*
* Fallback for when the library was not found via Composer.
*/
function simplesamlphp_auth_check_library() {
if (!class_exists('SimpleSAML_Configuration')) {
$dir = Settings::get('simplesamlphp_dir');
include_once $dir . '/lib/_autoload.php';
}
}
/**
* Rebuild simplesamlphp_auth_event_subscriber service.
*/
function simplesamlphp_auth_update_8001() {
\Drupal::service('kernel')->invalidateContainer();
}
/**
* Rebuild router for changed admin form.
*/
function simplesamlphp_auth_update_8002() {
\Drupal::service('router.builder')->rebuild();
}