Skip to content

Commit

Permalink
Implement #6: remove Zend_Auth_Adapter_Exception class
Browse files Browse the repository at this point in the history
  • Loading branch information
Bui Sy Nguyen committed Jan 21, 2016
1 parent 99b2f8c commit 127ea4c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 153 deletions.
8 changes: 2 additions & 6 deletions fproject/Zend/Amf/Adobe/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,15 @@ public function getAcl()
/**
* Perform authentication
*
* @throws Zend_Auth_Adapter_Exception
* @throws \fproject\amf\AmfException
* @return Zend_Auth_Result
* @see Zend_Auth_Adapter_Interface#authenticate()
*/
public function authenticate()
{
if (empty($this->_username) ||
empty($this->_password)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('Username/password should be set');
throw new \fproject\amf\AmfException('Username/password should be set');
}

if(!isset($this->_users[$this->_username])) {
Expand Down
23 changes: 7 additions & 16 deletions fproject/Zend/Auth/Adapter/DbTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function __construct(Zend_Db_Adapter_Abstract $zendDb = null, $tableName
* _setDbAdapter() - set the database adapter to be used for quering
*
* @param Zend_Db_Adapter_Abstract
* @throws Zend_Auth_Adapter_Exception
* @throws \fproject\amf\AmfException
* @return Zend_Auth_Adapter_DbTable
*/
protected function _setDbAdapter(Zend_Db_Adapter_Abstract $zendDb = null)
Expand All @@ -174,8 +174,7 @@ protected function _setDbAdapter(Zend_Db_Adapter_Abstract $zendDb = null)
require_once 'Zend/Db/Table/Abstract.php';
$this->_zendDb = Zend_Db_Table_Abstract::getDefaultAdapter();
if (null === $this->_zendDb) {
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('No database adapter present');
throw new \fproject\amf\AmfException('No database adapter present');
}
}

Expand Down Expand Up @@ -359,7 +358,7 @@ public function getResultRowObject($returnColumns = null, $omitColumns = null)
* been configured with all necessary information to successfully connect to a database
* table and attempt to find a record matching the provided identity.
*
* @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
* @throws \fproject\amf\AmfException if answering the authentication query is impossible
* @return Zend_Auth_Result
*/
public function authenticate()
Expand Down Expand Up @@ -392,7 +391,7 @@ public function authenticate()
* making sure that this adapter was indeed setup properly with all
* required pieces of information.
*
* @throws Zend_Auth_Adapter_Exception - in the event that setup was not done properly
* @throws \fproject\amf\AmfException - in the event that setup was not done properly
* @return true
*/
protected function _authenticateSetup()
Expand All @@ -412,11 +411,7 @@ protected function _authenticateSetup()
}

if (null !== $exception) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception($exception);
throw new \fproject\amf\AmfException($exception);
}

$this->_authenticateResultInfo = array(
Expand Down Expand Up @@ -466,7 +461,7 @@ protected function _authenticateCreateSelect()
* performs a query against the database with that object.
*
* @param Zend_Db_Select $dbSelect
* @throws Zend_Auth_Adapter_Exception - when an invalid select
* @throws \fproject\amf\AmfException - when an invalid select
* object is encountered
* @return array
*/
Expand All @@ -483,11 +478,7 @@ protected function _authenticateQuerySelect(Zend_Db_Select $dbSelect)
unset($origDbFetchMode);
}
} catch (Exception $e) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('The supplied parameters to Zend_Auth_Adapter_DbTable failed to '
throw new \fproject\amf\AmfException('The supplied parameters to Zend_Auth_Adapter_DbTable failed to '
. 'produce a valid sql statement, please check table and column names '
. 'for validity.', 0, $e);
}
Expand Down
14 changes: 3 additions & 11 deletions fproject/Zend/Auth/Adapter/Digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,20 @@ public function setPassword($password)
/**
* Defined by Zend_Auth_Adapter_Interface
*
* @throws Zend_Auth_Adapter_Exception
* @throws \fproject\amf\AmfException
* @return Zend_Auth_Result
*/
public function authenticate()
{
$optionsRequired = array('filename', 'realm', 'username', 'password');
foreach ($optionsRequired as $optionRequired) {
if (null === $this->{"_$optionRequired"}) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception("Option '$optionRequired' must be set before authentication");
throw new \fproject\amf\AmfException("Option '$optionRequired' must be set before authentication");
}
}

if (false === ($fileHandle = @fopen($this->_filename, 'r'))) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception("Cannot open '$this->_filename' for reading");
throw new \fproject\amf\AmfException("Cannot open '$this->_filename' for reading");
}

$id = "$this->_username:$this->_realm";
Expand Down
38 changes: 0 additions & 38 deletions fproject/Zend/Auth/Adapter/Exception.php

This file was deleted.

92 changes: 18 additions & 74 deletions fproject/Zend/Auth/Adapter/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,13 @@ class Zend_Auth_Adapter_Http implements Zend_Auth_Adapter_Interface
* 'use_opaque' => <bool> Whether to send the opaque value in the header
* 'alogrithm' => <string> See $_supportedAlgos. Default: MD5
* 'proxy_auth' => <bool> Whether to do authentication as a Proxy
* @throws Zend_Auth_Adapter_Exception
* @throws \fproject\amf\AmfException
* @return void
*/
public function __construct(array $config)
{
if (!extension_loaded('hash')) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception(__CLASS__ . ' requires the \'hash\' extension');
throw new \fproject\amf\AmfException(__CLASS__ . ' requires the \'hash\' extension');
}

$this->_request = null;
Expand All @@ -181,21 +177,13 @@ public function __construct(array $config)


if (empty($config['accept_schemes'])) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('Config key \'accept_schemes\' is required');
throw new \fproject\amf\AmfException('Config key \'accept_schemes\' is required');
}

