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