Skip to content

Commit

Permalink
Fix Joomla >= 4.3.0 authentication properly
Browse files Browse the repository at this point in the history
  • Loading branch information
campbell-m committed Oct 16, 2023
1 parent 8b8f737 commit 80f4640
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
12 changes: 0 additions & 12 deletions web/auth/cms/joomla.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,3 @@ define('JPATH_BASE', $joomla_path);

require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
// Something changed at Joomla 4.3.0 - it's not clear what - but adding these
// lines seems to work. Not the cleanest solution.
// See https://groups.google.com/g/joomla-dev-general/c/55J2s9hhMxA/m/IpBrs3HZAgAJ?utm_medium=email&utm_source=footer&pli=1
// TODO: something better
if (version_compare(JVERSION, '4.3.0', '>='))
{
require_once JPATH_BASE . '/plugins/authentication/joomla/src/Extension/Joomla.php';
require_once JPATH_BASE . '/plugins/authentication/cookie/src/Extension/Cookie.php';
require_once JPATH_BASE . '/plugins/authentication/ldap/src/Extension/Ldap.php';
require_once JPATH_BASE . '/plugins/authentication/ldap/src/Factory/LdapFactoryInterface.php';
require_once JPATH_BASE . '/plugins/authentication/ldap/src/Factory/LdapFactory.php';
}
17 changes: 1 addition & 16 deletions web/lib/MRBS/Auth/AuthJoomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,7 @@ public function validateUser(
{
$mainframe = JFactory::getApplication('site');

try
{
return $mainframe->login(array('username' => $user, 'password' => $pass));
}
// We shouldn't have to do this, but from Joomla 4.3.0 logging in with an invalid
// username/password combination throws an error, so we catch it and return FALSE.
// [The problem with catching all throwables is that we mask other possible errors.
// However, there's no guarantee that the current error on an invalid user won't
// change in future versions of Joomla.]
// See https://groups.google.com/g/joomla-dev-general/c/55J2s9hhMxA/m/IpBrs3HZAgAJ?utm_medium=email&utm_source=footer&pli=1
// See also auth/cms/joomla.inc.
// TODO: something better
catch (\Throwable $e)
{
return false;
}
return $mainframe->login(array('username' => $user, 'password' => $pass));
}


Expand Down
15 changes: 13 additions & 2 deletions web/lib/MRBS/Session/SessionJoomla.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace MRBS\Session;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Language;
use MRBS\JFactory;
use MRBS\User;
use function MRBS\auth;
Expand Down Expand Up @@ -36,7 +38,7 @@ public function __construct()
// See https://groups.google.com/g/joomla-dev-general/c/55J2s9hhMxA

// Boot the DI container
$container = \Joomla\CMS\Factory::getContainer();
$container = Factory::getContainer();

// Alias the session service keys to the web session service as that is the primary session backend for this application.
// In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects
Expand All @@ -51,9 +53,18 @@ public function __construct()

// Instantiate the application.
$this->app = $container->get(\Joomla\CMS\Application\SiteApplication::class);
// Build the namespace map and load the language (necessary from Joomla 4.3.0 onwards - see
// https://groups.google.com/g/joomla-dev-general/c/55J2s9hhMxA/m/IpBrs3HZAgAJ?utm_medium=email&utm_source=footer&pli=1
// and https://joomla.stackexchange.com/questions/32145/joomla-4-error-when-i-use-getarticleroute/32146#32146)
if (version_compare(JVERSION, '4.3.0', '>='))
{
$this->app->createExtensionNamespaceMap();
$lang = Language::getInstance('en'); // doesn't matter which language as we never use it
$this->app->loadLanguage($lang);
}

// Set the application as global app
\Joomla\CMS\Factory::$application = $this->app;
Factory::$application = $this->app;
}

$this->session = JFactory::getSession();
Expand Down

0 comments on commit 80f4640

Please sign in to comment.