4 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
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.
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.
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
23 * Authentication plugin interface. Instantiate a subclass of AuthPlugin
24 * and set $wgAuth to it to authenticate against some external tool.
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.
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
39 * @param $username String: username.
42 public function userExists( $username ) {
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
53 * @param $username String: username.
54 * @param $password String: user password.
57 public function authenticate( $username, $password ) {
63 * Modify options in the login template.
65 * @param $template UserLoginTemplate object.
67 public function modifyUITemplate( &$template ) {
69 $template->set( 'usedomain', false );
73 * Set the domain this plugin is supposed to use when authenticating.
75 * @param $domain String: authentication domain.
77 public function setDomain( $domain ) {
78 $this->domain
= $domain;
82 * Check to see if the specific domain is a valid domain.
84 * @param $domain String: authentication domain.
87 public function validDomain( $domain ) {
93 * When a user logs in, optionally fill in preferences and such.
94 * For instance, you might pull the email address or real name from the
95 * external user database.
97 * The User object is passed by reference so it can be modified; don't
98 * forget the & on your function declaration.
102 public function updateUser( &$user ) {
103 # Override this and do something
109 * Return true if the wiki should create a new local account automatically
110 * when asked to login a user who doesn't exist locally but does in the
111 * external auth database.
113 * If you don't automatically create accounts, you must still create
114 * accounts in some way. It's not possible to authenticate without
117 * This is just a question, and shouldn't perform any actions.
121 public function autoCreate() {
126 * Can users change their passwords?
130 public function allowPasswordChange() {
135 * Can users change their Real Name?
139 public function allowRealNameChange() {
144 * Can users change their email address?
148 public function allowEmailChange() {
153 * Can users change their Nickname?
157 public function allowNickChange() {
162 * Set the given password in the authentication database.
163 * As a special case, the password may be set to null to request
164 * locking the password to an unusable value, with the expectation
165 * that it will be set later through a mail reset or other method.
167 * Return true if successful.
169 * @param $user User object.
170 * @param $password String: password.
173 public function setPassword( $user, $password ) {
178 * Update user information in the external authentication database.
179 * Return true if successful.
181 * @param $user User object.
184 public function updateExternalDB( $user ) {
189 * Check to see if external accounts can be created.
190 * Return true if external accounts can be created.
193 public function canCreateAccounts() {
198 * Add a user to the external authentication database.
199 * Return true if successful.
201 * @param User $user - only the name should be assumed valid at this point
202 * @param string $password
203 * @param string $email
204 * @param string $realname
207 public function addUser( $user, $password, $email='', $realname='' ) {
213 * Return true to prevent logins that don't authenticate here from being
214 * checked against the local database's password fields.
216 * This is just a question, and shouldn't perform any actions.
220 public function strict() {
225 * Check if a user should authenticate locally if the global authentication fails.
226 * If either this or strict() returns true, local authentication is not used.
228 * @param $username String: username.
231 public function strictUserAuth( $username ) {
236 * When creating a user account, optionally fill in preferences and such.
237 * For instance, you might pull the email address or real name from the
238 * external user database.
240 * The User object is passed by reference so it can be modified; don't
241 * forget the & on your function declaration.
243 * @param $user User object.
244 * @param $autocreate bool True if user is being autocreated on login
246 public function initUser( &$user, $autocreate=false ) {
247 # Override this to do something.
251 * If you want to munge the case of an account name before the final
252 * check, now is your chance.
254 public function getCanonicalName( $username ) {
259 * Get an instance of a User object
264 public function getUserInstance( User
&$user ) {
265 return new AuthPluginUser( $user );
269 class AuthPluginUser
{
270 function __construct( $user ) {
274 public function getId() {
279 public function isLocked() {
284 public function isHidden() {
289 public function resetAuthToken() {