Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#3642 branch 'hotfix/au…
Browse files Browse the repository at this point in the history
…thentication-db-fix'
  • Loading branch information
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/Adapter/DbTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
use Zend\Authentication\Result as AuthenticationResult;
use Zend\Db\Adapter\Adapter as DbAdapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Expression;
use Zend\Db\Sql\Select as DbSelect;
use Zend\Db\Sql;
use Zend\Db\Sql\Expression as SqlExpr;
use Zend\Db\Sql\Predicate\Operator as SqlOp;

class DbTable extends AbstractAdapter
{
Expand All @@ -27,7 +28,7 @@ class DbTable extends AbstractAdapter
protected $zendDb = null;

/**
* @var DbSelect
* @var Sql\Select
*/
protected $dbSelect = null;

Expand Down Expand Up @@ -205,12 +206,12 @@ public function getAmbiguityIdentity()
/**
* getDbSelect() - Return the preauthentication Db Select object for userland select query modification
*
* @return DbSelect
* @return Sql\Select
*/
public function getDbSelect()
{
if ($this->dbSelect == null) {
$this->dbSelect = new DbSelect();
$this->dbSelect = new Sql\Select();
}
return $this->dbSelect;
}
Expand Down Expand Up @@ -338,19 +339,17 @@ protected function _authenticateCreateSelect()
$this->credentialTreatment = '?';
}

$credentialExpression = new Expression(
'(CASE WHEN '
. $this->zendDb->getPlatform()->quoteIdentifier($this->credentialColumn)
. ' = ' . $this->credentialTreatment
. ' THEN 1 ELSE 0 END) AS '
. $this->zendDb->getPlatform()->quoteIdentifier('zend_auth_credential_match')
$credentialExpression = new SqlExpr(
'(CASE WHEN ?' . ' = ' . $this->credentialTreatment . ' THEN 1 ELSE 0 END) AS ?',
array($this->credentialColumn, $this->credential, 'zend_auth_credential_match'),
array(SqlExpr::TYPE_IDENTIFIER, SqlExpr::TYPE_VALUE, SqlExpr::TYPE_IDENTIFIER)
);

// get select
$dbSelect = clone $this->getDbSelect();
$dbSelect->from($this->tableName)
->columns(array('*', $credentialExpression))
->where($this->zendDb->getPlatform()->quoteIdentifier($this->identityColumn) . ' = ?');
->columns(array('*', $credentialExpression))
->where(new SqlOp($this->identityColumn, '=', $this->identity));

return $dbSelect;
}
Expand All @@ -363,14 +362,17 @@ protected function _authenticateCreateSelect()
* @throws Exception\RuntimeException when an invalid select object is encountered
* @return array
*/
protected function _authenticateQuerySelect(DbSelect $dbSelect)
protected function _authenticateQuerySelect(Sql\Select $dbSelect)
{
$statement = $this->zendDb->createStatement();
$dbSelect->prepareStatement($this->zendDb, $statement);
$resultSet = new ResultSet();
$sql = new Sql\Sql($this->zendDb);
$statement = $sql->prepareStatementForSqlObject($dbSelect);
try {
$resultSet->initialize($statement->execute(array($this->credential, $this->identity)));
$resultIdentities = $resultSet->toArray();
$result = $statement->execute();
$resultIdentities = array();
// iterate result, most cross platform way
foreach ($result as $row) {
$resultIdentities[] = $row;
}
} catch (\Exception $e) {
throw new Exception\RuntimeException(
'The supplied parameters to DbTable failed to '
Expand Down

0 comments on commit 8c5486e

Please sign in to comment.