diff --git a/app/Models/OAuth2/AccessToken.php b/app/Models/OAuth2/AccessToken.php index 9f5445a5..34c96d46 100644 --- a/app/Models/OAuth2/AccessToken.php +++ b/app/Models/OAuth2/AccessToken.php @@ -20,7 +20,6 @@ /** * @ORM\Entity(repositoryClass="App\Repositories\DoctrineAccessTokenRepository") * @ORM\Table(name="oauth2_access_token") - * @ORM\Cache("NONSTRICT_READ_WRITE") * Class AccessToken * @package Models\OAuth2 */ diff --git a/app/Models/OAuth2/Client.php b/app/Models/OAuth2/Client.php index 7eb221cc..580760ee 100644 --- a/app/Models/OAuth2/Client.php +++ b/app/Models/OAuth2/Client.php @@ -38,7 +38,6 @@ /** * @ORM\Entity(repositoryClass="App\Repositories\DoctrineOAuth2ClientRepository") * @ORM\Table(name="oauth2_client") - * @ORM\Cache("NONSTRICT_READ_WRITE") * Class Client * @package Models\OAuth2 */ diff --git a/app/Models/OAuth2/RefreshToken.php b/app/Models/OAuth2/RefreshToken.php index 6c267c57..02deb714 100644 --- a/app/Models/OAuth2/RefreshToken.php +++ b/app/Models/OAuth2/RefreshToken.php @@ -21,7 +21,6 @@ /** * @ORM\Entity(repositoryClass="App\Repositories\DoctrineRefreshTokenRepository") * @ORM\Table(name="oauth2_refresh_token") - * @ORM\Cache("NONSTRICT_READ_WRITE") * Class RefreshToken * Refresh Token Entity */ diff --git a/app/Repositories/DoctrineAccessTokenRepository.php b/app/Repositories/DoctrineAccessTokenRepository.php index 14c59a0f..ceb713c8 100644 --- a/app/Repositories/DoctrineAccessTokenRepository.php +++ b/app/Repositories/DoctrineAccessTokenRepository.php @@ -14,7 +14,6 @@ use Doctrine\ORM\QueryBuilder; use Models\OAuth2\AccessToken; -use Models\OAuth2\RefreshToken; use OAuth2\Repositories\IAccessTokenRepository; /** * Class DoctrineAccessTokenRepository @@ -42,24 +41,6 @@ function getByValue(string $hashed_value):?AccessToken return $this->findOneBy(['value' => $hashed_value]); } - /** - * @param string $hashed_value - * @return AccessToken|null - */ - function getByValueCacheable(string $hashed_value):?AccessToken - { - return $this->getEntityManager() - ->createQueryBuilder() - ->select("e") - ->from($this->getBaseEntity(), "e") - ->where("e.value = (:value)") - ->setParameter("value", trim($hashed_value)) - ->setMaxResults(1) - ->getQuery() - ->setCacheable(true) - ->getOneOrNullResult(); - } - /** * @param string $hashed_value * @return AccessToken|null diff --git a/app/Repositories/DoctrineOAuth2ClientRepository.php b/app/Repositories/DoctrineOAuth2ClientRepository.php index fbee1a1e..5e6f97cb 100644 --- a/app/Repositories/DoctrineOAuth2ClientRepository.php +++ b/app/Repositories/DoctrineOAuth2ClientRepository.php @@ -98,25 +98,6 @@ public function getClientById(string $client_id):?Client ->getOneOrNullResult(); } - /** - * @param string $client_id - * @return Client|null - * @throws \Doctrine\ORM\NonUniqueResultException - */ - public function getClientByIdCacheable(string $client_id):?Client - { - return $this->getEntityManager() - ->createQueryBuilder() - ->select("c") - ->from($this->getBaseEntity(), "c") - ->where("c.client_id = (:client_id)") - ->setParameter("client_id", trim($client_id)) - ->setMaxResults(1) - ->getQuery() - ->setCacheable(true) - ->getOneOrNullResult(); - } - /** * @param int $id * @return Client|null diff --git a/app/Repositories/DoctrineRefreshTokenRepository.php b/app/Repositories/DoctrineRefreshTokenRepository.php index 90a85c37..29f6a209 100644 --- a/app/Repositories/DoctrineRefreshTokenRepository.php +++ b/app/Repositories/DoctrineRefreshTokenRepository.php @@ -62,22 +62,4 @@ function getByValue(string $hashed_value):?RefreshToken { return $this->findOneBy(['value' => $hashed_value]); } - - /** - * @param string $hashed_value - * @return RefreshToken|null - */ - function getByValueCacheable(string $hashed_value):?RefreshToken - { - return $this->getEntityManager() - ->createQueryBuilder() - ->select("e") - ->from($this->getBaseEntity(), "e") - ->where("e.value = (:value)") - ->setParameter("value", trim($hashed_value)) - ->setMaxResults(1) - ->getQuery() - ->setCacheable(true) - ->getOneOrNullResult(); - } } \ No newline at end of file diff --git a/app/Services/OAuth2/TokenService.php b/app/Services/OAuth2/TokenService.php index 53c66ad6..4fac6d85 100644 --- a/app/Services/OAuth2/TokenService.php +++ b/app/Services/OAuth2/TokenService.php @@ -770,7 +770,7 @@ public function getAccessToken($value, $is_hashed = false) if (!$this->cache_service->exists($hashed_value)) { $this->lock_manager_service->lock('lock.get.accesstoken.' . $hashed_value, function () use ($value, $hashed_value) { // check on DB... - $access_token_db = $this->access_token_repository->getByValueCacheable($hashed_value); + $access_token_db = $this->access_token_repository->getByValue($hashed_value); if (is_null($access_token_db)) { if ($this->isAccessTokenRevoked($hashed_value)) { throw new RevokedAccessTokenException(sprintf('Access token %s is revoked!', $value)); @@ -830,9 +830,8 @@ public function getAccessToken($value, $is_hashed = false) $access_token->setRefreshToken($refresh_token); } } catch (UnacquiredLockException $ex1) { - throw new InvalidAccessTokenException(sprintf("Access token %s. ", $value)); + throw new InvalidAccessTokenException(sprintf("access token %s ", $value)); } - return $access_token; }); } @@ -921,11 +920,11 @@ public function createRefreshToken(AccessToken &$access_token, $refresh_cache = } /** - * @param string $value - * @param false $is_hashed + * @param \oauth2\services\refresh $value + * @param bool $is_hashed * @return RefreshToken * @throws InvalidGrantTypeException - * @throws ReplayAttackRefreshTokenException + * @throws ReplayAttackException * @throws RevokedRefreshTokenException */ public function getRefreshToken($value, $is_hashed = false) @@ -933,7 +932,7 @@ public function getRefreshToken($value, $is_hashed = false) //hash the given value, bc tokens values are stored hashed on DB $hashed_value = !$is_hashed ? Hash::compute('sha256', $value) : $value; - $refresh_token_db = $this->refresh_token_repository->getByValueCacheable($hashed_value); + $refresh_token_db = $this->refresh_token_repository->getByValue($hashed_value); if (is_null($refresh_token_db)) { if ($this->isRefreshTokenRevoked($hashed_value)) diff --git a/app/libs/OAuth2/GrantTypes/AbstractGrantType.php b/app/libs/OAuth2/GrantTypes/AbstractGrantType.php index 2adfb13b..a43077cc 100644 --- a/app/libs/OAuth2/GrantTypes/AbstractGrantType.php +++ b/app/libs/OAuth2/GrantTypes/AbstractGrantType.php @@ -93,8 +93,8 @@ public function completeFlow(OAuth2Request $request) // get client credentials from request.. $this->client_auth_context = $this->client_service->getCurrentClientAuthInfo(); - // retrieve client from storage ... - $this->current_client = $this->client_repository->getClientByIdCacheable($this->client_auth_context->getId()); + // retrieve client from storage.. + $this->current_client = $this->client_repository->getClientById($this->client_auth_context->getId()); if (is_null($this->current_client)) throw new InvalidClientException diff --git a/app/libs/OAuth2/GrantTypes/ValidateBearerTokenGrantType.php b/app/libs/OAuth2/GrantTypes/ValidateBearerTokenGrantType.php index e78b2114..f66c7371 100644 --- a/app/libs/OAuth2/GrantTypes/ValidateBearerTokenGrantType.php +++ b/app/libs/OAuth2/GrantTypes/ValidateBearerTokenGrantType.php @@ -185,7 +185,7 @@ public function completeFlow(OAuth2Request $request) $strategy->validate($access_token, $this->current_client); - $issued_client = $this->client_repository->getClientByIdCacheable($access_token->getClientId()); + $issued_client = $this->client_repository->getClientById($access_token->getClientId()); if (is_null($issued_client)) { @@ -193,7 +193,7 @@ public function completeFlow(OAuth2Request $request) ( sprintf ( - 'Access token %s does not belongs to client id %s.', + 'access token %s does not belongs to client id %s', $token_value, $access_token->getClientId() ) diff --git a/app/libs/OAuth2/Repositories/IAccessTokenRepository.php b/app/libs/OAuth2/Repositories/IAccessTokenRepository.php index df2d6715..b90612f2 100644 --- a/app/libs/OAuth2/Repositories/IAccessTokenRepository.php +++ b/app/libs/OAuth2/Repositories/IAccessTokenRepository.php @@ -56,12 +56,6 @@ function getAllValidByUserId(int $user_id,PagingInfo $paging_info):PagingRespons */ function getByValue(string $hashed_value):?AccessToken; - /** - * @param string $hashed_value - * @return AccessToken|null - */ - function getByValueCacheable(string $hashed_value):?AccessToken; - /** * @param string $hashed_value * @return AccessToken diff --git a/app/libs/OAuth2/Repositories/IClientRepository.php b/app/libs/OAuth2/Repositories/IClientRepository.php index 82e231f0..ebffdf36 100644 --- a/app/libs/OAuth2/Repositories/IClientRepository.php +++ b/app/libs/OAuth2/Repositories/IClientRepository.php @@ -31,13 +31,6 @@ public function getByApplicationName(string $app_name):?Client; */ public function getClientById(string $client_id):?Client; - /** - * @param string $client_id - * @return Client|null - * @throws \Doctrine\ORM\NonUniqueResultException - */ - public function getClientByIdCacheable(string $client_id):?Client; - /** * @param int $id * @return Client|null diff --git a/run_tests.sh b/run_tests.sh deleted file mode 100755 index 116b814c..00000000 --- a/run_tests.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/bash -./vendor/bin/phpunit \ No newline at end of file