Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converts the authentication plugins to service providers #39624

Merged
merged 8 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugins/authentication/cookie/cookie.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_AUTHENTICATION_COOKIE_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Authentication\Cookie</namespace>
<files>
<filename plugin="cookie">cookie.php</filename>
<folder plugin="cookie">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_authentication_cookie.ini</language>
Expand Down
51 changes: 51 additions & 0 deletions plugins/authentication/cookie/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Authentication.cookie
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Authentication\Cookie\Extension\Cookie;

return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);

$plugin = new Cookie(
$dispatcher,
(array) PluginHelper::getPlugin('authentication', 'cookie')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));

return $plugin;
}
);
}
};

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion plugins/authentication/joomla/joomla.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_AUTHENTICATION_JOOMLA_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Authentication\Joomla</namespace>
<files>
<filename plugin="joomla">joomla.php</filename>
<folder plugin="joomla">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_authentication_joomla.ini</language>
Expand Down
51 changes: 51 additions & 0 deletions plugins/authentication/joomla/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Authentication.joomla
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Authentication\Joomla\Extension\Joomla;

return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);

$plugin = new Joomla(
$dispatcher,
(array) PluginHelper::getPlugin('authentication', 'joomla')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));

return $plugin;
}
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt

* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

namespace Joomla\Plugin\Authentication\Joomla\Extension;

use Joomla\CMS\Authentication\Authentication;
use Joomla\CMS\Helper\AuthenticationHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\User\User;
use Joomla\CMS\User\UserHelper;
use Joomla\Database\DatabaseAwareTrait;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -27,23 +25,9 @@
*
* @since 1.5
*/
class PlgAuthenticationJoomla extends CMSPlugin
final class Joomla extends CMSPlugin
{
/**
* Application object
*
* @var \Joomla\CMS\Application\CMSApplication
* @since 4.0.0
*/
protected $app;

/**
* Database object
*
* @var \Joomla\Database\DatabaseDriver
* @since 4.0.0
*/
protected $db;
use DatabaseAwareTrait;

/**
* This method should handle any authentication and report back to the subject
Expand All @@ -63,12 +47,12 @@ public function onUserAuthenticate($credentials, $options, &$response)
// Joomla does not like blank passwords
if (empty($credentials['password'])) {
$response->status = Authentication::STATUS_FAILURE;
$response->error_message = Text::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
$response->error_message = $this->getApplication()->getLanguage()->_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');

return;
}

$db = $this->db;
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName(['id', 'password']))
->from($db->quoteName('#__users'))
Expand All @@ -87,7 +71,7 @@ public function onUserAuthenticate($credentials, $options, &$response)
$response->email = $user->email;
$response->fullname = $user->name;

if ($this->app->isClient('administrator')) {
if ($this->getApplication()->isClient('administrator')) {
$response->language = $user->getParam('admin_language');
} else {
$response->language = $user->getParam('language');
Expand All @@ -98,7 +82,7 @@ public function onUserAuthenticate($credentials, $options, &$response)
} else {
// Invalid password
$response->status = Authentication::STATUS_FAILURE;
$response->error_message = Text::_('JGLOBAL_AUTH_INVALID_PASS');
$response->error_message = $this->getApplication()->getLanguage()->_('JGLOBAL_AUTH_INVALID_PASS');
}
} else {
// Let's hash the entered password even if we don't have a matching user for some extra response time
Expand All @@ -107,7 +91,7 @@ public function onUserAuthenticate($credentials, $options, &$response)

// Invalid user
$response->status = Authentication::STATUS_FAILURE;
$response->error_message = Text::_('JGLOBAL_AUTH_NO_USER');
$response->error_message = $this->getApplication()->getLanguage()->_('JGLOBAL_AUTH_NO_USER');
}
}
}
4 changes: 3 additions & 1 deletion plugins/authentication/ldap/ldap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_LDAP_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Authentication\Ldap</namespace>
<files>
<filename plugin="ldap">ldap.php</filename>
<folder plugin="ldap">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_authentication_ldap.ini</language>
Expand Down
51 changes: 51 additions & 0 deletions plugins/authentication/ldap/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Authentication.ldap
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Authentication\Ldap\Extension\Ldap;

return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);

$plugin = new Ldap(
$dispatcher,
(array) PluginHelper::getPlugin('authentication', 'ldap')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));

return $plugin;
}
);
}
};
Loading