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.
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 */
28 /** @var $authId int auth source ID for this plugin instance */
33 * @param $settings array
35 function AuthPlugin($settings = array(), $authId = null) {
36 $this->settings
= $settings;
37 $this->authId
= $authId;
42 // General Plugin Functions
46 * Return the name of this plugin.
47 * Should be overridden by subclass.
55 * Return the localized name of this plugin.
56 * Should be overridden by subclass.
59 function getDisplayName() {
60 return 'Abstract Authentication Plugin';
64 * Return the localized description of this plugin.
65 * Should be overridden by subclass.
68 function getDescription() {
69 'Authentication plugin base class';
73 * Return the path to a template for plugin settings.
74 * Can return null if there are no plugin-specific settings.
77 function getSettingsTemplate() {
78 return $this->getTemplatePath() . 'settings.tpl';
87 * Update local user profile from the remote source, if enabled.
89 * @return boolean true if successful
91 function doGetUserInfo(&$user) {
92 if (isset($this->settings
['syncProfiles'])) {
93 return $this->getUserInfo($user);
99 * Update remote user profile, if enabled.
101 * @return boolean true if successful
103 function doSetUserInfo(&$user) {
104 if (isset($this->settings
['syncProfiles'])) {
105 return $this->setUserInfo($user);
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);
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);
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
147 function &getInstance($settings, $authId) {
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) {
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
173 function userExists($username) {
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) {
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) {
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) {
207 * Create a user on the remote source.
208 * @param $user User to create
209 * @return boolean true if successful
211 function createUser(&$user) {
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) {
227 * Return true iff this is a site-wide plugin.
229 function isSitePlugin() {
234 * Return the management verbs for this plugin.
236 function getManagementVerbs() {
240 Locale
::translate('admin.authSources')
245 function manage($verb, $args) {
246 if ($verb === 'authSources') {
247 Request
::redirect('index', 'admin', 'auth');