diff --git a/src/Adapter/DbTable.php b/src/Adapter/DbTable.php index 5e462e3..f53e3a0 100644 --- a/src/Adapter/DbTable.php +++ b/src/Adapter/DbTable.php @@ -29,77 +29,77 @@ class DbTable implements AdapterInterface * * @var DbAdapter */ - protected $_zendDb = null; + protected $zendDb = null; /** * @var DbSelect */ - protected $_dbSelect = null; + protected $dbSelect = null; /** - * $_tableName - the table name to check + * $tableName - the table name to check * * @var string */ - protected $_tableName = null; + protected $tableName = null; /** - * $_identityColumn - the column to use as the identity + * $identityColumn - the column to use as the identity * * @var string */ - protected $_identityColumn = null; + protected $identityColumn = null; /** - * $_credentialColumns - columns to be used as the credentials + * $credentialColumns - columns to be used as the credentials * * @var string */ - protected $_credentialColumn = null; + protected $credentialColumn = null; /** - * $_identity - Identity value + * $identity - Identity value * * @var string */ - protected $_identity = null; + protected $identity = null; /** - * $_credential - Credential values + * $credential - Credential values * * @var string */ - protected $_credential = null; + protected $credential = null; /** - * $_credentialTreatment - Treatment applied to the credential, such as MD5() or PASSWORD() + * $credentialTreatment - Treatment applied to the credential, such as MD5() or PASSWORD() * * @var string */ - protected $_credentialTreatment = null; + protected $credentialTreatment = null; /** - * $_authenticateResultInfo + * $authenticateResultInfo * * @var array */ - protected $_authenticateResultInfo = null; + protected $authenticateResultInfo = null; /** - * $_resultRow - Results of database authentication query + * $resultRow - Results of database authentication query * * @var array */ - protected $_resultRow = null; + protected $resultRow = null; /** - * $_ambiguityIdentity - Flag to indicate same Identity can be used with + * $ambiguityIdentity - Flag to indicate same Identity can be used with * different credentials. Default is FALSE and need to be set to true to * allow ambiguity usage. * * @var boolean */ - protected $_ambiguityIdentity = false; + protected $ambiguityIdentity = false; /** * __construct() - Sets configuration options @@ -114,7 +114,7 @@ class DbTable implements AdapterInterface public function __construct(DbAdapter $zendDb, $tableName = null, $identityColumn = null, $credentialColumn = null, $credentialTreatment = null) { - $this->_zendDb = $zendDb; + $this->zendDb = $zendDb; if (null !== $tableName) { $this->setTableName($tableName); @@ -141,7 +141,7 @@ public function __construct(DbAdapter $zendDb, $tableName = null, $identityColum */ public function setTableName($tableName) { - $this->_tableName = $tableName; + $this->tableName = $tableName; return $this; } @@ -153,7 +153,7 @@ public function setTableName($tableName) */ public function setIdentityColumn($identityColumn) { - $this->_identityColumn = $identityColumn; + $this->identityColumn = $identityColumn; return $this; } @@ -165,7 +165,7 @@ public function setIdentityColumn($identityColumn) */ public function setCredentialColumn($credentialColumn) { - $this->_credentialColumn = $credentialColumn; + $this->credentialColumn = $credentialColumn; return $this; } @@ -188,7 +188,7 @@ public function setCredentialColumn($credentialColumn) */ public function setCredentialTreatment($treatment) { - $this->_credentialTreatment = $treatment; + $this->credentialTreatment = $treatment; return $this; } @@ -200,7 +200,7 @@ public function setCredentialTreatment($treatment) */ public function setIdentity($value) { - $this->_identity = $value; + $this->identity = $value; return $this; } @@ -213,7 +213,7 @@ public function setIdentity($value) */ public function setCredential($credential) { - $this->_credential = $credential; + $this->credential = $credential; return $this; } @@ -228,9 +228,9 @@ public function setCredential($credential) public function setAmbiguityIdentity($flag) { if (is_integer($flag)) { - $this->_ambiguityIdentity = (1 === $flag ? true : false); + $this->ambiguityIdentity = (1 === $flag ? true : false); } elseif (is_bool($flag)) { - $this->_ambiguityIdentity = $flag; + $this->ambiguityIdentity = $flag; } return $this; } @@ -243,7 +243,7 @@ public function setAmbiguityIdentity($flag) */ public function getAmbiguityIdentity() { - return $this->_ambiguityIdentity; + return $this->ambiguityIdentity; } /** @@ -253,10 +253,10 @@ public function getAmbiguityIdentity() */ public function getDbSelect() { - if ($this->_dbSelect == null) { - $this->_dbSelect = new DbSelect(); + if ($this->dbSelect == null) { + $this->dbSelect = new DbSelect(); } - return $this->_dbSelect; + return $this->dbSelect; } /** @@ -268,7 +268,7 @@ public function getDbSelect() */ public function getResultRowObject($returnColumns = null, $omitColumns = null) { - if (!$this->_resultRow) { + if (!$this->resultRow) { return false; } @@ -276,10 +276,10 @@ public function getResultRowObject($returnColumns = null, $omitColumns = null) if (null !== $returnColumns) { - $availableColumns = array_keys($this->_resultRow); + $availableColumns = array_keys($this->resultRow); foreach ((array)$returnColumns as $returnColumn) { if (in_array($returnColumn, $availableColumns)) { - $returnObject->{$returnColumn} = $this->_resultRow[$returnColumn]; + $returnObject->{$returnColumn} = $this->resultRow[$returnColumn]; } } return $returnObject; @@ -287,7 +287,7 @@ public function getResultRowObject($returnColumns = null, $omitColumns = null) } elseif (null !== $omitColumns) { $omitColumns = (array)$omitColumns; - foreach ($this->_resultRow as $resultColumn => $resultValue) { + foreach ($this->resultRow as $resultColumn => $resultValue) { if (!in_array($resultColumn, $omitColumns)) { $returnObject->{$resultColumn} = $resultValue; } @@ -296,7 +296,7 @@ public function getResultRowObject($returnColumns = null, $omitColumns = null) } else { - foreach ($this->_resultRow as $resultColumn => $resultValue) { + foreach ($this->resultRow as $resultColumn => $resultValue) { $returnObject->{$resultColumn} = $resultValue; } return $returnObject; @@ -346,15 +346,15 @@ protected function _authenticateSetup() { $exception = null; - if ($this->_tableName == '') { + if ($this->tableName == '') { $exception = 'A table must be supplied for the DbTable authentication adapter.'; - } elseif ($this->_identityColumn == '') { + } elseif ($this->identityColumn == '') { $exception = 'An identity column must be supplied for the DbTable authentication adapter.'; - } elseif ($this->_credentialColumn == '') { + } elseif ($this->credentialColumn == '') { $exception = 'A credential column must be supplied for the DbTable authentication adapter.'; - } elseif ($this->_identity == '') { + } elseif ($this->identity == '') { $exception = 'A value for the identity was not provided prior to authentication with DbTable.'; - } elseif ($this->_credential === null) { + } elseif ($this->credential === null) { $exception = 'A credential value was not provided prior to authentication with DbTable.'; } @@ -362,9 +362,9 @@ protected function _authenticateSetup() throw new Exception\RuntimeException($exception); } - $this->_authenticateResultInfo = array( + $this->authenticateResultInfo = array( 'code' => AuthenticationResult::FAILURE, - 'identity' => $this->_identity, + 'identity' => $this->identity, 'messages' => array() ); @@ -380,23 +380,23 @@ protected function _authenticateSetup() protected function _authenticateCreateSelect() { // build credential expression - if (empty($this->_credentialTreatment) || (strpos($this->_credentialTreatment, '?') === false)) { - $this->_credentialTreatment = '?'; + if (empty($this->credentialTreatment) || (strpos($this->credentialTreatment, '?') === false)) { + $this->credentialTreatment = '?'; } $credentialExpression = new Expression( '(CASE WHEN ' - . $this->_zendDb->getPlatform()->quoteIdentifier($this->_credentialColumn) - . ' = ' . $this->_credentialTreatment + . $this->zendDb->getPlatform()->quoteIdentifier($this->credentialColumn) + . ' = ' . $this->credentialTreatment . ' THEN 1 ELSE 0 END) AS ' - . $this->_zendDb->getPlatform()->quoteIdentifier('zend_auth_credential_match') + . $this->zendDb->getPlatform()->quoteIdentifier('zend_auth_credential_match') ); // get select $dbSelect = clone $this->getDbSelect(); - $dbSelect->from($this->_tableName) + $dbSelect->from($this->tableName) ->columns(array('*', $credentialExpression)) - ->where($this->_zendDb->getPlatform()->quoteIdentifier($this->_identityColumn) . ' = ?'); + ->where($this->zendDb->getPlatform()->quoteIdentifier($this->identityColumn) . ' = ?'); return $dbSelect; } @@ -411,11 +411,11 @@ protected function _authenticateCreateSelect() */ protected function _authenticateQuerySelect(DbSelect $dbSelect) { - $statement = $this->_zendDb->createStatement(); - $dbSelect->prepareStatement($this->_zendDb, $statement); + $statement = $this->zendDb->createStatement(); + $dbSelect->prepareStatement($this->zendDb, $statement); $resultSet = new ResultSet(); try { - $resultSet->initialize($statement->execute(array($this->_credential, $this->_identity))); + $resultSet->initialize($statement->execute(array($this->credential, $this->identity))); $resultIdentities = $resultSet->toArray(); } catch (\Exception $e) { throw new Exception\RuntimeException( @@ -438,12 +438,12 @@ protected function _authenticateValidateResultSet(array $resultIdentities) { if (count($resultIdentities) < 1) { - $this->_authenticateResultInfo['code'] = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND; - $this->_authenticateResultInfo['messages'][] = 'A record with the supplied identity could not be found.'; + $this->authenticateResultInfo['code'] = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND; + $this->authenticateResultInfo['messages'][] = 'A record with the supplied identity could not be found.'; return $this->_authenticateCreateAuthResult(); } elseif (count($resultIdentities) > 1 && false === $this->getAmbiguityIdentity()) { - $this->_authenticateResultInfo['code'] = AuthenticationResult::FAILURE_IDENTITY_AMBIGUOUS; - $this->_authenticateResultInfo['messages'][] = 'More than one record matches the supplied identity.'; + $this->authenticateResultInfo['code'] = AuthenticationResult::FAILURE_IDENTITY_AMBIGUOUS; + $this->authenticateResultInfo['messages'][] = 'More than one record matches the supplied identity.'; return $this->_authenticateCreateAuthResult(); } @@ -461,16 +461,16 @@ protected function _authenticateValidateResultSet(array $resultIdentities) protected function _authenticateValidateResult($resultIdentity) { if ($resultIdentity['zend_auth_credential_match'] != '1') { - $this->_authenticateResultInfo['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; - $this->_authenticateResultInfo['messages'][] = 'Supplied credential is invalid.'; + $this->authenticateResultInfo['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; + $this->authenticateResultInfo['messages'][] = 'Supplied credential is invalid.'; return $this->_authenticateCreateAuthResult(); } unset($resultIdentity['zend_auth_credential_match']); - $this->_resultRow = $resultIdentity; + $this->resultRow = $resultIdentity; - $this->_authenticateResultInfo['code'] = AuthenticationResult::SUCCESS; - $this->_authenticateResultInfo['messages'][] = 'Authentication successful.'; + $this->authenticateResultInfo['code'] = AuthenticationResult::SUCCESS; + $this->authenticateResultInfo['messages'][] = 'Authentication successful.'; return $this->_authenticateCreateAuthResult(); } @@ -483,9 +483,9 @@ protected function _authenticateValidateResult($resultIdentity) protected function _authenticateCreateAuthResult() { return new AuthenticationResult( - $this->_authenticateResultInfo['code'], - $this->_authenticateResultInfo['identity'], - $this->_authenticateResultInfo['messages'] + $this->authenticateResultInfo['code'], + $this->authenticateResultInfo['identity'], + $this->authenticateResultInfo['messages'] ); } diff --git a/src/Adapter/Digest.php b/src/Adapter/Digest.php index b10df9e..42cc5d7 100644 --- a/src/Adapter/Digest.php +++ b/src/Adapter/Digest.php @@ -24,28 +24,28 @@ class Digest implements AdapterInterface * * @var string */ - protected $_filename; + protected $filename; /** * Digest authentication realm * * @var string */ - protected $_realm; + protected $realm; /** * Digest authentication user * * @var string */ - protected $_username; + protected $username; /** * Password for the user of the realm * * @var string */ - protected $_password; + protected $password; /** * Sets adapter options @@ -73,7 +73,7 @@ public function __construct($filename = null, $realm = null, $username = null, $ */ public function getFilename() { - return $this->_filename; + return $this->filename; } /** @@ -84,7 +84,7 @@ public function getFilename() */ public function setFilename($filename) { - $this->_filename = (string) $filename; + $this->filename = (string) $filename; return $this; } @@ -95,7 +95,7 @@ public function setFilename($filename) */ public function getRealm() { - return $this->_realm; + return $this->realm; } /** @@ -106,7 +106,7 @@ public function getRealm() */ public function setRealm($realm) { - $this->_realm = (string) $realm; + $this->realm = (string) $realm; return $this; } @@ -117,7 +117,7 @@ public function setRealm($realm) */ public function getUsername() { - return $this->_username; + return $this->username; } /** @@ -128,7 +128,7 @@ public function getUsername() */ public function setUsername($username) { - $this->_username = (string) $username; + $this->username = (string) $username; return $this; } @@ -139,7 +139,7 @@ public function setUsername($username) */ public function getPassword() { - return $this->_password; + return $this->password; } /** @@ -150,7 +150,7 @@ public function getPassword() */ public function setPassword($password) { - $this->_password = (string) $password; + $this->password = (string) $password; return $this; } @@ -164,30 +164,30 @@ public function authenticate() { $optionsRequired = array('filename', 'realm', 'username', 'password'); foreach ($optionsRequired as $optionRequired) { - if (null === $this->{"_$optionRequired"}) { + if (null === $this->$optionRequired) { throw new Exception\RuntimeException("Option '$optionRequired' must be set before authentication"); } } - if (false === ($fileHandle = @fopen($this->_filename, 'r'))) { - throw new Exception\UnexpectedValueException("Cannot open '$this->_filename' for reading"); + if (false === ($fileHandle = @fopen($this->filename, 'r'))) { + throw new Exception\UnexpectedValueException("Cannot open '$this->filename' for reading"); } - $id = "$this->_username:$this->_realm"; + $id = "$this->username:$this->realm"; $idLength = strlen($id); $result = array( 'code' => AuthenticationResult::FAILURE, 'identity' => array( - 'realm' => $this->_realm, - 'username' => $this->_username, + 'realm' => $this->realm, + 'username' => $this->username, ), 'messages' => array() ); while ($line = trim(fgets($fileHandle))) { if (substr($line, 0, $idLength) === $id) { - if ($this->_secureStringCompare(substr($line, -32), md5("$this->_username:$this->_realm:$this->_password"))) { + if ($this->_secureStringCompare(substr($line, -32), md5("$this->username:$this->realm:$this->password"))) { $result['code'] = AuthenticationResult::SUCCESS; } else { $result['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; @@ -198,7 +198,7 @@ public function authenticate() } $result['code'] = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND; - $result['messages'][] = "Username '$this->_username' and realm '$this->_realm' combination not found"; + $result['messages'][] = "Username '$this->username' and realm '$this->realm' combination not found"; return new AuthenticationResult($result['code'], $result['identity'], $result['messages']); } diff --git a/src/Adapter/Http.php b/src/Adapter/Http.php index 336ed38..2999e7d 100644 --- a/src/Adapter/Http.php +++ b/src/Adapter/Http.php @@ -34,70 +34,70 @@ class Http implements AdapterInterface * * @var HTTPRequest */ - protected $_request; + protected $request; /** * Reference to the HTTP Response object * * @var HTTPResponse */ - protected $_response; + protected $response; /** * Object that looks up user credentials for the Basic scheme * * @var Http\ResolverInterface */ - protected $_basicResolver; + protected $basicResolver; /** * Object that looks up user credentials for the Digest scheme * * @var Http\ResolverInterface */ - protected $_digestResolver; + protected $digestResolver; /** * List of authentication schemes supported by this class * * @var array */ - protected $_supportedSchemes = array('basic', 'digest'); + protected $supportedSchemes = array('basic', 'digest'); /** * List of schemes this class will accept from the client * * @var array */ - protected $_acceptSchemes; + protected $acceptSchemes; /** * Space-delimited list of protected domains for Digest Auth * * @var string */ - protected $_domains; + protected $domains; /** * The protection realm to use * * @var string */ - protected $_realm; + protected $realm; /** * Nonce timeout period * * @var integer */ - protected $_nonceTimeout; + protected $nonceTimeout; /** * Whether to send the opaque value in the header. True by default * * @var boolean */ - protected $_useOpaque; + protected $useOpaque; /** * List of the supported digest algorithms. I want to support both MD5 and @@ -105,14 +105,14 @@ class Http implements AdapterInterface * * @var array */ - protected $_supportedAlgos = array('MD5'); + protected $supportedAlgos = array('MD5'); /** * The actual algorithm to use. Defaults to MD5 * * @var string */ - protected $_algo; + protected $algo; /** * List of supported qop options. My intetion is to support both 'auth' and @@ -120,7 +120,7 @@ class Http implements AdapterInterface * * @var array */ - protected $_supportedQops = array('auth'); + protected $supportedQops = array('auth'); /** * Whether or not to do Proxy Authentication instead of origin server @@ -128,14 +128,14 @@ class Http implements AdapterInterface * * @var boolean */ - protected $_imaProxy; + protected $imaProxy; /** * Flag indicating the client is IE and didn't bother to return the opaque string * * @var boolean */ - protected $_ieNoOpaque; + protected $ieNoOpaque; /** * Constructor @@ -146,26 +146,26 @@ class Http implements AdapterInterface * 'digest_domains' => Space-delimited list of URIs * 'nonce_timeout' => * 'use_opaque' => Whether to send the opaque value in the header - * 'alogrithm' => See $_supportedAlgos. Default: MD5 + * 'alogrithm' => See $supportedAlgos. Default: MD5 * 'proxy_auth' => Whether to do authentication as a Proxy * @throws Exception\InvalidArgumentException */ public function __construct(array $config) { - $this->_request = null; - $this->_response = null; - $this->_ieNoOpaque = false; + $this->request = null; + $this->response = null; + $this->ieNoOpaque = false; if (empty($config['accept_schemes'])) { throw new Exception\InvalidArgumentException('Config key "accept_schemes" is required'); } $schemes = explode(' ', $config['accept_schemes']); - $this->_acceptSchemes = array_intersect($schemes, $this->_supportedSchemes); - if (empty($this->_acceptSchemes)) { + $this->acceptSchemes = array_intersect($schemes, $this->supportedSchemes); + if (empty($this->acceptSchemes)) { throw new Exception\InvalidArgumentException(sprintf( 'No supported schemes given in "accept_schemes". Valid values: %s', - implode(', ', $this->_supportedSchemes) + implode(', ', $this->supportedSchemes) )); } @@ -180,10 +180,10 @@ public function __construct(array $config) . 'excluding quotation marks and colons' ); } else { - $this->_realm = $config['realm']; + $this->realm = $config['realm']; } - if (in_array('digest', $this->_acceptSchemes)) { + if (in_array('digest', $this->acceptSchemes)) { if (empty($config['digest_domains']) || !ctype_print($config['digest_domains']) || strpos($config['digest_domains'], '"') !== false) { @@ -192,7 +192,7 @@ public function __construct(array $config) . 'only printable characters, excluding quotation marks' ); } else { - $this->_domains = $config['digest_domains']; + $this->domains = $config['digest_domains']; } if (empty($config['nonce_timeout']) || @@ -201,75 +201,75 @@ public function __construct(array $config) 'Config key \'nonce_timeout\' is required, and must be an integer' ); } else { - $this->_nonceTimeout = (int) $config['nonce_timeout']; + $this->nonceTimeout = (int) $config['nonce_timeout']; } // We use the opaque value unless explicitly told not to if (isset($config['use_opaque']) && false == (bool) $config['use_opaque']) { - $this->_useOpaque = false; + $this->useOpaque = false; } else { - $this->_useOpaque = true; + $this->useOpaque = true; } - if (isset($config['algorithm']) && in_array($config['algorithm'], $this->_supportedAlgos)) { - $this->_algo = $config['algorithm']; + if (isset($config['algorithm']) && in_array($config['algorithm'], $this->supportedAlgos)) { + $this->algo = $config['algorithm']; } else { - $this->_algo = 'MD5'; + $this->algo = 'MD5'; } } // Don't be a proxy unless explicitly told to do so if (isset($config['proxy_auth']) && true == (bool) $config['proxy_auth']) { - $this->_imaProxy = true; // I'm a Proxy + $this->imaProxy = true; // I'm a Proxy } else { - $this->_imaProxy = false; + $this->imaProxy = false; } } /** - * Setter for the _basicResolver property + * Setter for the basicResolver property * * @param Http\ResolverInterface $resolver * @return Http Provides a fluent interface */ public function setBasicResolver(Http\ResolverInterface $resolver) { - $this->_basicResolver = $resolver; + $this->basicResolver = $resolver; return $this; } /** - * Getter for the _basicResolver property + * Getter for the basicResolver property * * @return Http\ResolverInterface */ public function getBasicResolver() { - return $this->_basicResolver; + return $this->basicResolver; } /** - * Setter for the _digestResolver property + * Setter for the digestResolver property * * @param Http\ResolverInterface $resolver * @return Http Provides a fluent interface */ public function setDigestResolver(Http\ResolverInterface $resolver) { - $this->_digestResolver = $resolver; + $this->digestResolver = $resolver; return $this; } /** - * Getter for the _digestResolver property + * Getter for the digestResolver property * * @return Http\ResolverInterface */ public function getDigestResolver() { - return $this->_digestResolver; + return $this->digestResolver; } /** @@ -280,7 +280,7 @@ public function getDigestResolver() */ public function setRequest(HTTPRequest $request) { - $this->_request = $request; + $this->request = $request; return $this; } @@ -292,7 +292,7 @@ public function setRequest(HTTPRequest $request) */ public function getRequest() { - return $this->_request; + return $this->request; } /** @@ -303,7 +303,7 @@ public function getRequest() */ public function setResponse(HTTPResponse $response) { - $this->_response = $response; + $this->response = $response; return $this; } @@ -315,7 +315,7 @@ public function setResponse(HTTPResponse $response) */ public function getResponse() { - return $this->_response; + return $this->response; } /** @@ -326,18 +326,18 @@ public function getResponse() */ public function authenticate() { - if (empty($this->_request) || empty($this->_response)) { + if (empty($this->request) || empty($this->response)) { throw new Exception\RuntimeException('Request and Response objects must be set before calling ' . 'authenticate()'); } - if ($this->_imaProxy) { + if ($this->imaProxy) { $getHeader = 'Proxy-Authorization'; } else { $getHeader = 'Authorization'; } - $headers = $this->_request->getHeaders(); + $headers = $this->request->getHeaders(); if (!$headers->has($getHeader)) { return $this->_challengeClient(); } @@ -351,8 +351,8 @@ public function authenticate() // The server can issue multiple challenges, but the client should // answer with only the selected auth scheme. - if (!in_array($clientScheme, $this->_supportedSchemes)) { - $this->_response->setStatusCode(400); + if (!in_array($clientScheme, $this->supportedSchemes)) { + $this->response->setStatusCode(400); return new Authentication\Result( Authentication\Result::FAILURE_UNCATEGORIZED, array(), @@ -361,7 +361,7 @@ public function authenticate() } // client sent a scheme that is not the one required - if (!in_array($clientScheme, $this->_acceptSchemes)) { + if (!in_array($clientScheme, $this->acceptSchemes)) { // challenge again the client return $this->_challengeClient(); } @@ -390,7 +390,7 @@ public function authenticate() */ protected function _challengeClient() { - if ($this->_imaProxy) { + if ($this->imaProxy) { $statusCode = 407; $headerName = 'Proxy-Authenticate'; } else { @@ -398,14 +398,14 @@ protected function _challengeClient() $headerName = 'WWW-Authenticate'; } - $this->_response->setStatusCode($statusCode); + $this->response->setStatusCode($statusCode); // Send a challenge in each acceptable authentication scheme - $headers = $this->_response->getHeaders(); - if (in_array('basic', $this->_acceptSchemes)) { + $headers = $this->response->getHeaders(); + if (in_array('basic', $this->acceptSchemes)) { $headers->addHeaderLine($headerName, $this->_basicHeader()); } - if (in_array('digest', $this->_acceptSchemes)) { + if (in_array('digest', $this->acceptSchemes)) { $headers->addHeaderLine($headerName, $this->_digestHeader()); } return new Authentication\Result( @@ -425,7 +425,7 @@ protected function _challengeClient() */ protected function _basicHeader() { - return 'Basic realm="' . $this->_realm . '"'; + return 'Basic realm="' . $this->realm . '"'; } /** @@ -438,12 +438,12 @@ protected function _basicHeader() */ protected function _digestHeader() { - $wwwauth = 'Digest realm="' . $this->_realm . '", ' - . 'domain="' . $this->_domains . '", ' + $wwwauth = 'Digest realm="' . $this->realm . '", ' + . 'domain="' . $this->domains . '", ' . 'nonce="' . $this->_calcNonce() . '", ' - . ($this->_useOpaque ? 'opaque="' . $this->_calcOpaque() . '", ' : '') - . 'algorithm="' . $this->_algo . '", ' - . 'qop="' . implode(',', $this->_supportedQops) . '"'; + . ($this->useOpaque ? 'opaque="' . $this->_calcOpaque() . '", ' : '') + . 'algorithm="' . $this->algo . '", ' + . 'qop="' . implode(',', $this->supportedQops) . '"'; return $wwwauth; } @@ -460,7 +460,7 @@ protected function _basicAuth($header) if (empty($header)) { throw new Exception\RuntimeException('The value of the client Authorization header is required'); } - if (empty($this->_basicResolver)) { + if (empty($this->basicResolver)) { throw new Exception\RuntimeException( 'A basicResolver object must be set before doing Basic ' . 'authentication'); @@ -485,13 +485,13 @@ protected function _basicAuth($header) return $this->_challengeClient(); } - $result = $this->_basicResolver->resolve($creds[0], $this->_realm, $creds[1]); + $result = $this->basicResolver->resolve($creds[0], $this->realm, $creds[1]); if ($result && !is_array($result) && $this->_secureStringCompare($result, $creds[1]) ) { - $identity = array('username'=>$creds[0], 'realm'=>$this->_realm); + $identity = array('username'=>$creds[0], 'realm'=>$this->realm); return new Authentication\Result(Authentication\Result::SUCCESS, $identity); } elseif (is_array($result)) { return new Authentication\Result(Authentication\Result::SUCCESS, $result); @@ -512,13 +512,13 @@ protected function _digestAuth($header) if (empty($header)) { throw new Exception\RuntimeException('The value of the client Authorization header is required'); } - if (empty($this->_digestResolver)) { + if (empty($this->digestResolver)) { throw new Exception\RuntimeException('A digestResolver object must be set before doing Digest authentication'); } $data = $this->_parseDigestAuth($header); if ($data === false) { - $this->_response->setStatusCode(400); + $this->response->setStatusCode(400); return new Authentication\Result( Authentication\Result::FAILURE_UNCATEGORIZED, array(), @@ -538,7 +538,7 @@ protected function _digestAuth($header) } // The opaque value is also required to match, but of course IE doesn't // play ball. - if (!$this->_ieNoOpaque && $this->_calcOpaque() != $data['opaque']) { + if (!$this->ieNoOpaque && $this->_calcOpaque() != $data['opaque']) { return $this->_challengeClient(); } @@ -546,7 +546,7 @@ protected function _digestAuth($header) // This makes no assumptions about how the password hash was // constructed beyond that it must have been built in such a way as // to be recreatable with the current settings of this object. - $ha1 = $this->_digestResolver->resolve($data['username'], $data['realm']); + $ha1 = $this->digestResolver->resolve($data['username'], $data['realm']); if ($ha1 === false) { return $this->_challengeClient(); } @@ -554,7 +554,7 @@ protected function _digestAuth($header) // If MD5-sess is used, a1 value is made of the user's password // hash with the server and client nonce appended, separated by // colons. - if ($this->_algo == 'MD5-sess') { + if ($this->algo == 'MD5-sess') { $ha1 = hash('md5', $ha1 . ':' . $data['nonce'] . ':' . $data['cnonce']); } @@ -562,7 +562,7 @@ protected function _digestAuth($header) // option selected by the client and the supported hash functions switch ($data['qop']) { case 'auth': - $a2 = $this->_request->getMethod() . ':' . $data['uri']; + $a2 = $this->request->getMethod() . ':' . $data['uri']; break; case 'auth-int': // Should be REQUEST_METHOD . ':' . uri . ':' . hash(entity-body), @@ -598,7 +598,7 @@ protected function _digestAuth($header) protected function _calcNonce() { // Once subtle consequence of this timeout calculation is that it - // actually divides all of time into _nonceTimeout-sized sections, such + // actually divides all of time into nonceTimeout-sized sections, such // that the value of timeout is the point in time of the next // approaching "boundary" of a section. This allows the server to // consistently generate the same timeout (and hence the same nonce @@ -606,9 +606,9 @@ protected function _calcNonce() // "boundaries" is not crossed between requests. If that happens, the // nonce will change on its own, and effectively log the user out. This // would be surprising if the user just logged in. - $timeout = ceil(time() / $this->_nonceTimeout) * $this->_nonceTimeout; + $timeout = ceil(time() / $this->nonceTimeout) * $this->nonceTimeout; - $userAgentHeader = $this->_request->getHeaders()->get('User-Agent'); + $userAgentHeader = $this->request->getHeaders()->get('User-Agent'); if ($userAgentHeader) { $userAgent = $userAgentHeader->getFieldValue(); } elseif (isset($_SERVER['HTTP_USER_AGENT'])) { @@ -690,7 +690,7 @@ protected function _parseDigestAuth($header) // Section 3.2.2.5 in RFC 2617 says the authenticating server must // verify that the URI field in the Authorization header is for the // same resource requested in the Request Line. - $rUri = $this->_request->getUri(); + $rUri = $this->request->getUri(); $cUri = UriFactory::factory($temp[1]); // Make sure the path portion of both URIs is the same @@ -719,12 +719,12 @@ protected function _parseDigestAuth($header) // The spec says this should default to MD5 if omitted. OK, so how does // that square with the algo we send out in the WWW-Authenticate header, // if it can easily be overridden by the client? - $ret = preg_match('/algorithm="?(' . $this->_algo . ')"?/', $header, $temp); + $ret = preg_match('/algorithm="?(' . $this->algo . ')"?/', $header, $temp); if ($ret && !empty($temp[1]) - && in_array($temp[1], $this->_supportedAlgos)) { + && in_array($temp[1], $this->supportedAlgos)) { $data['algorithm'] = $temp[1]; } else { - $data['algorithm'] = 'MD5'; // = $this->_algo; ? + $data['algorithm'] = 'MD5'; // = $this->algo; ? } $temp = null; @@ -741,12 +741,12 @@ protected function _parseDigestAuth($header) $temp = null; // If the server sent an opaque value, the client must send it back - if ($this->_useOpaque) { + if ($this->useOpaque) { $ret = preg_match('/opaque="([^"]+)"/', $header, $temp); if (!$ret || empty($temp[1])) { // Big surprise: IE isn't RFC 2617-compliant. - $headers = $this->_request->getHeaders(); + $headers = $this->request->getHeaders(); if (!$headers->has('User-Agent')) { return false; } @@ -756,11 +756,11 @@ protected function _parseDigestAuth($header) } $temp[1] = ''; - $this->_ieNoOpaque = true; + $this->ieNoOpaque = true; } // This implementation only sends MD5 hex strings in the opaque value - if (!$this->_ieNoOpaque && + if (!$this->ieNoOpaque && (32 != strlen($temp[1]) || !ctype_xdigit($temp[1]))) { return false; } else { @@ -771,11 +771,11 @@ protected function _parseDigestAuth($header) // Not optional in this implementation, but must be one of the supported // qop types - $ret = preg_match('/qop="?(' . implode('|', $this->_supportedQops) . ')"?/', $header, $temp); + $ret = preg_match('/qop="?(' . implode('|', $this->supportedQops) . ')"?/', $header, $temp); if (!$ret || empty($temp[1])) { return false; } - if (!in_array($temp[1], $this->_supportedQops)) { + if (!in_array($temp[1], $this->supportedQops)) { return false; } else { $data['qop'] = $temp[1]; diff --git a/src/Adapter/Http/FileResolver.php b/src/Adapter/Http/FileResolver.php index 96ccf7f..45b0a07 100644 --- a/src/Adapter/Http/FileResolver.php +++ b/src/Adapter/Http/FileResolver.php @@ -24,7 +24,7 @@ class FileResolver implements ResolverInterface * * @var string */ - protected $_file; + protected $file; /** * Constructor @@ -50,7 +50,7 @@ public function setFile($path) if (empty($path) || !is_readable($path)) { throw new Exception\InvalidArgumentException('Path not readable: ' . $path); } - $this->_file = $path; + $this->file = $path; return $this; } @@ -62,7 +62,7 @@ public function setFile($path) */ public function getFile() { - return $this->_file; + return $this->file; } /** @@ -102,9 +102,9 @@ public function resolve($username, $realm, $password = null) } // Open file, read through looking for matching credentials - $fp = @fopen($this->_file, 'r'); + $fp = @fopen($this->file, 'r'); if (!$fp) { - throw new Exception\RuntimeException('Unable to open password file: ' . $this->_file); + throw new Exception\RuntimeException('Unable to open password file: ' . $this->file); } // No real validation is done on the contents of the password file. The diff --git a/src/Result.php b/src/Result.php index f2544b4..5ea0a4f 100644 --- a/src/Result.php +++ b/src/Result.php @@ -51,14 +51,14 @@ class Result * * @var int */ - protected $_code; + protected $code; /** * The identity used in the authentication attempt * * @var mixed */ - protected $_identity; + protected $identity; /** * An array of string reasons why the authentication attempt was unsuccessful @@ -67,7 +67,7 @@ class Result * * @var array */ - protected $_messages; + protected $messages; /** * Sets the result code, identity, and failure messages @@ -86,9 +86,9 @@ public function __construct($code, $identity, array $messages = array()) $code = 1; } - $this->_code = $code; - $this->_identity = $identity; - $this->_messages = $messages; + $this->code = $code; + $this->identity = $identity; + $this->messages = $messages; } /** @@ -98,7 +98,7 @@ public function __construct($code, $identity, array $messages = array()) */ public function isValid() { - return ($this->_code > 0) ? true : false; + return ($this->code > 0) ? true : false; } /** @@ -108,7 +108,7 @@ public function isValid() */ public function getCode() { - return $this->_code; + return $this->code; } /** @@ -118,7 +118,7 @@ public function getCode() */ public function getIdentity() { - return $this->_identity; + return $this->identity; } /** @@ -130,6 +130,6 @@ public function getIdentity() */ public function getMessages() { - return $this->_messages; + return $this->messages; } } diff --git a/src/Storage/NonPersistent.php b/src/Storage/NonPersistent.php index 07922a2..a85008c 100644 --- a/src/Storage/NonPersistent.php +++ b/src/Storage/NonPersistent.php @@ -26,7 +26,7 @@ class NonPersistent implements StorageInterface /** * Holds the actual auth data */ - protected $_data; + protected $data; /** * Returns true if and only if storage is empty @@ -36,7 +36,7 @@ class NonPersistent implements StorageInterface */ public function isEmpty() { - return empty($this->_data); + return empty($this->data); } /** @@ -47,7 +47,7 @@ public function isEmpty() */ public function read() { - return $this->_data; + return $this->data; } /** @@ -58,7 +58,7 @@ public function read() */ public function write($contents) { - $this->_data = $contents; + $this->data = $contents; } /** @@ -68,6 +68,6 @@ public function write($contents) */ public function clear() { - $this->_data = null; + $this->data = null; } }