Skip to content

Commit 581955d

Browse files
committedJun 13, 2019
Add support for groups. Add support for log extra info: Logins, Change of user systemrole
1 parent 6efec8e commit 581955d

10 files changed

+64
-7
lines changed
 

‎README.txt

100755100644
File mode changed.

‎course_and_role_mapping.php

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
$regs = saml_hook_get_course_info($course);
4444
if ($regs) {
4545
list($match, $country, $domain, $courseid, $period, $role, $status) = $regs;
46+
$group = null;
47+
if (isset($regs[7])) {
48+
$group = $regs[7];
49+
}
4650

4751
if (!empty($courseid)) {
4852
foreach ($rolemapping as $shortname => $values) {
@@ -71,6 +75,7 @@
7175
'period' => $period,
7276
'role' => $mappedrole,
7377
'status' => $status,
78+
'group' => $group
7479
];
7580
if (!$anycourseactive && $status == 'active') {
7681
$anycourseactive = true;

‎custom_hook.php

+11
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ function saml_hook_post_user_created($user, $saml_attributes = []) {
161161
4 - period period of the course
162162
5 - role role to be mappend with moodle role
163163
6 - status 'active' | 'inactive'
164+
7 - group the group inside the course
164165
165166
The auth/saml plugin save those data that will be available
166167
for the enrol/saml plugin.
@@ -180,6 +181,7 @@ function saml_hook_post_user_created($user, $saml_attributes = []) {
180181
$regs[4] = $matches[2]; // period
181182
$regs[5] = $matches[3]; // role
182183
$regs[6] = $matches[4]; // status
184+
$regs[7] = null; // group
183185
}
184186
*/
185187
function saml_hook_get_course_info($course) {
@@ -191,5 +193,14 @@ function saml_hook_get_course_info($course) {
191193
$regs = $matches;
192194
}
193195

196+
// Example retreving course from course_id
197+
// because course_id is like: mat1-t1, mat1-t2 and t1 and t2 are
198+
// groups of course mat1
199+
// $course_id = $regs[3];
200+
// $data = explode("-", $course_id);
201+
// if (isset($data[1])) {
202+
// $regs[7] = $data[1];
203+
// }
204+
194205
return $regs;
195206
}

‎error.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ function auth_saml_log_error($msg, $logfile) {
108108
}
109109

110110

111-
function auth_saml_decorate_log($msg) {
112-
return $msg = date('D M d H:i:s Y').' [client '.$_SERVER['REMOTE_ADDR'].'] [error] '.$msg."\r\n";
111+
function auth_saml_log_info($msg, $logfile) {
112+
global $CFG;
113+
if (isset($logfile) && !empty($logfile)) {
114+
if (substr($logfile, 0) == '/') {
115+
$destination = $logfile;
116+
} else {
117+
$destination = $CFG->dataroot . '/' . $logfile;
118+
}
119+
$msg = auth_saml_decorate_log($msg, 'info');
120+
file_put_contents($destination, $msg, FILE_APPEND);
121+
} else {
122+
syslog(LOG_INFO, $msg);
123+
}
124+
}
125+
126+
function auth_saml_decorate_log($msg, $level = "error") {
127+
return $msg = date('D M d H:i:s Y').' [client '.$_SERVER['REMOTE_ADDR'].'] ['.$level.'] '.$msg."\r\n";
113128
}

‎index.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
if ($samlparam->dosinglelogout) {
7474
$as->logout($urltogo);
75-
assert("FALSE"); // The previous line issues a redirect.
75+
assert(false); // The previous line issues a redirect.
7676
} else {
7777
header('Location: '.$urltogo);
7878
exit();
@@ -235,6 +235,10 @@
235235
auth_saml_error($err['login'], $CFG->wwwroot.'/auth/saml/login.php', $pluginconfig->samllogfile, true);
236236
}
237237

238+
if ($pluginconfig->logextrainfo) {
239+
auth_saml_log_info($username.' logged', $pluginconfig->samllogfile);
240+
}
241+
238242
// Sync system role.
239243
$samlroles = null;
240244
if (isset($pluginconfig->role) && isset($samlattributes[$pluginconfig->role])) {
@@ -261,9 +265,15 @@
261265
if ($isrole) {
262266
// Following calls will not create duplicates.
263267
role_assign($role['id'], $user->id, $systemcontext->id, 'auth_saml');
268+
if ($pluginconfig->logextrainfo) {
269+
auth_saml_log_info("Systemrole ". $role['shortname']. 'assigned to '.$username, $pluginconfig->samllogfile);
270+
}
264271
} else {
265272
// Unassign only if previously assigned by this plugin.
266273
role_unassign($role['id'], $user->id, $systemcontext->id, 'auth_saml');
274+
if ($pluginconfig->logextrainfo) {
275+
auth_saml_log_info("Systemrole ".$role['shortname']. 'unassigned to '.$username, $pluginconfig->samllogfile);
276+
}
267277
}
268278
}
269279
}

‎lang/en/auth_saml.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@
153153
$string['auth_saml_error_complete_user_login'] = "Failed to complete user login of {\$a}";
154154

155155
$string['auth_saml_logfile'] = 'Log file path';
156-
$string['auth_saml_logfile_description'] = 'Set a filename if you want log the SAML plugin errors in a different file that the syslog. (Use an absolute path or Moodle will save this file in the moodledata folder).';
156+
$string['auth_saml_logfile_description'] = 'Set a filename if you want log the SAML plugin errors in a different file than the syslog. (Use an absolute path or Moodle will save this file in the moodledata folder).';
157+
158+
$string['auth_saml_logextrainfo'] = 'Log extra info';
159+
$string['auth_saml_logextrainfo_description'] = 'Enable it in order to log extra info like logins actions and user systemrole changes executed by the plugin';
157160

158161
$string['auth_saml_samlhookfile'] = 'Hook file path';
159162
$string['auth_saml_samlhookfile_description'] = 'Set a path if you want to use a hook file that contain your specific functions. The path can either be absolute or relative to your Moodle root directory.';

‎lang/es/auth_saml.php

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@
141141
$string['auth_saml_logfile'] = 'Ruta del fichero de log del plugin SAML';
142142
$string['auth_saml_logfile_description'] = 'Establece un nombre de fichero si tu quieres loggear los errores del plugin saml en un fichero diferente que el syslog (Establece una ruta absoluta o Moodle guardará este fichero dentro de la carpeta moodledata)';
143143

144+
$string['auth_saml_logextrainfo'] = 'Registrar información adicional';
145+
$string['auth_saml_logextrainfo_description'] = 'Habilítalo para registrar en el log información adicional como acciones de log in y modificaciones de roles de sistema del usuario ejecutadas por el plugin.';
146+
144147
$string['auth_saml_samlhookfile'] = 'Ruta del fichero del hook del plugin SAML';
145148
$string['auth_saml_samlhookfile_description'] = 'Establece la ruta si quieres usar un fichero hook que contiene tus funciones específicas. La ruta puede ser absoluta o relativa al directorio raíz de Moodle.';
146149
$string['auth_saml_errorbadhook'] = "Incorrect SAML plugin hook file: {\$a}";

‎lang/es_es/auth_saml.php

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
$string['auth_saml_logfile'] = 'Ruta del fichero de log del plugin SAML';
140140
$string['auth_saml_logfile_description'] = 'Establece un nombre de fichero si tu quieres loggear los errores del plugin saml en un fichero diferente que el syslog (Establece una ruta absoluta o Moodle guardará este fichero dentro de la carpeta moodledata)';
141141

142+
$string['auth_saml_logextrainfo'] = 'Registrar información adicional';
143+
$string['auth_saml_logextrainfo_description'] = 'Habilítalo para registrar en el log información adicional como acciones de log in y modificaciones de roles de sistema del usuario ejecutadas por el plugin.';
144+
142145
$string['auth_saml_samlhookfile'] = 'Ruta del fichero del hook del plugin SAML';
143146
$string['auth_saml_samlhookfile_description'] = 'Establece la ruta si quieres usar un fichero hook que contiene tus funciones específicas. La ruta puede ser absoluta o relativa al directorio raíz de Moodle.';
144147
$string['auth_saml_errorbadhook'] = "Incorrect SAML plugin hook file: {\$a}";

‎settings.php

+7
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ function save_in_saml_config_file() {
156156
$setting = new admin_setting_configtext($name, $title, $description, $default, PARAM_RAW);
157157
$settings->add($setting);
158158

159+
$name = 'auth_saml/logextrainfo';
160+
$title = get_string('auth_saml_logextrainfo', 'auth_saml');
161+
$description = get_string('auth_saml_logextrainfo_description', 'auth_saml');
162+
$default = false;
163+
$setting = new admin_setting_configcheckbox($name, $title, $description, $default, true, false);
164+
$settings->add($setting);
165+
159166
$name = 'auth_saml/disablejit';
160167
$title = get_string('auth_saml_disablejit', 'auth_saml');
161168
$description = get_string('auth_saml_disablejit_description', 'auth_saml');

‎version.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828

2929
defined('MOODLE_INTERNAL') || die();
3030

31-
$plugin->version = 2019011501;
31+
$plugin->version = 2019061301;
3232
$plugin->requires = 2017111300;
33-
$plugin->release = 'auth/saml version of 15-01-2019';
34-
$plugin->maturity = MATURITY_BETA;
33+
$plugin->release = 'auth/saml version of 13-06-2019';
34+
$plugin->maturity = MATURITY_STABLE;
3535
$plugin->cron = 0;
3636
$plugin->component = 'auth_saml';

0 commit comments

Comments
 (0)
Please sign in to comment.