Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions auth/saml/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@
<td class="right"><?php print_string("auth_saml_course_field_id", "auth_saml"); ?>:</td>
<td>
<select name="moodlecoursefieldid">
<option name="shortname" value="shortname" <?php if($config->moodlecoursefieldid == 'shortname') echo 'selected="selected"'; ?> >Short Name</option>
<option name="idnumber" value="idnumber" <?php if($config->moodlecoursefieldid == 'idnumber') echo 'selected="selected"'; ?> >Number ID</option>
<option name="shortname" value="shortname" <?php if($config->moodlecoursefieldid == 'mapping') echo 'selected="selected"'; ?> >Mapping</option>
<option name="idnumber" value="idnumber" <?php if($config->moodlecoursefieldid == 'idnumber') echo 'selected="selected"'; ?> >Course ID</option>
</select>
</td>
<td><?php print_string("auth_saml_course_field_id_description", "auth_saml"); ?></td>
Expand Down
32 changes: 12 additions & 20 deletions auth/saml/course_mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,20 @@
foreach($saml_courses as $key => $course) {
if(preg_match('/urn:mace:terena.org:schac:userStatus:(.+):(.+):(.+):(.+):(.+):(.+)/', $course, $regs)) {
list($match, $country, $domain, $course_id, $period, $role, $status) = $regs;
if(isset($role_mapping[$role]) && isset($course_mapping[$course_id][$period])) {
$mapped_role = $role_mapping[$role];
$mapped_course_id = $course_mapping[$course_id][$period];
$mapped_courses[$mapped_role][$status][$mapped_course_id] = array( 'country' => $country,
'domain' => $domain,
'course_id' => $mapped_course_id,
'period' => $period,
'role' => $mapped_role,
'status' => $status,
);
if(!$any_course_active && $status == 'active') {
$any_course_active = true;
}
}
else {
$str_obj = new stdClass();
$str_obj->course = '('.$course_id.' -- '.$period.')';
$str_obj->user = $saml_user_identify;
$err['course_enrollment'][] = get_string('auth_saml_course_not_found' , 'auth_saml', $str_obj);
$mapped_role = !empty($role_mapping[$role]) ? $role_mapping[$role] : $role;
$mapped_course_id = ($config->moodlecoursefieldid == 'idnumber') ? $course_id : $course_mapping[$course_id][$period];
$mapped_courses[$mapped_role][$status][$mapped_course_id] = array(
'country' => $country,
'domain' => $domain,
'course_id' => $mapped_course_id,
'period' => $period,
'role' => $mapped_role,
'status' => $status,
);
if(!$any_course_active && $status == 'active') {
$any_course_active = true;
}
}
}

unset($saml_courses);
unset($saml_user_identify);
6 changes: 4 additions & 2 deletions enrol/saml/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Important for enrollment!!
==========================

This plugin suppose that the IdP send the courses data of the user in a attribute that
can be configured but the pattern of the expected data is always:
<course_id>:<period>:<role>:<status>
can be configured but the pattern of the expected data is always defined per the RFC:
https://tools.ietf.org/html/rfc6338
e.g.,
urn:mace:terena.org:schac:userStatus:(.+):(.+):(.+):(.+):(.+):(.+)
You can change this pattern editing the file auth/saml/course_mapping.php