mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
Merge pull request #1515 from Hardolaf/feature/auth-refactor
[feature/auth-refactor] Use a base class for all authentication providers
This commit is contained in:
commit
86b910692a
9 changed files with 155 additions and 84 deletions
|
@ -678,8 +678,12 @@ class acp_board
|
||||||
$auth_plugins = array();
|
$auth_plugins = array();
|
||||||
$auth_providers = $phpbb_container->get('auth.provider_collection');
|
$auth_providers = $phpbb_container->get('auth.provider_collection');
|
||||||
|
|
||||||
foreach($auth_providers as $key => $value)
|
foreach ($auth_providers as $key => $value)
|
||||||
{
|
{
|
||||||
|
if (!($value instanceof phpbb_auth_provider_interface))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$auth_plugins[] = str_replace('auth.provider.', '', $key);
|
$auth_plugins[] = str_replace('auth.provider.', '', $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ if (!defined('IN_PHPBB'))
|
||||||
*
|
*
|
||||||
* @package auth
|
* @package auth
|
||||||
*/
|
*/
|
||||||
class phpbb_auth_provider_apache implements phpbb_auth_provider_interface
|
class phpbb_auth_provider_apache extends phpbb_auth_provider_base
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Apache Authentication Constructor
|
* Apache Authentication Constructor
|
||||||
|
@ -256,20 +256,4 @@ class phpbb_auth_provider_apache implements phpbb_auth_provider_interface
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function acp($new)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function logout($data, $new_session)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
64
phpBB/includes/auth/provider/base.php
Normal file
64
phpBB/includes/auth/provider/base.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package auth
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base authentication provider class that all other providers should implement
|
||||||
|
*
|
||||||
|
* @package auth
|
||||||
|
*/
|
||||||
|
abstract class phpbb_auth_provider_base implements phpbb_auth_provider_interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function autologin()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function acp($new)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function logout($data, $new_session)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validate_session($user)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ if (!defined('IN_PHPBB'))
|
||||||
*
|
*
|
||||||
* @package auth
|
* @package auth
|
||||||
*/
|
*/
|
||||||
class phpbb_auth_provider_db implements phpbb_auth_provider_interface
|
class phpbb_auth_provider_db extends phpbb_auth_provider_base
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,14 +45,6 @@ class phpbb_auth_provider_db implements phpbb_auth_provider_interface
|
||||||
$this->php_ext = $php_ext;
|
$this->php_ext = $php_ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -302,36 +294,4 @@ class phpbb_auth_provider_db implements phpbb_auth_provider_interface
|
||||||
'user_row' => $row,
|
'user_row' => $row,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function autologin()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function acp($new)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function logout($data, $new_session)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function validate_session($user)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ if (!defined('IN_PHPBB'))
|
||||||
*
|
*
|
||||||
* @package auth
|
* @package auth
|
||||||
*/
|
*/
|
||||||
class phpbb_auth_provider_ldap implements phpbb_auth_provider_interface
|
class phpbb_auth_provider_ldap extends phpbb_auth_provider_base
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* LDAP Authentication Constructor
|
* LDAP Authentication Constructor
|
||||||
|
@ -283,14 +283,6 @@ class phpbb_auth_provider_ldap implements phpbb_auth_provider_interface
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function autologin()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -367,20 +359,4 @@ class phpbb_auth_provider_ldap implements phpbb_auth_provider_interface
|
||||||
{
|
{
|
||||||
return str_replace(array('*', '\\', '(', ')'), array('\\*', '\\\\', '\\(', '\\)'), $string);
|
return str_replace(array('*', '\\', '(', ')'), array('\\*', '\\\\', '\\(', '\\)'), $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function logout($data, $new_session)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function validate_session($user)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,6 +404,12 @@ class phpbb_session
|
||||||
$method = basename(trim($config['auth_method']));
|
$method = basename(trim($config['auth_method']));
|
||||||
|
|
||||||
$provider = $phpbb_container->get('auth.provider.' . $method);
|
$provider = $phpbb_container->get('auth.provider.' . $method);
|
||||||
|
|
||||||
|
if (!($provider instanceof phpbb_auth_provider_interface))
|
||||||
|
{
|
||||||
|
throw new \RuntimeException($provider . ' must implement phpbb_auth_provider_interface');
|
||||||
|
}
|
||||||
|
|
||||||
$ret = $provider->validate_session($this->data);
|
$ret = $provider->validate_session($this->data);
|
||||||
if ($ret !== null && !$ret)
|
if ($ret !== null && !$ret)
|
||||||
{
|
{
|
||||||
|
|
13
tests/acp_board/auth_provider/invalid.php
Normal file
13
tests/acp_board/auth_provider/invalid.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_auth_provider_acp_board_invalid
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
16
tests/acp_board/auth_provider/valid.php
Normal file
16
tests/acp_board/auth_provider/valid.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_auth_provider_acp_board_valid extends phpbb_auth_provider_base
|
||||||
|
{
|
||||||
|
public function login($username, $password)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
48
tests/acp_board/select_auth_method_test.php
Normal file
48
tests/acp_board/select_auth_method_test.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_board.php';
|
||||||
|
require_once dirname(__FILE__) . '/auth_provider/invalid.php';
|
||||||
|
require_once dirname(__FILE__) . '/auth_provider/valid.php';
|
||||||
|
|
||||||
|
class phpbb_acp_board_select_auth_method_test extends phpbb_test_case
|
||||||
|
{
|
||||||
|
protected $acp_board;
|
||||||
|
|
||||||
|
public static function select_auth_method_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('acp_board_valid', '<option value="acp_board_valid" selected="selected">Acp_board_valid</option>'),
|
||||||
|
array('acp_board_invalid', '<option value="acp_board_valid">Acp_board_valid</option>'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
global $phpbb_container;
|
||||||
|
$phpbb_container = new phpbb_mock_container_builder();
|
||||||
|
|
||||||
|
$phpbb_container->set('auth.provider_collection', array(
|
||||||
|
'auth.provider.acp_board_valid' => new phpbb_auth_provider_acp_board_valid,
|
||||||
|
'auth.provider.acp_board_invalid' => new phpbb_auth_provider_acp_board_invalid,
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->acp_board = new acp_board();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider select_auth_method_data
|
||||||
|
*/
|
||||||
|
public function test_select_auth_method($selected, $expected)
|
||||||
|
{
|
||||||
|
$this->assertEquals($expected, $this->acp_board->select_auth_method($selected));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue