]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/AuthPlugin.php
MediaWiki 1.11.0-scripts
[autoinstallsdev/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  * This interface is new, and might change a bit before 1.4.0 final is
33  * done...
34  *
35  */
36 class AuthPlugin {
37         /**
38          * Check whether there exists a user account with the given name.
39          * The name will be normalized to MediaWiki's requirements, so
40          * you might need to munge it (for instance, for lowercase initial
41          * letters).
42          *
43          * @param $username String: username.
44          * @return bool
45          * @public
46          */
47         function userExists( $username ) {
48                 # Override this!
49                 return false;
50         }
51
52         /**
53          * Check if a username+password pair is a valid login.
54          * The name will be normalized to MediaWiki's requirements, so
55          * you might need to munge it (for instance, for lowercase initial
56          * letters).
57          *
58          * @param $username String: username.
59          * @param $password String: user password.
60          * @return bool
61          * @public
62          */
63         function authenticate( $username, $password ) {
64                 # Override this!
65                 return false;
66         }
67
68         /**
69          * Modify options in the login template.
70          *
71          * @param $template UserLoginTemplate object.
72          * @public
73          */
74         function modifyUITemplate( &$template ) {
75                 # Override this!
76                 $template->set( 'usedomain', false );
77         }
78
79         /**
80          * Set the domain this plugin is supposed to use when authenticating.
81          *
82          * @param $domain String: authentication domain.
83          * @public
84          */
85         function setDomain( $domain ) {
86                 $this->domain = $domain;
87         }
88
89         /**
90          * Check to see if the specific domain is a valid domain.
91          *
92          * @param $domain String: authentication domain.
93          * @return bool
94          * @public
95          */
96         function validDomain( $domain ) {
97                 # Override this!
98                 return true;
99         }
100
101         /**
102          * When a user logs in, optionally fill in preferences and such.
103          * For instance, you might pull the email address or real name from the
104          * external user database.
105          *
106          * The User object is passed by reference so it can be modified; don't
107          * forget the & on your function declaration.
108          *
109          * @param User $user
110          * @public
111          */
112         function updateUser( &$user ) {
113                 # Override this and do something
114                 return true;
115         }
116
117
118         /**
119          * Return true if the wiki should create a new local account automatically
120          * when asked to login a user who doesn't exist locally but does in the
121          * external auth database.
122          *
123          * If you don't automatically create accounts, you must still create
124          * accounts in some way. It's not possible to authenticate without
125          * a local account.
126          *
127          * This is just a question, and shouldn't perform any actions.
128          *
129          * @return bool
130          * @public
131          */
132         function autoCreate() {
133                 return false;
134         }
135
136         /**
137          * Can users change their passwords?
138          *
139          * @return bool
140          */
141         function allowPasswordChange() {
142                 return true;
143         }
144
145         /**
146          * Set the given password in the authentication database.
147          * As a special case, the password may be set to null to request
148          * locking the password to an unusable value, with the expectation
149          * that it will be set later through a mail reset or other method.
150          *
151          * Return true if successful.
152          *
153          * @param $user User object.
154          * @param $password String: password.
155          * @return bool
156          * @public
157          */
158         function setPassword( $user, $password ) {
159                 return true;
160         }
161
162         /**
163          * Update user information in the external authentication database.
164          * Return true if successful.
165          *
166          * @param $user User object.
167          * @return bool
168          * @public
169          */
170         function updateExternalDB( $user ) {
171                 return true;
172         }
173
174         /**
175          * Check to see if external accounts can be created.
176          * Return true if external accounts can be created.
177          * @return bool
178          * @public
179          */
180         function canCreateAccounts() {
181                 return false;
182         }
183
184         /**
185          * Add a user to the external authentication database.
186          * Return true if successful.
187          *
188          * @param User $user - only the name should be assumed valid at this point
189          * @param string $password
190          * @param string $email
191          * @param string $realname
192          * @return bool
193          * @public
194          */
195         function addUser( $user, $password, $email='', $realname='' ) {
196                 return true;
197         }
198
199
200         /**
201          * Return true to prevent logins that don't authenticate here from being
202          * checked against the local database's password fields.
203          *
204          * This is just a question, and shouldn't perform any actions.
205          *
206          * @return bool
207          * @public
208          */
209         function strict() {
210                 return false;
211         }
212
213         /**
214          * When creating a user account, optionally fill in preferences and such.
215          * For instance, you might pull the email address or real name from the
216          * external user database.
217          *
218          * The User object is passed by reference so it can be modified; don't
219          * forget the & on your function declaration.
220          *
221          * @param $user User object.
222          * @param $autocreate bool True if user is being autocreated on login
223          * @public
224          */
225         function initUser( $user, $autocreate=false ) {
226                 # Override this to do something.
227         }
228
229         /**
230          * If you want to munge the case of an account name before the final
231          * check, now is your chance.
232          */
233         function getCanonicalName( $username ) {
234                 return $username;
235         }
236 }
237
238