_JEXEC & copyright

This commit is contained in:
Artem Vasilev 2024-03-09 18:57:05 +03:00
parent f821c9becb
commit ce0b9a6bc9
6 changed files with 133 additions and 66 deletions

View File

@ -1,18 +1,27 @@
<?php <?php
/**
* @package Joomla.Administrator
* @subpackage com_oauthserver
*
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
* @license MIT; see LICENSE.txt
**/
namespace Webmasterskaya\Component\OauthServer\Administrator\Table; namespace Webmasterskaya\Component\OauthServer\Administrator\Table;
use Joomla\CMS\Table\Table; use Joomla\CMS\Table\Table;
use Joomla\Database\DatabaseDriver; use Joomla\Database\DatabaseDriver;
\defined('_JEXEC') or die;
/** /**
* @property int $id * @property int $id
* @property string $identifier * @property string $identifier
* @property \DateTimeImmutable|\DateTime|string $expiry * @property \DateTimeImmutable|\DateTime|string $expiry
* @property ?int $user_id * @property ?int $user_id
* @property string|array|null $scopes * @property string|array|null $scopes
* @property int $client_id * @property int $client_id
* @property int $revoked * @property int $revoked
* *
* @since version * @since version
*/ */
@ -40,4 +49,4 @@ class AccessTokenTable extends Table implements RevokedTableInterface
{ {
parent::__construct('#__webmasterskaya_oauthserver_access_tokens', 'id', $db); parent::__construct('#__webmasterskaya_oauthserver_access_tokens', 'id', $db);
} }
} }

View File

@ -1,18 +1,27 @@
<?php <?php
/**
* @package Joomla.Administrator
* @subpackage com_oauthserver
*
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
* @license MIT; see LICENSE.txt
**/
namespace Webmasterskaya\Component\OauthServer\Administrator\Table; namespace Webmasterskaya\Component\OauthServer\Administrator\Table;
use Joomla\CMS\Table\Table; use Joomla\CMS\Table\Table;
use Joomla\Database\DatabaseDriver; use Joomla\Database\DatabaseDriver;
\defined('_JEXEC') or die;
/** /**
* @property int $id * @property int $id
* @property string $identifier * @property string $identifier
* @property \DateTimeImmutable|\DateTime|string $expiry * @property \DateTimeImmutable|\DateTime|string $expiry
* @property int|null $user_id * @property int|null $user_id
* @property string|array|null $scopes * @property string|array|null $scopes
* @property int $revoked * @property int $revoked
* @property int $client_id * @property int $client_id
* *
* @since version * @since version
*/ */
@ -40,4 +49,4 @@ class AuthCodeTable extends Table implements RevokedTableInterface
{ {
parent::__construct('#__webmasterskaya_oauthserver_authorization_codes', 'id', $db); parent::__construct('#__webmasterskaya_oauthserver_authorization_codes', 'id', $db);
} }
} }

View File

