This repository was archived by the owner on Dec 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicAuthSessionProvider.php
executable file
·90 lines (80 loc) · 2.41 KB
/
BasicAuthSessionProvider.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
<?php
/**
* MediaWiki HTTP Basic Auth Session Provider
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*/
namespace MediaWiki\Session;
use Config;
use User;
use WebRequest;
/**
* Session provider for HTTP Basic Auth
*/
class BasicAuthSessionProvider extends SessionProvider {
/**
* If we find Basic authentication, we provide a basic Session object.
* Otherwise return null.
*/
public function provideSessionInfo( WebRequest $request ) {
if ( !isset( $_SERVER['PHP_AUTH_USER'] ) ) {
return null;
}
$name = $_SERVER['PHP_AUTH_USER'];
return new SessionInfo(
SessionInfo::MAX_PRIORITY,
[
'provider' => $this,
'userInfo' => UserInfo::newFromName($name, true),
],
);
}
/**
* From SessionProvider documentation:
* "Indicate whether self::persistSession() can save arbitrary session IDs"
*
* We authenticate upstream, so MediaWiki cannot give us a session ID.
*/
public function persistsSessionId() {
return false;
}
/**
* We authenticate upstream, so MediaWiki cannot change user.
*/
public function canChangeUser() {
return false;
}
/**
* This is a no-op: we authenticate upstream, so the upstream authenticator
* persists sessions.
*/
public function persistSession( SessionBackend $session, WebRequest $request ) {
}
/**
* This is a no-op. From SessionProvider documentation:
*
* "A backend that cannot persist sesison ID or user info should implement
* this as a no-op."
*/
public function unpersistSession( WebRequest $request ) {
}
/**
* This is a no-op: we authenticate upstream, so if we want to prevent
* sessions for the user, we disable the user in the upstream authenticator.
*/
public function preventSessionsForUser( $username ) {
}
}