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#4815 from qapa/zendfra…
Browse files Browse the repository at this point in the history
…mework/zendframework#4563

Make HTTP auth adapter's challengeClient() method public
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/Adapter/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ public function authenticate()

$headers = $this->request->getHeaders();
if (!$headers->has($getHeader)) {
return $this->_challengeClient();
return $this->challengeClient();
}
$authHeader = $headers->get($getHeader)->getFieldValue();
if (!$authHeader) {
return $this->_challengeClient();
return $this->challengeClient();
}

list($clientScheme) = explode(' ', $authHeader);
Expand All @@ -360,7 +360,7 @@ public function authenticate()
// client sent a scheme that is not the one required
if (!in_array($clientScheme, $this->acceptSchemes)) {
// challenge again the client
return $this->_challengeClient();
return $this->challengeClient();
}

switch ($clientScheme) {
Expand All @@ -377,6 +377,22 @@ public function authenticate()
return $result;
}

/**
* @deprecated
* @see Http::challengeClient()
* @return Authentication\Result Always returns a non-identity Auth result
*/
protected function _challengeClient()
{
trigger_error(
'This method is deprecated and will be removed in the future'
. ', please use the public challengeClient() instead',
E_USER_DEPRECATED
);

return $this->challengeClient();
}

/**
* Challenge Client
*
Expand All @@ -385,7 +401,7 @@ public function authenticate()
*
* @return Authentication\Result Always returns a non-identity Auth result
*/
protected function _challengeClient()
public function challengeClient()
{
if ($this->imaProxy) {
$statusCode = 407;
Expand Down Expand Up @@ -474,12 +490,12 @@ protected function _basicAuth($header)
// implementation does. If invalid credentials are detected,
// re-challenge the client.
if (!ctype_print($auth)) {
return $this->_challengeClient();
return $this->challengeClient();
}
// Fix for ZF-1515: Now re-challenges on empty username or password
$creds = array_filter(explode(':', $auth));
if (count($creds) != 2) {
return $this->_challengeClient();
return $this->challengeClient();
}

$result = $this->basicResolver->resolve($creds[0], $this->realm, $creds[1]);
Expand All @@ -498,7 +514,7 @@ protected function _basicAuth($header)
return new Authentication\Result(Authentication\Result::SUCCESS, $result);
}

return $this->_challengeClient();
return $this->challengeClient();
}

/**
Expand Down Expand Up @@ -530,17 +546,17 @@ protected function _digestAuth($header)
// See ZF-1052. This code was a bit too unforgiving of invalid
// usernames. Now, if the username is bad, we re-challenge the client.
if ('::invalid::' == $data['username']) {
return $this->_challengeClient();
return $this->challengeClient();
}

// Verify that the client sent back the same nonce
if ($this->_calcNonce() != $data['nonce']) {
return $this->_challengeClient();
return $this->challengeClient();
}
// The opaque value is also required to match, but of course IE doesn't
// play ball.
if (!$this->ieNoOpaque && $this->_calcOpaque() != $data['opaque']) {
return $this->_challengeClient();
return $this->challengeClient();
}

// Look up the user's password hash. If not found, deny access.
Expand All @@ -549,7 +565,7 @@ protected function _digestAuth($header)
// to be recreatable with the current settings of this object.
$ha1 = $this->digestResolver->resolve($data['username'], $data['realm']);
if ($ha1 === false) {
return $this->_challengeClient();
return $this->challengeClient();
}

// If MD5-sess is used, a1 value is made of the user's password
Expand Down Expand Up @@ -588,7 +604,7 @@ protected function _digestAuth($header)
return new Authentication\Result(Authentication\Result::SUCCESS, $identity);
}

return $this->_challengeClient();
return $this->challengeClient();
}

/**
Expand Down
52 changes: 52 additions & 0 deletions test/Adapter/HttpTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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
* @package Zend_Authentication
*/

namespace ZendTest\Authentication\Adapter;

use Zend\Authentication\Adapter;

class HttpTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Wrapper
*/
protected $_wrapper;

public function setUp()
{
$config = array(
'accept_schemes' => 'basic',
'realm' => 'testing',
);

$this->_wrapper = new Wrapper($config);
}

public function tearDown()
{
unset($this->_wrapper);
}

/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testProtectedMethodChallengeClientTriggersErrorDeprecated()
{
$this->_wrapper->_challengeClient();
}
}

class Wrapper extends Adapter\Http
{
public function __call($method, $args)
{
return call_user_func_array(array($this, $method), $args);
}
}

0 comments on commit 9e7b400

Please sign in to comment.