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
3 changes: 2 additions & 1 deletion auth/oidc/binding_username_claim.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

use auth_oidc\form\binding_username_claim;
use core\context\system;

require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
Expand All @@ -33,7 +34,7 @@

$url = new moodle_url('/auth/oidc/binding_username_claim.php');
$PAGE->set_url($url);
$PAGE->set_context(context_system::instance());
$PAGE->set_context(system::instance());
$PAGE->set_pagelayout('admin');
$PAGE->set_heading(get_string('settings_page_binding_username_claim', 'auth_oidc'));
$PAGE->set_title(get_string('settings_page_binding_username_claim', 'auth_oidc'));
Expand Down
3 changes: 2 additions & 1 deletion auth/oidc/change_binding_username_claim_tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use auth_oidc\form\change_binding_username_claim_tool_form2;
use auth_oidc\preview;
use auth_oidc\process;
use core\context\system;

require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
Expand All @@ -36,7 +37,7 @@

$url = new moodle_url('/auth/oidc/change_binding_username_claim_tool.php');
$PAGE->set_url($url);
$PAGE->set_context(context_system::instance());
$PAGE->set_context(system::instance());
$PAGE->set_pagelayout('admin');
$PAGE->set_heading(get_string('settings_page_change_binding_username_claim_tool', 'auth_oidc'));
$PAGE->set_title(get_string('settings_page_change_binding_username_claim_tool', 'auth_oidc'));
Expand Down
4 changes: 3 additions & 1 deletion auth/oidc/classes/event/action_failed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace auth_oidc\event;

use core\context\system;

