]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/AuthPlugin.php
MediaWiki 1.16.4
[autoinstalls/mediawiki.git] / includes / AuthPlugin.php
1 <?php
2 /**
3  */
4 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # http://www.gnu.org/copyleft/gpl.html
21
22 /**
23  * Authentication plugin interface. Instantiate a subclass of AuthPlugin
24  * and set $wgAuth to it to authenticate against some external tool.
25  *
26  * The default behavior is not to do anything, and use the local user
27  * database for all authentication. A subclass can require that all
28  * accounts authenticate externally, or use it only as a fallback; also
29  * you can transparently create internal wiki accounts the first time
30  * someone logs in who can be authenticated externally.
31  */
32 class AuthPlugin {
33         /**
34          * Check whether there exists a user account with the given name.
35          * The name will be normalized to MediaWiki's requirements, so
36          * you might need to munge it (for instance, for lowercase initial
37          * letters).
38          *
39          * @param $username String: username.
40          * @return bool
41          */
42         public function userExists( $username ) {
43                 # Override this!
44                 return false;
45         }
46
47         /**
48          * Check if a username+password pair is a valid login.
49          * The name will be normalized to MediaWiki's requirements, so
50          * you might need to munge it (for instance, for lowercase initial
51          * letters).
52          *
53          * @param $username String: username.
54          * @param $password String: user password.
55          * @return bool
56          */
57         public function authenticate( $username, $password ) {
58                 # Override this!
59                 return false;
60         }
61
62         /**
63          * Modify options in the login template.
64          *
65          * @param $template UserLoginTemplate object.
66          * @param $type String 'signup' or 'login'.
67          */
68         public function modifyUITemplate( &$template, &$type ) {
69                 # Override this!
70                 $template->set( 'usedomain', false );
71         }
72
73         /**
74          * Set the domain this plugin is supposed to use when authenticating.
75          *
76          * @param $domain String: authentication domain.
77          */
78         public function setDomain( $domain ) {
79                 $this->domain = $domain;
80         }
81
82         /**
83          * Check to see if the specific domain is a valid domain.
84          *
85          * @param $domain String: authentication domain.
86          * @return bool
87          */
88         public function validDomain( $domain ) {
89                 # Override this!
90                 return true;
91         }
92
93         /**
94          * When a user logs in, optionally fill in preferences and such.
95          * For instance, you might pull the email address or real name from the
96          * external user database.
97          *
98          * The User object is passed by reference so it can be modified; don't
99          * forget the & on your function declaration.
100          *
101          * @param $user User object
102          */
103         public function updateUser( &$user ) {
104                 # Override this and do something
105                 return true;
106         }
107
108
109         /**
110          * Return true if the wiki should create a new local account automatically
111          * when asked to login a user who doesn't exist locally but does in the
112          * external auth database.
113          *
114          * If you don't automatically create accounts, you must still create
115          * accounts in some way. It's not possible to authenticate without
116          * a local account.
117          *
118          * This is just a question, and shouldn't perform any actions.
119          *
120          * @return Boolean
121          */
122         public function autoCreate() {
123                 return false;
124         }
125
126         /**
127          * Allow a property change? Properties are the same as preferences
128          * and use the same keys. 'Realname' 'Emailaddress' and 'Nickname'
129          * all reference this.
130          *
131          * @return Boolean
132          */
133         public function allowPropChange( $prop = '' ) {
134                 if( $prop == 'realname' && is_callable( array( $this, 'allowRealNameChange' ) ) ) {
135                         return $this->allowRealNameChange();
136                 } elseif( $prop == 'emailaddress' && is_callable( array( $this, 'allowEmailChange' ) ) ) {
137                         return $this->allowEmailChange();
138                 } elseif( $prop == 'nickname' && is_callable( array( $this, 'allowNickChange' ) ) ) {
139                         return $this->allowNickChange();
140                 } else {
141                         return true;
142                 }
143         }
144
145         /**
146          * Can users change their passwords?
147          *
148          * @return bool
149          */
150         public function allowPasswordChange() {
151                 return true;
152         }
153
154         /**
155          * Set the given password in the authentication database.
156          * As a special case, the password may be set to null to request
157          * locking the password to an unusable value, with the expectation
158          * that it will be set later through a mail reset or other method.
159          *
160          * Return true if successful.
161          *
162          * @param $user User object.
163          * @param $password String: password.
164          * @return bool
165          */
166         public function setPassword( $user, $password ) {
167                 return true;
168         }
169
170         /**
171          * Update user information in the external authentication database.
172          * Return true if successful.
173          *
174          * @param $user User object.
175          * @return Boolean
176          */
177         public function updateExternalDB( $user ) {
178                 return true;
179         }
180
181         /**
182          * Check to see if external accounts can be created.
183          * Return true if external accounts can be created.
184          * @return Boolean
185          */
186         public function canCreateAccounts() {
187                 return false;
188         }
189
190         /**
191          * Add a user to the external authentication database.
192          * Return true if successful.
193          *
194          * @param $user User: only the name should be assumed valid at this point
195          * @param $password String
196          * @param $email String
197          * @param $realname String
198          * @return Boolean
199          */
200         public function addUser( $user, $password, $email='', $realname='' ) {
201                 return true;
202         }
203
204
205         /**
206          * Return true to prevent logins that don't authenticate here from being
207          * checked against the local database's password fields.
208          *
209          * This is just a question, and shouldn't perform any actions.
210          *
211          * @return Boolean
212          */
213         public function strict() {
214                 return false;
215         }
216
217         /**
218          * Check if a user should authenticate locally if the global authentication fails.
219          * If either this or strict() returns true, local authentication is not used.
220          *
221          * @param $username String: username.
222          * @return Boolean
223          */
224         public function strictUserAuth( $username ) {
225                 return false;
226         }
227
228         /**
229          * When creating a user account, optionally fill in preferences and such.
230          * For instance, you might pull the email address or real name from the
231          * external user database.
232          *
233          * The User object is passed by reference so it can be modified; don't
234          * forget the & on your function declaration.
235          *
236          * @param $user User object.
237          * @param $autocreate Boolean: True if user is being autocreated on login
238          */
239         public function initUser( &$user, $autocreate=false ) {
240                 # Override this to do something.
241         }
242
243         /**
244          * If you want to munge the case of an account name before the final
245          * check, now is your chance.
246          */
247         public function getCanonicalName( $username ) {
248                 return $username;
249         }
250         
251         /**
252          * Get an instance of a User object
253          *
254          * @param $user User
255          */
256         public function getUserInstance( User &$user ) {
257                 return new AuthPluginUser( $user );
258         }
259 }
260
261 class AuthPluginUser {
262         function __construct( $user ) {
263                 # Override this!
264         }
265         
266         public function getId() {
267                 # Override this!
268                 return -1;
269         }
270         
271         public function isLocked() {
272                 # Override this!
273                 return false;
274         }
275         
276         public function isHidden() {
277                 # Override this!
278                 return false;
279         }
280         
281         public function resetAuthToken() {
282                 # Override this!
283                 return true;
284         }
285 }