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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
Fixed files permissions
  • Loading branch information
Show file tree
Hide file tree
Showing 38 changed files with 1,185 additions and 288 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.4-dev",
"dev-develop": "2.5-dev"
"dev-master": "2.1-dev",
"dev-develop": "2.2-dev"
}
},
"autoload-dev": {
Expand Down
72 changes: 72 additions & 0 deletions src/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Authentication\Adapter;

abstract class AbstractAdapter implements ValidatableAdapterInterface
{

/**
* @var mixed
*/
protected $credential;

/**
* @var mixed
*/
protected $identity;

/**
* Returns the credential of the account being authenticated, or
* NULL if none is set.
*
* @return mixed
*/
public function getCredential()
{
return $this->credential;
}

/**
* Sets the credential for binding
*
* @param mixed $credential
* @return AbstractAdapter
*/
public function setCredential($credential)
{
$this->credential = $credential;

return $this;
}

/**
* Returns the identity of the account being authenticated, or
* NULL if none is set.
*
* @return mixed
*/
public function getIdentity()
{
return $this->identity;
}

/**
* Sets the identity for binding
*
* @param mixed $identity
* @return AbstractAdapter
*/
public function setIdentity($identity)
{
$this->identity = $identity;

return $this;
}
}
6 changes: 0 additions & 6 deletions src/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Authentication
*/

namespace Zend\Authentication\Adapter;

/**
* @category Zend
* @package Zend_Authentication
* @subpackage Adapter
*/
interface AdapterInterface
{
/**
Expand Down
91 changes: 24 additions & 67 deletions src/Adapter/DbTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Authentication
*/

namespace Zend\Authentication\Adapter;
Expand All @@ -14,15 +13,11 @@
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;

/**
* @category Zend
* @package Zend_Authentication
* @subpackage Adapter
*/
class DbTable implements AdapterInterface
class DbTable extends AbstractAdapter
{

/**
Expand All @@ -33,7 +28,7 @@ class DbTable implements AdapterInterface
protected $zendDb = null;

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

Expand All @@ -58,20 +53,6 @@ class DbTable implements AdapterInterface
*/
protected $credentialColumn = null;

/**
* $identity - Identity value
*
* @var string
*/
protected $identity = null;

/**
* $credential - Credential values
*
* @var string
*/
protected $credential = null;

/**
* $credentialTreatment - Treatment applied to the credential, such as MD5() or PASSWORD()
*
Expand Down Expand Up @@ -193,31 +174,6 @@ public function setCredentialTreatment($treatment)
return $this;
}

/**
* setIdentity() - set the value to be used as the identity
*
* @param string $value
* @return DbTable Provides a fluent interface
*/
public function setIdentity($value)
{
$this->identity = $value;
return $this;
}

/**
* setCredential() - set the credential value to be used, optionally can specify a treatment
* to be used, should be supplied in parametrized form, such as 'MD5(?)' or 'PASSWORD(?)'
*
* @param string $credential
* @return DbTable Provides a fluent interface
*/
public function setCredential($credential)
{
$this->credential = $credential;
return $this;
}

/**
* setAmbiguityIdentity() - sets a flag for usage of identical identities
* with unique credentials. It accepts integers (0, 1) or boolean (true,
Expand Down Expand Up @@ -250,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 @@ -374,7 +330,7 @@ protected function _authenticateSetup()
* _authenticateCreateSelect() - This method creates a Zend\Db\Sql\Select object that
* is completely configured to be queried against the database.
*
* @return DbSelect
* @return Sql\Select
*/
protected function _authenticateCreateSelect()
{
Expand All @@ -383,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 @@ -404,18 +358,21 @@ protected function _authenticateCreateSelect()
* _authenticateQuerySelect() - This method accepts a Zend\Db\Sql\Select object and
* performs a query against the database with that object.
*
* @param DbSelect $dbSelect
* @param Sql\Select $dbSelect
* @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
Loading

0 comments on commit 6e0bb7b

Please sign in to comment.