[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 3 require_once 'Net/IMSP.php'; 4 5 /** 6 * The Net_IMSP_Auth class abstract class for IMSP authentication. 7 * 8 * Required Parameters:<pre> 9 * 'username' Username to logon to IMSP server as. 10 * 'password' Password for current user. 11 * 'server' The hostname of the IMSP server. 12 * 'port' The port of the IMSP server.</pre> 13 * 14 * $Horde: framework/Net_IMSP/IMSP/Auth.php,v 1.8.10.11 2006/01/01 21:28:27 jan Exp $ 15 * 16 * Copyright 2003-2006 Michael Rubinsky <mrubinsk@horde.org> 17 * 18 * See the enclosed file COPYING for license information (LGPL). If you 19 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 20 * 21 * @author Michael Rubinsky <mrubinsk@horde.org> 22 * @package Net_IMSP 23 */ 24 class Net_IMSP_Auth { 25 /** 26 * Class variable to hold the resulting Net_IMSP object 27 * 28 * @var Net_IMSP 29 */ 30 var $_imsp; 31 32 /** 33 * Attempts to login to IMSP server. 34 * 35 * @param array $params Parameters for Net_IMSP 36 * @param boolean $login Should we remain logged in after auth? 37 * 38 * @return mixed Returns a Net_IMSP object connected to 39 * the IMSP server if login is true and 40 * successful. Returns boolean true if 41 * successful and login is false. Returns 42 * PEAR_Error on failure. 43 */ 44 function &authenticate($params, $login = true) 45 { 46 $this->_imsp = &$this->_authenticate($params); 47 48 if (is_a($this->_imsp, 'PEAR_Error')) { 49 return $this->_imsp; 50 } 51 52 if (!$login) { 53 $this->_imsp->logout(); 54 return true; 55 } 56 57 return $this->_imsp; 58 } 59 60 /** 61 * Private authentication function. Provides actual authentication 62 * code. 63 * 64 * @access private 65 * @param array $params Parameters for Net_IMSP_Auth driver. 66 * 67 * @return mixed Returns Net_IMSP object connected to server 68 * if successful, PEAR_Error on failure. 69 * @abstract 70 */ 71 function &_authenticate($params) 72 { 73 74 } 75 76 /** 77 * Returns the type of this driver. 78 * 79 * @abstract 80 * @return string Type of IMSP_Auth driver instance 81 */ 82 function getDriverType() 83 { 84 85 } 86 87 /** 88 * Force a logout from the underlying IMSP stream. 89 * 90 */ 91 function logout() 92 { 93 94 } 95 96 /** 97 * Attempts to return a concrete Net_IMSP_Auth instance based on $driver 98 * Must be called as &Net_IMSP_Auth::factory() 99 * 100 * @param string $driver Type of Net_IMSP_Auth subclass to return. 101 * 102 * @return mixed The created Net_IMSP_Auth subclass or PEAR_Error. 103 */ 104 function &factory($driver) 105 { 106 $driver = basename($driver); 107 108 if (empty($driver) || (strcmp($driver, 'none') == 0)) { 109 $auth = &new IMSP_Auth(); 110 return $auth; 111 } 112 113 if (file_exists(dirname(__FILE__) . '/Auth/' . $driver . '.php')) { 114 require_once dirname(__FILE__) . '/Auth/' . $driver . '.php'; 115 } 116 117 $class = 'Net_IMSP_Auth_' . $driver; 118 119 if (class_exists($class)) { 120 $auth = &new $class(); 121 return $auth; 122 } else { 123 Horde::fatal(PEAR::raiseError(sprintf(_("Unable to load the definition of %s."), $class)), __FILE__, __LINE__); 124 } 125 } 126 127 /** 128 * Attempts to return a concrete Net_IMSP_Auth instance based on $driver. 129 * Will only create a new object if one with the same parameters already 130 * does not exist. 131 * Must be called like: $var = &Net_IMSP_Auth::singleton('driver_type'); 132 * 133 * @param string $driver Type of IMSP_Auth subclass to return. 134 * 135 * @return object Reference to IMSP_Auth subclass. 136 */ 137 function &singleton($driver) 138 { 139 static $instances; 140 /* Check for any imtest driver instances and kill them. 141 Otherwise, the socket will hang between requests from 142 seperate drivers (an Auth request and an Options request).*/ 143 if (is_array($instances)) { 144 foreach ($instances as $obj) { 145 if ($obj->getDriverType() == 'imtest') { 146 $obj->logout(); 147 } 148 } 149 } 150 if (!isset($instances)) { 151 $instances = array(); 152 } 153 154 $signature = serialize(array($driver)); 155 if (!isset($instances[$signature])) { 156 $instances[$signature] = &Net_IMSP_Auth::factory($driver); 157 } 158 159 return $instances[$signature]; 160 } 161 162 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |