baseline
[omp.pkp.sfu.ca.git] / classes / plugins / AuthPlugin.inc.php
blob4221da2512f6d6f65dfd9f638d79d2f3b266d106
1 <?php
3 /**
4 * @file classes/plugins/AuthPlugin.inc.php
6 * Copyright (c) 2003-2008 John Willinsky
7 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
9 * @class AuthPlugin
10 * @ingroup plugins
12 * @brief Abstract class for authentication plugins.
14 * TODO: Error reporting when updating remote source fails.
15 * TODO: Support importing user accounts from the authentication source into OMP.
18 // $Id: AuthPlugin.inc.php,v 1.2 2009/06/09 23:37:13 tylerl Exp $
21 define('AUTH_PLUGIN_CATEGORY', 'auth');
23 class AuthPlugin extends Plugin {
25 /** @var $settings array settings for this plugin instance */
26 var $settings;
28 /** @var $authId int auth source ID for this plugin instance */
29 var $authId;
31 /**
32 * Constructor.
33 * @param $settings array
35 function AuthPlugin($settings = array(), $authId = null) {
36 $this->settings = $settings;
37 $this->authId = $authId;
42 // General Plugin Functions
45 /**
46 * Return the name of this plugin.
47 * Should be overridden by subclass.
48 * @return string
50 function getName() {
51 return 'auth';
54 /**
55 * Return the localized name of this plugin.
56 * Should be overridden by subclass.
57 * @return string
59 function getDisplayName() {
60 return 'Abstract Authentication Plugin';
63 /**
64 * Return the localized description of this plugin.
65 * Should be overridden by subclass.
66 * @return string
68 function getDescription() {
69 'Authentication plugin base class';
72 /**
73 * Return the path to a template for plugin settings.
74 * Can return null if there are no plugin-specific settings.
75 * @return string
77 function getSettingsTemplate() {
78 return $this->getTemplatePath() . 'settings.tpl';
83 // Wrapper Functions
86 /**
87 * Update local user profile from the remote source, if enabled.
88 * @param $user User
89 * @return boolean true if successful
91 function doGetUserInfo(&$user) {
92 if (isset($this->settings['syncProfiles'])) {
93 return $this->getUserInfo($user);
95 return false;
98 /**
99 * Update remote user profile, if enabled.
100 * @param $user User
101 * @return boolean true if successful
103 function doSetUserInfo(&$user) {
104 if (isset($this->settings['syncProfiles'])) {
105 return $this->setUserInfo($user);
107 return false;
111 * Update remote user password, if enabled.
112 * @param $username string
113 * @param $password string
114 * @return boolean true if successful
116 function doSetUserPassword($username, $password) {
117 if (isset($this->settings['syncPasswords'])) {
118 return $this->setUserPassword($username, $password);
120 return false;
124 * Create remote user account, if enabled.
125 * @param $user User to create
126 * @return boolean true if successful
128 function doCreateUser(&$user) {
129 if (isset($this->settings['createUsers'])) {
130 return $this->createUser($user);
132 return false;
137 // Core Plugin Functions
138 // (Must be implemented by every authentication plugin)
142 * Returns an instance of the authentication plugin
143 * @param $settings array settings specific to this instance
144 * @param $authId int identifier for this instance
145 * @return AuthPlugin
147 function &getInstance($settings, $authId) {
148 $returner = null;
149 return $returner;
153 * Authenticate a username and password.
154 * @param $username string
155 * @param $password string
156 * @return boolean true if authentication is successful
158 function authenticate($username, $password) {
159 return false;
164 // Optional Plugin Functions
165 // (Required for extended functionality but not for authentication-only plugins)
169 * Check if a username exists.
170 * @param $username string
171 * @return boolean
173 function userExists($username) {
174 return false;
178 * Retrieve user profile information from the remote source.
179 * Any unsupported fields (e.g., OMP-specific ones) should not be modified.
180 * @param $user User to update
181 * @return boolean true if successful
183 function getUserInfo(&$user) {
184 return false;
188 * Store user profile information on the remote source.
189 * @param $user User to store
190 * @return boolean true if successful
192 function setUserInfo(&$user) {
193 return false;
197 * Change a user's password on the remote source.
198 * @param $username string user to update
199 * @param $password string the new password
200 * @return boolean true if successful
202 function setUserPassword($username, $password) {
203 return false;
207 * Create a user on the remote source.
208 * @param $user User to create
209 * @return boolean true if successful
211 function createUser(&$user) {
212 return false;
216 * Delete a user from the remote source.
217 * This function is currently not used within OMP,
218 * but is reserved for future use.
219 * @param $username string user to delete
220 * @return boolean true if successful
222 function deleteUser($username) {
223 return false;
227 * Return true iff this is a site-wide plugin.
229 function isSitePlugin() {
230 return true;
234 * Return the management verbs for this plugin.
236 function getManagementVerbs() {
237 return array(
238 array(
239 'authSources',
240 Locale::translate('admin.authSources')
245 function manage($verb, $args) {
246 if ($verb === 'authSources') {
247 Request::redirect('index', 'admin', 'auth');
249 return false;