From ce0b9a6bc9b6ebc713b3d60bfae1d6040978f79b Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Sat, 9 Mar 2024 18:57:05 +0300 Subject: [PATCH] _JEXEC & copyright --- .../src/Table/AccessTokenTable.php | 23 +++-- .../administrator/src/Table/AuthCodeTable.php | 23 +++-- .../administrator/src/Table/ClientTable.php | 34 +++++--- .../src/Table/RefreshTokenTable.php | 22 +++-- .../src/Table/RevokedTableInterface.php | 11 ++- .../src/Table/RevokedTableTrait.php | 86 ++++++++++++------- 6 files changed, 133 insertions(+), 66 deletions(-) diff --git a/com_oauthserver/administrator/src/Table/AccessTokenTable.php b/com_oauthserver/administrator/src/Table/AccessTokenTable.php index 2c019cb..8f89422 100644 --- a/com_oauthserver/administrator/src/Table/AccessTokenTable.php +++ b/com_oauthserver/administrator/src/Table/AccessTokenTable.php @@ -1,18 +1,27 @@ + * @license MIT; see LICENSE.txt + **/ namespace Webmasterskaya\Component\OauthServer\Administrator\Table; use Joomla\CMS\Table\Table; use Joomla\Database\DatabaseDriver; +\defined('_JEXEC') or die; + /** - * @property int $id - * @property string $identifier + * @property int $id + * @property string $identifier * @property \DateTimeImmutable|\DateTime|string $expiry - * @property ?int $user_id - * @property string|array|null $scopes - * @property int $client_id - * @property int $revoked + * @property ?int $user_id + * @property string|array|null $scopes + * @property int $client_id + * @property int $revoked * * @since version */ @@ -40,4 +49,4 @@ class AccessTokenTable extends Table implements RevokedTableInterface { parent::__construct('#__webmasterskaya_oauthserver_access_tokens', 'id', $db); } -} \ No newline at end of file +} diff --git a/com_oauthserver/administrator/src/Table/AuthCodeTable.php b/com_oauthserver/administrator/src/Table/AuthCodeTable.php index 833b3a5..efddbde 100644 --- a/com_oauthserver/administrator/src/Table/AuthCodeTable.php +++ b/com_oauthserver/administrator/src/Table/AuthCodeTable.php @@ -1,18 +1,27 @@ + * @license MIT; see LICENSE.txt + **/ namespace Webmasterskaya\Component\OauthServer\Administrator\Table; use Joomla\CMS\Table\Table; use Joomla\Database\DatabaseDriver; +\defined('_JEXEC') or die; + /** - * @property int $id - * @property string $identifier + * @property int $id + * @property string $identifier * @property \DateTimeImmutable|\DateTime|string $expiry - * @property int|null $user_id - * @property string|array|null $scopes - * @property int $revoked - * @property int $client_id + * @property int|null $user_id + * @property string|array|null $scopes + * @property int $revoked + * @property int $client_id * * @since version */ @@ -40,4 +49,4 @@ class AuthCodeTable extends Table implements RevokedTableInterface { parent::__construct('#__webmasterskaya_oauthserver_authorization_codes', 'id', $db); } -} \ No newline at end of file +} diff --git a/com_oauthserver/administrator/src/Table/ClientTable.php b/com_oauthserver/administrator/src/Table/ClientTable.php index e39d097..6fe44a0 100644 --- a/com_oauthserver/administrator/src/Table/ClientTable.php +++ b/com_oauthserver/administrator/src/Table/ClientTable.php @@ -1,22 +1,30 @@ + * @license MIT; see LICENSE.txt + **/ namespace Webmasterskaya\Component\OauthServer\Administrator\Table; use Joomla\CMS\Table\Table; use Joomla\Database\DatabaseDriver; -use League\OAuth2\Server\Entities\ClientEntityInterface; + +\defined('_JEXEC') or die; /** - * @property int $id; - * @property string $identifier; - * @property string $name; - * @property ?string $secret; - * @property string|array|null $redirect_uris; - * @property string|array|null $grants; - * @property string|array|null $scopes; - * @property int $active; - * @property int $public; - * @property int $allow_plain_text_pkce; + * @property int $id ; + * @property string $identifier ; + * @property string $name ; + * @property ?string $secret ; + * @property string|array|null $redirect_uris ; + * @property string|array|null $grants ; + * @property string|array|null $scopes ; + * @property int $active ; + * @property int $public ; + * @property int $allow_plain_text_pkce; * * @since version */ @@ -41,7 +49,7 @@ class ClientTable extends Table /** * Constructor. * - * @param DatabaseDriver $db Database connector object + * @param DatabaseDriver $db Database connector object * * @since 1.0.0 */ @@ -49,4 +57,4 @@ class ClientTable extends Table { parent::__construct('#__webmasterskaya_oauthserver_clients', 'id', $db); } -} \ No newline at end of file +} diff --git a/com_oauthserver/administrator/src/Table/RefreshTokenTable.php b/com_oauthserver/administrator/src/Table/RefreshTokenTable.php index 13bfda8..3c7ac1d 100644 --- a/com_oauthserver/administrator/src/Table/RefreshTokenTable.php +++ b/com_oauthserver/administrator/src/Table/RefreshTokenTable.php @@ -1,19 +1,25 @@ + * @license MIT; see LICENSE.txt + **/ namespace Webmasterskaya\Component\OauthServer\Administrator\Table; -use DateTimeImmutable; use Joomla\CMS\Table\Table; use Joomla\Database\DatabaseDriver; -use League\OAuth2\Server\Entities\AccessTokenEntityInterface; -use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; + +\defined('_JEXEC') or die; /** - * @property int $id - * @property string $identifier + * @property int $id + * @property string $identifier * @property \DateTimeImmutable|\DateTime|string $expiry - * @property int $revoked - * @property int|null $access_token_id + * @property int $revoked + * @property int|null $access_token_id * * @since version */ @@ -33,4 +39,4 @@ class RefreshTokenTable extends Table implements RevokedTableInterface { parent::__construct('#__webmasterskaya_oauthserver_refresh_tokens', 'id', $db); } -} \ No newline at end of file +} diff --git a/com_oauthserver/administrator/src/Table/RevokedTableInterface.php b/com_oauthserver/administrator/src/Table/RevokedTableInterface.php index 92625ad..bdff04f 100644 --- a/com_oauthserver/administrator/src/Table/RevokedTableInterface.php +++ b/com_oauthserver/administrator/src/Table/RevokedTableInterface.php @@ -1,8 +1,17 @@ + * @license MIT; see LICENSE.txt + **/ namespace Webmasterskaya\Component\OauthServer\Administrator\Table; +\defined('_JEXEC') or die; + interface RevokedTableInterface { public function revoke($pks = null): bool; -} \ No newline at end of file +} diff --git a/com_oauthserver/administrator/src/Table/RevokedTableTrait.php b/com_oauthserver/administrator/src/Table/RevokedTableTrait.php index 04a28cd..49bd4bd 100644 --- a/com_oauthserver/administrator/src/Table/RevokedTableTrait.php +++ b/com_oauthserver/administrator/src/Table/RevokedTableTrait.php @@ -1,50 +1,52 @@ + * @license MIT; see LICENSE.txt + **/ namespace Webmasterskaya\Component\OauthServer\Administrator\Table; use Joomla\CMS\Event\AbstractEvent; use Joomla\CMS\Language\Text; +use Joomla\Database\DatabaseDriver; + +\defined('_JEXEC') or die; trait RevokedTableTrait { /** * @var string - * @since version + * @since version * @noinspection PhpMissingFieldTypeInspection */ protected $_tbl = ''; /** * @var string - * @since version + * @since version * @noinspection PhpMissingFieldTypeInspection */ protected $_tbl_key = ''; /** * @var array - * @since version + * @since version * @noinspection PhpMissingFieldTypeInspection */ protected $_tbl_keys = []; /** - * @var \Joomla\Database\DatabaseDriver - * @since version + * @var DatabaseDriver + * @since version * @noinspection PhpMissingFieldTypeInspection */ protected $_db; - abstract public function getDispatcher(); - - abstract public function setError($error); - - abstract public function getColumnAlias($column); - abstract public function getDbo(); - abstract public function appendPrimaryKeys($query, $pk = null); - public function revoke($pks = null): bool { // Pre-processing by observers @@ -52,31 +54,40 @@ trait RevokedTableTrait 'onTableBeforeRevoke', [ 'subject' => $this, - 'pks' => $pks, + 'pks' => $pks, ] ); $this->getDispatcher()->dispatch('onTableBeforeRevoke', $event); - if (!\is_null($pks)) { - if (!\is_array($pks)) { + if (!\is_null($pks)) + { + if (!\is_array($pks)) + { $pks = [$pks]; } - foreach ($pks as $key => $pk) { - if (!\is_array($pk)) { + foreach ($pks as $key => $pk) + { + if (!\is_array($pk)) + { $pks[$key] = [$this->_tbl_key => $pk]; } } } // If there are no primary keys set check to see if the instance key is set. - if (empty($pks)) { + if (empty($pks)) + { $pk = []; - foreach ($this->_tbl_keys as $key) { - if ($this->$key) { + foreach ($this->_tbl_keys as $key) + { + if ($this->$key) + { $pk[$key] = $this->$key; - } else { + } + else + { // We don't have a full primary key - return false $this->setError(Text::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); @@ -89,7 +100,8 @@ trait RevokedTableTrait $revokedField = $this->getColumnAlias('revoked'); - foreach ($pks as $pk) { + foreach ($pks as $pk) + { $query = $this->_db->getQuery(true) ->update($this->_db->quoteName($this->_tbl)) ->set($this->_db->quoteName($revokedField) . ' = 0'); @@ -99,9 +111,12 @@ trait RevokedTableTrait $this->_db->setQuery($query); - try { + try + { $this->_db->execute(); - } catch (\RuntimeException $e) { + } + catch (\RuntimeException $e) + { $this->setError($e->getMessage()); 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. $ours = true; - foreach ($this->_tbl_keys as $key) { - if ($this->$key != $pk[$key]) { + foreach ($this->_tbl_keys as $key) + { + if ($this->$key != $pk[$key]) + { $ours = false; } } - if ($ours) { + if ($ours) + { $this->$revokedField = 0; } } @@ -128,11 +146,19 @@ trait RevokedTableTrait 'onTableAfterRevoke', [ 'subject' => $this, - 'pks' => $pks + 'pks' => $pks ] ); $this->getDispatcher()->dispatch('onTableAfterRevoke', $event); return true; } -} \ No newline at end of file + + abstract public function getDispatcher(); + + abstract public function setError($error); + + abstract public function getColumnAlias($column); + + abstract public function appendPrimaryKeys($query, $pk = null); +}