@ -1,22 +1,30 @@
<?php <?php
/**
* @package Joomla.Administrator
* @subpackage com_oauthserver
*
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
* @license MIT; see LICENSE.txt
**/
namespace Webmasterskaya\Component\OauthServer\Administrator\Table; namespace Webmasterskaya\Component\OauthServer\Administrator\Table;
use Joomla\CMS\Table\Table; use Joomla\CMS\Table\Table;
use Joomla\Database\DatabaseDriver; use Joomla\Database\DatabaseDriver;
use League\OAuth2\Server\Entities\ClientEntityInterface;
\defined('_JEXEC') or die;
/** /**
* @property int $id; * @property int $id ;
* @property string $identifier; * @property string $identifier ;
* @property string $name; * @property string $name ;
* @property ?string $secret; * @property ?string $secret ;
* @property string|array|null $redirect_uris; * @property string|array|null $redirect_uris ;
* @property string|array|null $grants; * @property string|array|null $grants ;
* @property string|array|null $scopes; * @property string|array|null $scopes ;
* @property int $active; * @property int $active ;
* @property int $public; * @property int $public ;
* @property int $allow_plain_text_pkce; * @property int $allow_plain_text_pkce;
* *
* @since version * @since version
*/ */
@ -41,7 +49,7 @@ class ClientTable extends Table
/** /**
* Constructor. * Constructor.
* *
* @param DatabaseDriver $db Database connector object * @param DatabaseDriver $db Database connector object
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -49,4 +57,4 @@ class ClientTable extends Table
{ {
parent::__construct('#__webmasterskaya_oauthserver_clients', 'id', $db); parent::__construct('#__webmasterskaya_oauthserver_clients', 'id', $db);
} }
} }

View File

@ -1,19 +1,25 @@
<?php <?php
/**
* @package Joomla.Administrator
* @subpackage com_oauthserver
*
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
* @license MIT; see LICENSE.txt
**/
namespace Webmasterskaya\Component\OauthServer\Administrator\Table; namespace Webmasterskaya\Component\OauthServer\Administrator\Table;
use DateTimeImmutable;
use Joomla\CMS\Table\Table; use Joomla\CMS\Table\Table;
use Joomla\Database\DatabaseDriver; use Joomla\Database\DatabaseDriver;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; \defined('_JEXEC') or die;
/** /**
* @property int $id * @property int $id
* @property string $identifier * @property string $identifier
* @property \DateTimeImmutable|\DateTime|string $expiry * @property \DateTimeImmutable|\DateTime|string $expiry
* @property int $revoked * @property int $revoked
* @property int|null $access_token_id * @property int|null $access_token_id
* *
* @since version * @since version
*/ */
@ -33,4 +39,4 @@ class RefreshTokenTable extends Table implements RevokedTableInterface
{ {
parent::__construct('#__webmasterskaya_oauthserver_refresh_tokens', 'id', $db); parent::__construct('#__webmasterskaya_oauthserver_refresh_tokens', 'id', $db);
} }
} }

View File

@ -1,8 +1,17 @@
<?php <?php
/**
* @package Joomla.Administrator
* @subpackage com_oauthserver
*
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
* @license MIT; see LICENSE.txt
**/
namespace Webmasterskaya\Component\OauthServer\Administrator\Table; namespace Webmasterskaya\Component\OauthServer\Administrator\Table;
\defined('_JEXEC') or die;
interface RevokedTableInterface interface RevokedTableInterface
{ {
public function revoke($pks = null): bool; public function revoke($pks = null): bool;
} }

View File

