]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/extauth/Hardcoded.php
MediaWiki 1.16.0
[autoinstalls/mediawiki.git] / includes / extauth / Hardcoded.php
1 <?php
2
3 # Copyright (C) 2009 Aryeh Gregor
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21  * This class supports external authentication from a literal array dumped in
22  * LocalSettings.php.  It's mostly useful for testing.  Example configuration:
23  *
24  *   $wgExternalAuthType = 'ExternalUser_Hardcoded';
25  *   $wgExternalAuthConf = array(
26  *       'Bob Smith' => array(
27  *           'password' => 'literal string',
28  *           'emailaddress' => 'bob@example.com',
29  *       ),
30  *   );
31  *
32  * Multiple names may be provided.  The keys of the inner arrays can be either
33  * 'password', or the name of any preference.
34  *
35  * @ingroup ExternalUser
36  */
37 class ExternalUser_Hardcoded extends ExternalUser {
38         private $mName;
39
40         protected function initFromName( $name ) {
41                 global $wgExternalAuthConf;
42
43                 if ( isset( $wgExternalAuthConf[$name] ) ) {
44                         $this->mName = $name;
45                         return true;
46                 }
47                 return false;
48         }
49
50         protected function initFromId( $id ) {
51                 return $this->initFromName( $id );
52         }
53
54         public function getId() {
55                 return $this->mName;
56         }
57
58         public function getName() {
59                 return $this->mName;
60         }
61
62         public function authenticate( $password ) {
63                 global $wgExternalAuthConf;
64
65                 return isset( $wgExternalAuthConf[$this->mName]['password'] )
66                         && $wgExternalAuthConf[$this->mName]['password'] == $password;
67         }
68
69         public function getPref( $pref ) {
70                 global $wgExternalAuthConf;
71
72                 if ( isset( $wgExternalAuthConf[$this->mName][$pref] ) ) {
73                         return $wgExternalAuthConf[$this->mName][$pref];
74                 }
75                 return null;
76         }
77
78         # TODO: Implement setPref() via regex on LocalSettings.  (Just kidding.)
79 }