- md5
- fe47e0d3cef5a0ea6c8f4b200a22db28
- sha1
- 480f76f3b2d19d3dbd98b15d8abd32aa45248a89
- sha256
- 35e3f594ca89af3f5e79b0129d75e55c548a3c7e2fb8db9fcee9352c49cebe78
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
<?php
/**
* @package Joomla.Plugin
* @subpackage System.Webauthn
*
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\System\Webauthn\PluginTraits;
use Exception;
use Joomla\CMS\Event\Plugin\System\Webauthn\AjaxSaveLabel;
use Joomla\CMS\User\User;
/**
* Ajax handler for akaction=savelabel
*
* Stores a new label for a security key
*
* @since 4.0.0
*/
trait AjaxHandlerSaveLabel
{
/**
* Handle the callback to rename an authenticator
*
* @param AjaxSaveLabel $event The event we are handling
*
* @return void
*
* @since 4.0.0
*/
public function onAjaxWebauthnSavelabel(AjaxSaveLabel $event): void
{
// Initialize objects
$input = $this->getApplication()->input;
$repository = $this->authenticationHelper->getCredentialsRepository();
// Retrieve data from the request
$credentialId = $input->getBase64('credential_id', '');
$newLabel = $input->getString('new_label', '');
// Is this a valid credential?
if (empty($credentialId)) {
$event->addResult(false);
return;
}
$credentialId = base64_decode($credentialId);
if (empty($credentialId) || !$repository->has($credentialId)) {
$event->addResult(false);
return;
}
// Make sure I am editing my own key
try {
$credentialHandle = $repository->getUserHandleFor($credentialId);
$user = $this->getApplication()->getIdentity() ?? new User();
$myHandle = $repository->getHandleFromUserId($user->id);
} catch (Exception $e) {
$event->addResult(false);
return;
}
if ($credentialHandle !== $myHandle) {
$event->addResult(false);
return;
}
// Make sure the new label is not empty
if (empty($newLabel)) {
$event->addResult(false);
return;
}
// Save the new label
try {
$repository->setLabel($credentialId, $newLabel);
} catch (Exception $e) {
$event->addResult(false);
return;
}
$event->addResult(true);
}
}
The same content is in 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.