forked from typhonius/simplesamlphp_auth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
simplesamlphp_auth.install
97 lines (86 loc) · 2.68 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
95
96
97
<?php
/**
* @file
* the install file for the simplesamlphp_auth module
*/
/**
* Implements hook_schema().
*/
function simplesamlphp_auth_schema() {
$schema['simplesamlphp_auth_authmap'] = array(
'description' => 'Stores SimpleSAMLphp authentication mapping.',
'fields' => array(
'aid' => array(
'description' => 'Primary Key: Unique authmap ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => "User's {users}.uid.",
),
'authname' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Unique authentication name.',
),
),
'unique keys' => array(
'authname' => array('authname'),
),
'primary key' => array('aid'),
'foreign keys' => array(
'user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function simplesamlphp_auth_install() {
user_role_revoke_permissions(DRUPAL_AUTHENTICATED_RID, 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', 0);
$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 == '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;
}