/**
* Event fired whenever we need to record a debug message.
*/
Expand Down Expand Up @@ -53,7 +55,7 @@ public function get_description() {
* @return void
*/
protected function init() {
$this->context = \context_system::instance();
$this->context = system::instance();
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
Expand Down
4 changes: 3 additions & 1 deletion auth/oidc/classes/event/user_authed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace auth_oidc\event;

use core\context\system;

/**
* Event fired when a user authenticated with OIDC, but does not log in.
*/
Expand Down Expand Up @@ -53,7 +55,7 @@ public function get_description() {
* @return void
*/
protected function init() {
$this->context = \context_system::instance();
$this->context = system::instance();
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
Expand Down
4 changes: 3 additions & 1 deletion auth/oidc/classes/event/user_connected.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace auth_oidc\event;

use core\context\system;

/**
* Fired when a user connects to OpenID Connect.
*/
Expand Down Expand Up @@ -53,7 +55,7 @@ public function get_description() {
* @return void
*/
protected function init() {
$this->context = \context_system::instance();
$this->context = system::instance();
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'user';
Expand Down
4 changes: 3 additions & 1 deletion auth/oidc/classes/event/user_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace auth_oidc\event;

use core\context\system;

/**
* Event fired when OIDC creates a new user.
*/
Expand Down Expand Up @@ -53,7 +55,7 @@ public function get_description() {
* @return void
*/
protected function init() {
$this->context = \context_system::instance();
$this->context = system::instance();
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'user';
Expand Down
4 changes: 3 additions & 1 deletion auth/oidc/classes/event/user_disconnected.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace auth_oidc\event;

use core\context\system;

/**
* Fired when a user disconnects from OpenID Connect.
*/
Expand Down Expand Up @@ -53,7 +55,7 @@ public function get_description() {
* @return void
*/
protected function init() {
$this->context = \context_system::instance();
$this->context = system::instance();
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'user';
Expand Down
4 changes: 3 additions & 1 deletion auth/oidc/classes/event/user_loggedin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace auth_oidc\event;

use core\context\system;

/**
* Fired when a user uses OIDC to log in.
*/
Expand Down Expand Up @@ -53,7 +55,7 @@ public function get_description() {
* @return void
*/
protected function init() {
$this->context = \context_system::instance();
$this->context = system::instance();
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'user';
Expand Down
4 changes: 2 additions & 2 deletions auth/oidc/classes/event/user_rename_attempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace auth_oidc\event;

use context_system;
use core\context\system;
use core\event\base;

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ public function get_description() {
* @return void
*/
protected function init() {
$this->context = context_system::instance();
$this->context = system::instance();
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'user';
Expand Down
3 changes: 2 additions & 1 deletion auth/oidc/classes/loginflow/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use auth_oidc\jwt;
use auth_oidc\oidcclient;
use auth_oidc\utils;
use core\context\system;
use core_user;
use moodle_exception;
use stdClass;
Expand Down Expand Up @@ -388,7 +389,7 @@ public function disconnect($justremovetokens = false, $donotremovetokens = false
global $OUTPUT, $PAGE;
require_once($CFG->dirroot.'/user/lib.php');
$PAGE->set_url($selfurl->out());
$PAGE->set_context(\context_system::instance());
$PAGE->set_context(system::instance());
$PAGE->set_pagelayout('standard');
$USER->editing = false;

Expand Down
7 changes: 4 additions & 3 deletions auth/oidc/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

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

use core\context\user;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\contextlist;
use core_privacy\local\request\approved_contextlist;
Expand Down Expand Up @@ -127,7 +128,7 @@ public static function get_contexts_for_userid(int $userid): contextlist {
public static function get_users_in_context(\core_privacy\local\request\userlist $userlist) {
$context = $userlist->get_context();

if (!$context instanceof \context_user) {
if (!$context instanceof user) {
return;
}

Expand Down Expand Up @@ -161,7 +162,7 @@ public static function get_users_in_context(\core_privacy\local\request\userlist
public static function export_user_data(approved_contextlist $contextlist) {
global $DB;
$user = $contextlist->get_user();
$context = \context_user::instance($contextlist->get_user()->id);
$context = user::instance($contextlist->get_user()->id);
$tables = static::get_table_user_map($user);
foreach ($tables as $table => $filterparams) {
$records = $DB->get_recordset($table, $filterparams);
Expand Down Expand Up @@ -235,7 +236,7 @@ private static function delete_user_data(int $userid) {
public static function delete_data_for_users(\core_privacy\local\request\approved_userlist $userlist) {
$context = $userlist->get_context();
// Because we only use user contexts the instance ID is the user ID.
if ($context instanceof \context_user) {
if ($context instanceof user) {
self::delete_user_data($context->instanceid);
}
}
Expand Down
4 changes: 3 additions & 1 deletion auth/oidc/cleanupoidctokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
* @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/)
*/

use core\context\system;

require_once(__DIR__ . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/auth/oidc/lib.php');

require_login();

$context = context_system::instance();
$context = system::instance();
$pageurl = new moodle_url('/auth/oidc/cleanupoidctokens.php');

admin_externalpage_setup('auth_oidc_cleanup_oidc_tokens');
Expand Down
16 changes: 9 additions & 7 deletions auth/oidc/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

use auth_oidc\jwt;
use auth_oidc\utils;
use core\context\system;
use core\context\user;

// IdP types.
/**
Expand Down Expand Up @@ -94,7 +96,7 @@ function auth_oidc_initialize_customicon($filefullname) {
global $CFG;

$file = get_config('auth_oidc', 'customicon');
$systemcontext = \context_system::instance();
$systemcontext = system::instance();
$fullpath = "/{$systemcontext->id}/auth_oidc/customicon/0{$file}";

$fs = get_file_storage();
Expand Down Expand Up @@ -134,24 +136,24 @@ function auth_oidc_connectioncapability($userid, $mode = 'connect', $require = f
if ($require) {
// If requiring the capability and user has manageconnection than checking connect and disconnect is not needed.
$check = 'require_capability';
if (has_capability('auth/oidc:manageconnection', \context_user::instance($userid), $userid)) {
if (has_capability('auth/oidc:manageconnection', user::instance($userid), $userid)) {
return true;
}
} else if ($check('auth/oidc:manageconnection', \context_user::instance($userid), $userid)) {
} else if ($check('auth/oidc:manageconnection', user::instance($userid), $userid)) {
return true;
}

$result = false;
switch ($mode) {
case "connect":
$result = $check('auth/oidc:manageconnectionconnect', \context_user::instance($userid), $userid);
$result = $check('auth/oidc:manageconnectionconnect', user::instance($userid), $userid);
break;
case "disconnect":
$result = $check('auth/oidc:manageconnectiondisconnect', \context_user::instance($userid), $userid);
$result = $check('auth/oidc:manageconnectiondisconnect', user::instance($userid), $userid);
break;
case "both":
$result = $check('auth/oidc:manageconnectionconnect', \context_user::instance($userid), $userid);
$result = $result && $check('auth/oidc:manageconnectiondisconnect', \context_user::instance($userid), $userid);
$result = $check('auth/oidc:manageconnectionconnect', user::instance($userid), $userid);
$result = $result && $check('auth/oidc:manageconnectiondisconnect', user::instance($userid), $userid);
}
if ($require) {
return true;
Expand Down
4 changes: 3 additions & 1 deletion auth/oidc/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
*/

// phpcs:ignore moodle.Files.RequireLogin.Missing
use core\context\system;

require_once(__DIR__ . '/../../config.php');

$PAGE->set_url('/auth/oidc/logout.php');
$PAGE->set_context(context_system::instance());
$PAGE->set_context(system::instance());

$sid = optional_param('sid', '', PARAM_TEXT);

Expand Down
3 changes: 2 additions & 1 deletion auth/oidc/manageapplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

use auth_oidc\form\application;
use core\context\system;

require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
Expand All @@ -33,7 +34,7 @@

$url = new moodle_url('/auth/oidc/manageapplication.php');
$PAGE->set_url($url);
$PAGE->set_context(context_system::instance());
$PAGE->set_context(system::instance());
$PAGE->set_pagelayout('admin');
$PAGE->set_heading(get_string('settings_page_application', 'auth_oidc'));
$PAGE->set_title(get_string('settings_page_application', 'auth_oidc'));
Expand Down
20 changes: 11 additions & 9 deletions auth/oidc/tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
namespace auth_oidc;

use auth_oidc\privacy\provider;
use core\context\system;
use core\context\user;

/**
* Privacy test for auth_oidc
Expand Down Expand Up @@ -64,7 +66,7 @@ public function test_get_contexts_for_userid(): void {
$this->assertCount(1, $contextlist);

// Check that a context is returned and is the expected context.
$usercontext = \context_user::instance($user->id);
$usercontext = user::instance($user->id);
$this->assertEquals($usercontext->id, $contextlist->get_contextids()[0]);
}

Expand All @@ -79,7 +81,7 @@ public function test_get_users_in_context(): void {
$component = 'auth_oidc';
// Create a user.
$user = $this->getDataGenerator()->create_user();
$usercontext = \context_user::instance($user->id);
$usercontext = user::instance($user->id);

// The list of users should not return anything yet (related data still haven't been created).
$userlist = new \core_privacy\local\request\userlist($usercontext, $component);
Expand All @@ -98,7 +100,7 @@ public function test_get_users_in_context(): void {
$this->assertEquals($expected, $actual);

// The list of users for system context should not return any users.
$userlist = new \core_privacy\local\request\userlist(\context_system::instance(), $component);
$userlist = new \core_privacy\local\request\userlist(system::instance(), $component);
provider::get_users_in_context($userlist);
$this->assertCount(0, $userlist);
}
Expand All @@ -114,7 +116,7 @@ public function test_export_user_data(): void {
$tokenrecord = self::create_token($user->id);
$prevloginrecord = self::create_prevlogin($user->id);

$usercontext = \context_user::instance($user->id);
$usercontext = user::instance($user->id);

$writer = \core_privacy\local\request\writer::with_context($usercontext);
$this->assertFalse($writer->has_any_data());
Expand Down Expand Up @@ -149,7 +151,7 @@ public function test_delete_data_for_all_users_in_context(): void {
$user1 = $this->getDataGenerator()->create_user();
self::create_token($user1->id);
self::create_prevlogin($user1->id);
$user1context = \context_user::instance($user1->id);
$user1context = user::instance($user1->id);

$user2 = $this->getDataGenerator()->create_user();
self::create_token($user2->id);
Expand Down Expand Up @@ -182,7 +184,7 @@ public function test_delete_data_for_user(): void {
$user1 = $this->getDataGenerator()->create_user();
self::create_token($user1->id);
self::create_prevlogin($user1->id);
$user1context = \context_user::instance($user1->id);
$user1context = user::instance($user1->id);

$user2 = $this->getDataGenerator()->create_user();
self::create_token($user2->id);
Expand Down Expand Up @@ -215,13 +217,13 @@ public function test_delete_data_for_users(): void {
$component = 'auth_oidc';
// Create user1.
$user1 = $this->getDataGenerator()->create_user();
$usercontext1 = \context_user::instance($user1->id);
$usercontext1 = user::instance($user1->id);
self::create_token($user1->id);
self::create_prevlogin($user1->id);

// Create user2.
$user2 = $this->getDataGenerator()->create_user();
$usercontext2 = \context_user::instance($user2->id);
$usercontext2 = user::instance($user2->id);
self::create_token($user2->id);
self::create_prevlogin($user2->id);

Expand Down Expand Up @@ -257,7 +259,7 @@ public function test_delete_data_for_users(): void {
$this->assertCount(1, $userlist2);

// User data should be only removed in the user context.
$systemcontext = \context_system::instance();
$systemcontext = system::instance();
// Add userlist2 to the approved user list in the system context.
$approvedlist = new \core_privacy\local\request\approved_userlist($systemcontext, $component, $userlist2->get_userids());
// Delete user1 data using delete_data_for_user.
Expand Down
Loading