|
| 1 | +<?php |
| 2 | +// This file is part of Moodle - http://moodle.org/ |
| 3 | +// |
| 4 | +// Moodle is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// Moodle is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +namespace auth_saml2\local\hooks; |
| 18 | + |
| 19 | +/** |
| 20 | + * after_config hook callback for auth_saml2 |
| 21 | + * |
| 22 | + * @package auth_saml2 |
| 23 | + * @copyright 2024 David Carrillo <[email protected]> |
| 24 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 25 | + */ |
| 26 | +class after_config { |
| 27 | + /** |
| 28 | + * Callback executed from setup.php, available from Moodle 3.8 in core |
| 29 | + * |
| 30 | + * @param \core\hook\after_config $hook |
| 31 | + */ |
| 32 | + public static function callback(\core\hook\after_config $hook): void { |
| 33 | + global $CFG; |
| 34 | + |
| 35 | + if (during_initial_install() || isset($CFG->upgraderunning)) { |
| 36 | + // Do nothing during installation or upgrade. |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + try { |
| 41 | + $saml = optional_param('saml', null, PARAM_BOOL); |
| 42 | + if ($saml == 1) { |
| 43 | + if (isguestuser()) { |
| 44 | + // We want to force users to log in with a real account, so log guest users out. |
| 45 | + require_logout(); |
| 46 | + } |
| 47 | + // We have the saml=on param set. Disable guest access (in memory - |
| 48 | + // not saved in database) to force the login with saml for this request. |
| 49 | + unset($CFG->autologinguests); |
| 50 | + } |
| 51 | + } catch (\Exception $exception) { |
| 52 | + debugging('auth_saml2_after_config error', DEBUG_DEVELOPER, $exception->getTrace()); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments