-
Notifications
You must be signed in to change notification settings - Fork 21
/
course_and_role_mapping.php
102 lines (92 loc) · 3.9 KB
/
course_and_role_mapping.php
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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @author Erlend Strømsvik - Ny Media AS
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package auth/saml
*
* Authentication Plugin: SAML based SSO Authentication
*
* Authentication using SAML2 with SimpleSAMLphp.
*
* Based on plugins made by Sergio Gómez (moodle_ssp) and Martin Dougiamas (Shibboleth).
*/
if (!defined('MOODLE_INTERNAL')) {
// It must be included from a Moodle page.
die('Direct access to this script is forbidden.');
}
$rolemapping = get_role_mapping_for_sync($pluginconfig);
$coursemapping = get_course_mapping_for_sync($pluginconfig);
$mappedroles = [];
$mappedcourses = [];
foreach ($samlcourses as $key => $course) {
$mappedrole = $mappedcourseid = null;
if (function_exists('saml_hook_get_course_info')) {
$regs = saml_hook_get_course_info($course);
if ($regs) {
list($match, $country, $domain, $courseid, $period, $role, $status) = $regs;
$group = null;
if (isset($regs[7])) {
$group = $regs[7];
}
if (!empty($courseid)) {
foreach ($rolemapping as $shortname => $values) {
if (in_array($role, $values)) {
$mappedrole = $shortname;
break;
}
}
$mappedcourseids = [];
foreach ($coursemapping as $id => $values) {
if (in_array($courseid, $values)) {
$mappedcourseids[] = $id;
}
}
if (isset($status) && isset($mappedrole) && !empty($mappedcourseids)) {
if (!in_array($mappedrole, $mappedroles)) {
$mappedroles[] = $mappedrole;
}
foreach ($mappedcourseids as $mappedcourseid) {
$mappedcourses[$mappedrole][$status][$mappedcourseid] = [
'country' => $country,
'domain' => $domain,
'course_id' => $mappedcourseid,
'period' => $period,
'role' => $mappedrole,
'status' => $status,
'group' => $group
];
if (!$anycourseactive && $status == 'active') {
$anycourseactive = true;
}
}
} else if (!isset($status)) {
$err['course_enrollment'][] = get_string('auth_saml_status_not_found', 'auth_saml');
} else if (!isset($role)) {
$err['course_enrollment'][] = get_string('auth_saml_role_not_found', 'auth_saml');
} else {
$strobj = new stdClass();
$strobj->course = '('.$courseid.' -- '.$period.')';
$strobj->user = $username;
$err['course_enrollment'][] = get_string('auth_saml_course_not_found', 'auth_saml', $strobj);
}
}
}
} else {
$err['course_enrollment'][] = get_string('auth_saml_hook_not_defined', 'auth_saml');
}
}
unset($samlcourses);