$schemes = explode(' ', $config['accept_schemes']);
$this->_acceptSchemes = array_intersect($schemes, $this->_supportedSchemes);
if (empty($this->_acceptSchemes)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('No supported schemes given in \'accept_schemes\'. Valid values: '
throw new \fproject\amf\AmfException('No supported schemes given in \'accept_schemes\'. Valid values: '
. implode(', ', $this->_supportedSchemes));
}

Expand All @@ -205,11 +193,7 @@ public function __construct(array $config)
!ctype_print($config['realm']) ||
strpos($config['realm'], ':') !== false ||
strpos($config['realm'], '"') !== false) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('Config key \'realm\' is required, and must contain only printable '
throw new \fproject\amf\AmfException('Config key \'realm\' is required, and must contain only printable '
. 'characters, excluding quotation marks and colons');
} else {
$this->_realm = $config['realm'];
Expand All @@ -219,23 +203,15 @@ public function __construct(array $config)
if (empty($config['digest_domains']) ||
!ctype_print($config['digest_domains']) ||
strpos($config['digest_domains'], '"') !== false) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('Config key \'digest_domains\' is required, and must contain '
throw new \fproject\amf\AmfException('Config key \'digest_domains\' is required, and must contain '
. 'only printable characters, excluding quotation marks');
} else {
$this->_domains = $config['digest_domains'];
}

if (empty($config['nonce_timeout']) ||
!is_numeric($config['nonce_timeout'])) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('Config key \'nonce_timeout\' is required, and must be an '
throw new \fproject\amf\AmfException('Config key \'nonce_timeout\' is required, and must be an '
. 'integer');
} else {
$this->_nonceTimeout = (int) $config['nonce_timeout'];
Expand Down Expand Up @@ -358,18 +334,14 @@ public function getResponse()
/**
* Authenticate
*
* @throws Zend_Auth_Adapter_Exception
* @throws \fproject\amf\AmfException
* @return Zend_Auth_Result
*/
public function authenticate()
{
if (empty($this->_request) ||
empty($this->_response)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('Request and Response objects must be set before calling '
throw new \fproject\amf\AmfException('Request and Response objects must be set before calling '
. 'authenticate()');
}

Expand Down Expand Up @@ -412,11 +384,7 @@ public function authenticate()
$result = $this->_digestAuth($authHeader);
break;
default:
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('Unsupported authentication scheme');
throw new \fproject\amf\AmfException('Unsupported authentication scheme');
}

return $result;
Expand Down Expand Up @@ -493,36 +461,24 @@ protected function _digestHeader()
* Basic Authentication
*
* @param string $header Client's Authorization header
* @throws Zend_Auth_Adapter_Exception
* @throws \fproject\amf\AmfException
* @return Zend_Auth_Result
*/
protected function _basicAuth($header)
{
if (empty($header)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('The value of the client Authorization header is required');
throw new \fproject\amf\AmfException('The value of the client Authorization header is required');
}
if (empty($this->_basicResolver)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('A basicResolver object must be set before doing Basic '
throw new \fproject\amf\AmfException('A basicResolver object must be set before doing Basic '
. 'authentication');
}

// Decode the Authorization header
$auth = substr($header, strlen('Basic '));
$auth = base64_decode($auth);
if (!$auth) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('Unable to base64_decode Authorization header value');
throw new \fproject\amf\AmfException('Unable to base64_decode Authorization header value');
}

// See ZF-1253. Validate the credentials the same way the digest
Expand Down Expand Up @@ -550,24 +506,16 @@ protected function _basicAuth($header)
* Digest Authentication
*
* @param string $header Client's Authorization header
* @throws Zend_Auth_Adapter_Exception
* @throws \fproject\amf\AmfException
* @return Zend_Auth_Result Valid auth result only on successful auth
*/
protected function _digestAuth($header)
{
if (empty($header)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('The value of the client Authorization header is required');
throw new \fproject\amf\AmfException('The value of the client Authorization header is required');
}
if (empty($this->_digestResolver)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('A digestResolver object must be set before doing Digest authentication');
throw new \fproject\amf\AmfException('A digestResolver object must be set before doing Digest authentication');
}

$data = $this->_parseDigestAuth($header);
Expand Down Expand Up @@ -622,11 +570,7 @@ protected function _digestAuth($header)
// Should be REQUEST_METHOD . ':' . uri . ':' . hash(entity-body),
// but this isn't supported yet, so fall through to default case
default:
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('Client requested an unsupported qop option');
throw new \fproject\amf\AmfException('Client requested an unsupported qop option');
}
// Using hash() should make parameterizing the hash algorithm
// easier
Expand Down
2 changes: 1 addition & 1 deletion fproject/Zend/Auth/Adapter/Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface Zend_Auth_Adapter_Interface
/**
* Performs an authentication attempt
*
* @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
* @throws \fproject\amf\AmfException If authentication cannot be performed
* @return Zend_Auth_Result
*/
public function authenticate();
Expand Down
8 changes: 2 additions & 6 deletions fproject/Zend/Auth/Adapter/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected function _getAuthorityName()
/**
* Authenticate the user
*
* @throws Zend_Auth_Adapter_Exception
* @throws \fproject\amf\AmfException
* @return Zend_Auth_Result
*/
public function authenticate()
Expand Down Expand Up @@ -282,11 +282,7 @@ public function authenticate()
foreach ($this->_options as $name => $options) {

if (!is_array($options)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('Adapter options array not an array');
throw new \fproject\amf\AmfException('Adapter options array not an array');
}
$adapterOptions = $this->_prepareOptions($ldap, $options);
$dname = '';
Expand Down
Loading

0 comments on commit 127ea4c

Please sign in to comment.