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
31 changes: 29 additions & 2 deletions auth/saml/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,39 @@
**/
class auth_plugin_saml extends auth_plugin_base {

/**
* The SP.
*/
protected static $sp;

/**
* Are we currently forcing log-out?
*/
protected static $forcingLogout = FALSE;

/**
* Constructor.
*/
function auth_plugin_saml() {
$this->authtype = 'saml';
$this->config = get_config('auth/saml');
$this->authtype = 'saml';
$this->config = get_config('auth/saml');
// Include the autoloader since Moodle isn't a composer project itself.
require_once($this->config->samllib . '/_autoload.php');
if (empty(static::$sp)) {
static::$sp = new SimpleSAML_Auth_Simple($this->config->sp_source);
}
// Additionally determine if the user is still logged in to the SP.
global $USER;
global $SESSION;
if ($USER->loggedin && $USER->auth == "saml") {
if (!static::$forcingLogout
&& (!static::$sp->isAuthenticated()
|| (static::$sp->getAuthData('saml:sp:NameID') != $SESSION->auth_saml['NameID']))) {
// The user is logged in with the saml module but doesn't share a session on the SP.
static::$forcingLogout = TRUE;
require_logout();
}
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion auth/saml/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@

$USER = complete_user_login($user);

if (function_exists('saml_hook_post_user_created')) {
if (function_exists('saml_hook_post_user_created') && !$user_exists && $USER->id) {
saml_hook_post_user_created($USER);
}

Expand All @@ -218,6 +218,7 @@
$USER->loggedin = true;
$USER->site = $CFG->wwwroot;
set_moodle_cookie($USER->username);
$SESSION->auth_saml['NameID'] = $as->getAuthData('saml:sp:NameID');

if(isset($err) && !empty($err)) {
auth_saml_error($err, $urltogo, $pluginconfig->samllogfile);
Expand Down