diff --git a/application/Espo/Core/Authentication/AuthToken/AuthTokenData.php b/application/Espo/Core/Authentication/AuthToken/Data.php similarity index 99% rename from application/Espo/Core/Authentication/AuthToken/AuthTokenData.php rename to application/Espo/Core/Authentication/AuthToken/Data.php index 59470bde3b..0af14f62bb 100644 --- a/application/Espo/Core/Authentication/AuthToken/AuthTokenData.php +++ b/application/Espo/Core/Authentication/AuthToken/Data.php @@ -34,7 +34,7 @@ use RuntimeException; /** * An auth token data. Used for auth token creation. */ -class AuthTokenData +class Data { private $userId; diff --git a/application/Espo/Core/Authentication/AuthToken/EspoAuthTokenManager.php b/application/Espo/Core/Authentication/AuthToken/EspoManager.php similarity index 87% rename from application/Espo/Core/Authentication/AuthToken/EspoAuthTokenManager.php rename to application/Espo/Core/Authentication/AuthToken/EspoManager.php index e0145a1017..5a3c6bc330 100644 --- a/application/Espo/Core/Authentication/AuthToken/EspoAuthTokenManager.php +++ b/application/Espo/Core/Authentication/AuthToken/EspoManager.php @@ -29,33 +29,32 @@ namespace Espo\Core\Authentication\AuthToken; -use Espo\{ - ORM\EntityManager, -}; +use Espo\ORM\EntityManager; +use Espo\Entities\AuthToken as AuthTokenEntity; use RuntimeException; use const MCRYPT_DEV_URANDOM; -class EspoAuthTokenManager implements AuthTokenManager +class EspoManager implements Manager { - protected $entityManager; + private $entityManager; - protected $repository; + private $repository; - const TOKEN_RANDOM_LENGTH = 16; + private const TOKEN_RANDOM_LENGTH = 16; public function __construct(EntityManager $entityManager) { $this->entityManager = $entityManager; - $this->repository = $entityManager->getRepository('AuthToken'); + $this->repository = $entityManager->getRepository(AuthTokenEntity::ENTITY_TYPE); } public function get(string $token): ?AuthToken { $authToken = $this->entityManager - ->getRepository('AuthToken') + ->getRDBRepository(AuthTokenEntity::ENTITY_TYPE) ->select([ 'id', 'isActive', @@ -76,20 +75,20 @@ class EspoAuthTokenManager implements AuthTokenManager return $authToken; } - public function create(AuthTokenData $authTokenData): AuthToken + public function create(Data $data): AuthToken { $authToken = $this->repository->getNew(); $authToken->set([ - 'userId' => $authTokenData->getUserId(), - 'portalId' => $authTokenData->getPortalId(), - 'hash' => $authTokenData->getHash(), - 'ipAddress' => $authTokenData->getIpAddress(), + 'userId' => $data->getUserId(), + 'portalId' => $data->getPortalId(), + 'hash' => $data->getHash(), + 'ipAddress' => $data->getIpAddress(), 'lastAccess' => date('Y-m-d H:i:s'), 'token' => $this->generateToken(), ]); - if ($authTokenData->toCreateSecret()) { + if ($data->toCreateSecret()) { $authToken->set('secret', $this->generateToken()); } diff --git a/application/Espo/Core/Authentication/AuthToken/AuthTokenManager.php b/application/Espo/Core/Authentication/AuthToken/Manager.php similarity index 95% rename from application/Espo/Core/Authentication/AuthToken/AuthTokenManager.php rename to application/Espo/Core/Authentication/AuthToken/Manager.php index d5f14a9322..530e0993bc 100644 --- a/application/Espo/Core/Authentication/AuthToken/AuthTokenManager.php +++ b/application/Espo/Core/Authentication/AuthToken/Manager.php @@ -32,7 +32,7 @@ namespace Espo\Core\Authentication\AuthToken; /** * Fetches and stores auth tokens. */ -interface AuthTokenManager +interface Manager { /** * Get an auth token. If does not exist then returns NULL. @@ -42,7 +42,7 @@ interface AuthTokenManager /** * Create an auth token and store it. */ - public function create(AuthTokenData $authTokenData): AuthToken; + public function create(Data $data): AuthToken; /** * Make an auth token inactive (invalid). diff --git a/application/Espo/Core/Authentication/Authentication.php b/application/Espo/Core/Authentication/Authentication.php index 23a10ff602..d17a25a77f 100644 --- a/application/Espo/Core/Authentication/Authentication.php +++ b/application/Espo/Core/Authentication/Authentication.php @@ -47,8 +47,8 @@ use Espo\Core\Authentication\{ Result\FailReason, LoginFactory, TwoFactor\LoginFactory as TwoFactorLoginFactory, - AuthToken\AuthTokenManager, - AuthToken\AuthTokenData, + AuthToken\Manager as AuthTokenManager, + AuthToken\Data as AuthTokenData, AuthToken\AuthToken, Hook\Manager as HookManager, Login\Data as LoginData, diff --git a/application/Espo/Core/Binding/DefaultBinding.php b/application/Espo/Core/Binding/DefaultBinding.php index c3d4f299f4..44c636f7ac 100644 --- a/application/Espo/Core/Binding/DefaultBinding.php +++ b/application/Espo/Core/Binding/DefaultBinding.php @@ -94,7 +94,7 @@ class DefaultBinding implements BindingProcessor ); $binder->bindService( - 'Espo\\Core\\Authentication\\AuthToken\\AuthTokenManager', + 'Espo\\Core\\Authentication\\AuthToken\\Manager', 'authTokenManager' ); diff --git a/application/Espo/Core/Console/Commands/AuthTokenCheck.php b/application/Espo/Core/Console/Commands/AuthTokenCheck.php index 0b8019e639..219c45485b 100644 --- a/application/Espo/Core/Console/Commands/AuthTokenCheck.php +++ b/application/Espo/Core/Console/Commands/AuthTokenCheck.php @@ -31,7 +31,7 @@ namespace Espo\Core\Console\Commands; use Espo\Core\{ ORM\EntityManager, - Authentication\AuthToken\AuthTokenManager, + Authentication\AuthToken\Manager as AuthTokenManager, Console\Command, Console\Command\Params, Console\IO, @@ -39,9 +39,9 @@ use Espo\Core\{ class AuthTokenCheck implements Command { - protected $entityManager; + private $entityManager; - protected $authTokenManager; + private $authTokenManager; public function __construct(EntityManager $entityManager, AuthTokenManager $authTokenManager) { diff --git a/application/Espo/Core/EntryPoint/Starter.php b/application/Espo/Core/EntryPoint/Starter.php index ae2f5eeae1..595673653d 100644 --- a/application/Espo/Core/EntryPoint/Starter.php +++ b/application/Espo/Core/EntryPoint/Starter.php @@ -35,7 +35,7 @@ use Espo\Core\EntryPoint\EntryPointManager; use Espo\Core\ApplicationUser; use Espo\Core\Portal\Application as PortalApplication; use Espo\Core\Authentication\AuthenticationFactory; -use Espo\Core\Authentication\AuthToken\AuthTokenManager; +use Espo\Core\Authentication\AuthToken\Manager as AuthTokenManager; use Espo\Core\Api\ErrorOutput; use Espo\Core\Api\RequestWrapper; use Espo\Core\Api\ResponseWrapper; diff --git a/application/Espo/Resources/metadata/app/containerServices.json b/application/Espo/Resources/metadata/app/containerServices.json index 17937107dc..37d6557799 100644 --- a/application/Espo/Resources/metadata/app/containerServices.json +++ b/application/Espo/Resources/metadata/app/containerServices.json @@ -1,6 +1,6 @@ { "authTokenManager": { - "className": "Espo\\Core\\Authentication\\AuthToken\\EspoAuthTokenManager" + "className": "Espo\\Core\\Authentication\\AuthToken\\EspoManager" }, "schema": { "className": "Espo\\Core\\Utils\\Database\\Schema\\Schema" diff --git a/tests/integration/Espo/Core/Authentication/AuthToken/AuthTokenManagerTest.php b/tests/integration/Espo/Core/Authentication/AuthToken/AuthTokenManagerTest.php index f0f5e43a37..d58bbaf732 100644 --- a/tests/integration/Espo/Core/Authentication/AuthToken/AuthTokenManagerTest.php +++ b/tests/integration/Espo/Core/Authentication/AuthToken/AuthTokenManagerTest.php @@ -29,7 +29,7 @@ namespace tests\integration\Espo\Core\Authentication\AuthToken; -use Espo\Core\Authentication\AuthToken\AuthTokenData; +use Espo\Core\Authentication\AuthToken\Data; class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase { @@ -37,7 +37,7 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase { $authTokenManager = $this->getContainer()->get('authTokenManager'); - $authTokenData = AuthTokenData::create([ + $authTokenData = Data::create([ 'hash' => 'test-hash', 'ipAddress' => 'ip-address', 'userId' => 'user-id', @@ -63,7 +63,7 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase { $authTokenManager = $this->getContainer()->get('authTokenManager'); - $authTokenData = AuthTokenData::create([ + $authTokenData = Data::create([ 'hash' => 'test-hash', 'ipAddress' => 'ip-address', 'userId' => 'user-id', @@ -86,7 +86,7 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase { $authTokenManager = $this->getContainer()->get('authTokenManager'); - $authTokenData = AuthTokenData::create([ + $authTokenData = Data::create([ 'hash' => 'test-hash', 'userId' => 'user-id', ]); @@ -104,7 +104,7 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase { $authTokenManager = $this->getContainer()->get('authTokenManager'); - $authTokenData = AuthTokenData::create([ + $authTokenData = Data::create([ 'hash' => 'test-hash', 'userId' => 'user-id', ]); diff --git a/tests/unit/Espo/Core/Authentication/AuthToken/AuthTokenDataTest.php b/tests/unit/Espo/Core/Authentication/AuthToken/AuthTokenDataTest.php index 13b7331074..afdf33ce42 100644 --- a/tests/unit/Espo/Core/Authentication/AuthToken/AuthTokenDataTest.php +++ b/tests/unit/Espo/Core/Authentication/AuthToken/AuthTokenDataTest.php @@ -29,13 +29,13 @@ namespace tests\unit\Espo\Core\Authentication\AuthToken; -use Espo\Core\Authentication\AuthToken\AuthTokenData; +use Espo\Core\Authentication\AuthToken\Data; class AuthTokenDataTest extends \PHPUnit\Framework\TestCase { public function testCreate() { - $authTokenData = AuthTokenData::create([ + $authTokenData = Data::create([ 'hash' => 'hash', 'ipAddress' => 'ip-address', 'userId' => 'user-id',