@ -1,50 +1,52 @@
<?php <?php
/**
* @package Joomla.Administrator
* @subpackage com_oauthserver
*
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
* @license MIT; see LICENSE.txt
**/
namespace Webmasterskaya\Component\OauthServer\Administrator\Table; namespace Webmasterskaya\Component\OauthServer\Administrator\Table;
use Joomla\CMS\Event\AbstractEvent; use Joomla\CMS\Event\AbstractEvent;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\Database\DatabaseDriver;
\defined('_JEXEC') or die;
trait RevokedTableTrait trait RevokedTableTrait
{ {
/** /**
* @var string * @var string
* @since version * @since version
* @noinspection PhpMissingFieldTypeInspection * @noinspection PhpMissingFieldTypeInspection
*/ */
protected $_tbl = ''; protected $_tbl = '';
/** /**
* @var string * @var string
* @since version * @since version
* @noinspection PhpMissingFieldTypeInspection * @noinspection PhpMissingFieldTypeInspection
*/ */
protected $_tbl_key = ''; protected $_tbl_key = '';
/** /**
* @var array * @var array
* @since version * @since version
* @noinspection PhpMissingFieldTypeInspection * @noinspection PhpMissingFieldTypeInspection
*/ */
protected $_tbl_keys = []; protected $_tbl_keys = [];
/** /**
* @var \Joomla\Database\DatabaseDriver * @var DatabaseDriver
* @since version * @since version
* @noinspection PhpMissingFieldTypeInspection * @noinspection PhpMissingFieldTypeInspection
*/ */
protected $_db; protected $_db;
abstract public function getDispatcher();
abstract public function setError($error);
abstract public function getColumnAlias($column);
abstract public function getDbo(); abstract public function getDbo();
abstract public function appendPrimaryKeys($query, $pk = null);
public function revoke($pks = null): bool public function revoke($pks = null): bool
{ {
// Pre-processing by observers // Pre-processing by observers
@ -52,31 +54,40 @@ trait RevokedTableTrait
'onTableBeforeRevoke', 'onTableBeforeRevoke',
[ [
'subject' => $this, 'subject' => $this,
'pks' => $pks, 'pks' => $pks,
] ]
); );
$this->getDispatcher()->dispatch('onTableBeforeRevoke', $event); $this->getDispatcher()->dispatch('onTableBeforeRevoke', $event);
if (!\is_null($pks)) { if (!\is_null($pks))
if (!\is_array($pks)) { {
if (!\is_array($pks))
{
$pks = [$pks]; $pks = [$pks];
} }
foreach ($pks as $key => $pk) { foreach ($pks as $key => $pk)
if (!\is_array($pk)) { {
if (!\is_array($pk))
{
$pks[$key] = [$this->_tbl_key => $pk]; $pks[$key] = [$this->_tbl_key => $pk];
} }
} }
} }
// If there are no primary keys set check to see if the instance key is set. // If there are no primary keys set check to see if the instance key is set.
if (empty($pks)) { if (empty($pks))
{
$pk = []; $pk = [];
foreach ($this->_tbl_keys as $key) { foreach ($this->_tbl_keys as $key)
if ($this->$key) { {
if ($this->$key)
{
$pk[$key] = $this->$key; $pk[$key] = $this->$key;
} else { }
else
{
// We don't have a full primary key - return false // We don't have a full primary key - return false
$this->setError(Text::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); $this->setError(Text::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
@ -89,7 +100,8 @@ trait RevokedTableTrait
$revokedField = $this->getColumnAlias('revoked'); $revokedField = $this->getColumnAlias('revoked');
foreach ($pks as $pk) { foreach ($pks as $pk)
{
$query = $this->_db->getQuery(true) $query = $this->_db->getQuery(true)
->update($this->_db->quoteName($this->_tbl)) ->update($this->_db->quoteName($this->_tbl))
->set($this->_db->quoteName($revokedField) . ' = 0'); ->set($this->_db->quoteName($revokedField) . ' = 0');
@ -99,9 +111,12 @@ trait RevokedTableTrait
$this->_db->setQuery($query); $this->_db->setQuery($query);
try { try
{
$this->_db->execute(); $this->_db->execute();
} catch (\RuntimeException $e) { }
catch (\RuntimeException $e)
{
$this->setError($e->getMessage()); $this->setError($e->getMessage());
return false; return false;
@ -110,13 +125,16 @@ trait RevokedTableTrait
// If the Table instance value is in the list of primary keys that were set, set the instance. // If the Table instance value is in the list of primary keys that were set, set the instance.
$ours = true; $ours = true;
foreach ($this->_tbl_keys as $key) { foreach ($this->_tbl_keys as $key)
if ($this->$key != $pk[$key]) { {
if ($this->$key != $pk[$key])
{
$ours = false; $ours = false;
} }
} }
if ($ours) { if ($ours)
{
$this->$revokedField = 0; $this->$revokedField = 0;
} }
} }
@ -128,11 +146,19 @@ trait RevokedTableTrait
'onTableAfterRevoke', 'onTableAfterRevoke',
[ [
'subject' => $this, 'subject' => $this,
'pks' => $pks 'pks' => $pks
] ]
); );
$this->getDispatcher()->dispatch('onTableAfterRevoke', $event); $this->getDispatcher()->dispatch('onTableAfterRevoke', $event);
return true; return true;
} }
}
abstract public function getDispatcher();
abstract public function setError($error);
abstract public function getColumnAlias($column);
abstract public function appendPrimaryKeys($query, $pk = null);
}