diff --git a/plugins/api-authentication/basic/basic.xml b/plugins/api-authentication/basic/basic.xml
index 4e3c90c7fb172..4bc18acc159aa 100644
--- a/plugins/api-authentication/basic/basic.xml
+++ b/plugins/api-authentication/basic/basic.xml
@@ -9,11 +9,13 @@
www.joomla.org
4.0.0
PLG_API-AUTHENTICATION_BASIC_XML_DESCRIPTION
+ Joomla\Plugin\ApiAuthentication\Basic
- basic.php
+ services
+ src
- language/en-GB/plg_authentication_api_basic.ini
- language/en-GB/plg_authentication_api_basic.sys.ini
+ language/en-GB/plg_api-authentication_basic.ini
+ language/en-GB/plg_api-authentication_basic.sys.ini
diff --git a/plugins/api-authentication/basic/services/provider.php b/plugins/api-authentication/basic/services/provider.php
new file mode 100644
index 0000000000000..77278ea99d0cc
--- /dev/null
+++ b/plugins/api-authentication/basic/services/provider.php
@@ -0,0 +1,49 @@
+
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+defined('_JEXEC') or die;
+
+use Joomla\CMS\Extension\PluginInterface;
+use Joomla\CMS\Plugin\PluginHelper;
+use Joomla\CMS\User\UserFactoryInterface;
+use Joomla\Database\DatabaseInterface;
+use Joomla\DI\Container;
+use Joomla\DI\ServiceProviderInterface;
+use Joomla\Event\DispatcherInterface;
+use Joomla\Plugin\ApiAuthentication\Basic\Extension\Basic;
+
+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)
+ {
+ $plugin = new Basic(
+ $container->get(DispatcherInterface::class),
+ (array) PluginHelper::getPlugin('api-authentication', 'basic'),
+ $container->get(UserFactoryInterface::class)
+ );
+ $plugin->setDatabase($container->get(DatabaseInterface::class));
+
+ return $plugin;
+ }
+ );
+ }
+};
diff --git a/plugins/api-authentication/basic/basic.php b/plugins/api-authentication/basic/src/Extension/Basic.php
similarity index 64%
rename from plugins/api-authentication/basic/basic.php
rename to plugins/api-authentication/basic/src/Extension/Basic.php
index 44cd2ad57292e..89998499ca7ee 100644
--- a/plugins/api-authentication/basic/basic.php
+++ b/plugins/api-authentication/basic/src/Extension/Basic.php
@@ -1,42 +1,64 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
+namespace Joomla\Plugin\ApiAuthentication\Basic\Extension;
+
defined('_JEXEC') or die;
+use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Authentication\Authentication;
-use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
-use Joomla\CMS\User\User;
+use Joomla\CMS\User\UserFactoryInterface;
use Joomla\CMS\User\UserHelper;
+use Joomla\Database\DatabaseAwareTrait;
+use Joomla\Event\DispatcherInterface;
/**
* Joomla Authentication plugin
*
* @since 4.0.0
*/
-class PlgApiAuthenticationBasic extends CMSPlugin
+final class Basic extends CMSPlugin
{
+ use DatabaseAwareTrait;
+
/**
* The application object
*
- * @var \Joomla\CMS\Application\CMSApplicationInterface
+ * @var CMSApplicationInterface
* @since 4.0.0
*/
protected $app;
/**
- * The application object
+ * The user factory
*
- * @var \Joomla\Database\DatabaseInterface
- * @since 4.0.0
+ * @var UserFactoryInterface
+ * @since __DEPLOY_VERSION__
+ */
+ private $userFactory;
+
+ /**
+ * Constructor.
+ *
+ * @param DispatcherInterface $dispatcher The dispatcher
+ * @param array $config An optional associative array of configuration settings
+ * @param UserFactoryInterface $userFactory The user factory
+ *
+ * @since __DEPLOY_VERSION__
*/
- protected $db;
+ public function __construct(DispatcherInterface $dispatcher, array $config, UserFactoryInterface $userFactory)
+ {
+ parent::__construct($dispatcher, $config);
+
+ $this->userFactory = $userFactory;
+ }
/**
* This method should handle any authentication and report back to the subject
@@ -59,12 +81,12 @@ public function onUserAuthenticate($credentials, $options, &$response)
if ($password === '')
{
$response->status = Authentication::STATUS_FAILURE;
- $response->error_message = Text::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
+ $response->error_message = $this->app->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'))
@@ -81,7 +103,7 @@ public function onUserAuthenticate($credentials, $options, &$response)
if ($match === true)
{
// Bring this in line with the rest of the system
- $user = User::getInstance($result->id);
+ $user = $this->userFactory->loadUserById($result->id);
$response->email = $user->email;
$response->fullname = $user->name;
$response->username = $username;
@@ -103,7 +125,7 @@ public function onUserAuthenticate($credentials, $options, &$response)
{
// Invalid password
$response->status = Authentication::STATUS_FAILURE;
- $response->error_message = Text::_('JGLOBAL_AUTH_INVALID_PASS');
+ $response->error_message = $this->app->getLanguage()->_('JGLOBAL_AUTH_INVALID_PASS');
}
}
else
@@ -114,7 +136,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->app->getLanguage()->_('JGLOBAL_AUTH_NO_USER');
}
}
}