diff --git a/Controller/AuthorizeController.php b/Controller/AuthorizeController.php index a56a149c..70405a41 100644 --- a/Controller/AuthorizeController.php +++ b/Controller/AuthorizeController.php @@ -22,12 +22,12 @@ use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Form\Form; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; +use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Router; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -101,7 +101,7 @@ class AuthorizeController implements ContainerAwareInterface private $templateEngineType; /** - * @var EventDispatcher + * @var TraceableEventDispatcher */ private $eventDispatcher; @@ -111,17 +111,17 @@ class AuthorizeController implements ContainerAwareInterface * * @todo This controller could be refactored to do not rely on so many dependencies * - * @param RequestStack $requestStack - * @param SessionInterface $session - * @param Form $authorizeForm - * @param AuthorizeFormHandler $authorizeFormHandler - * @param OAuth2 $oAuth2Server - * @param EngineInterface $templating - * @param TokenStorageInterface $tokenStorage - * @param Router $router - * @param ClientManagerInterface $clientManager - * @param EventDispatcher $eventDispatcher - * @param string $templateEngineType + * @param RequestStack $requestStack + * @param SessionInterface $session + * @param Form $authorizeForm + * @param AuthorizeFormHandler $authorizeFormHandler + * @param OAuth2 $oAuth2Server + * @param EngineInterface $templating + * @param TokenStorageInterface $tokenStorage + * @param Router $router + * @param ClientManagerInterface $clientManager + * @param TraceableEventDispatcher $eventDispatcher + * @param string $templateEngineType */ public function __construct( RequestStack $requestStack, @@ -133,7 +133,7 @@ public function __construct( TokenStorageInterface $tokenStorage, Router $router, ClientManagerInterface $clientManager, - EventDispatcher $eventDispatcher, + TraceableEventDispatcher $eventDispatcher, $templateEngineType = 'twig' ) { $this->requestStack = $requestStack; diff --git a/CouchDocument/AccessToken.php b/CouchDocument/AccessToken.php new file mode 100644 index 00000000..1bf31e60 --- /dev/null +++ b/CouchDocument/AccessToken.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\CouchDocument; + +use FOS\OAuthServerBundle\Model\AccessToken as BaseAccessToken; + +class AccessToken extends BaseAccessToken +{ +} diff --git a/CouchDocument/AccessTokenManager.php b/CouchDocument/AccessTokenManager.php new file mode 100644 index 00000000..d1a2a3a4 --- /dev/null +++ b/CouchDocument/AccessTokenManager.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\CouchDocument; + +use FOS\OAuthServerBundle\Model\AccessTokenManagerInterface; + +class AccessTokenManager extends TokenManager implements AccessTokenManagerInterface +{ +} diff --git a/CouchDocument/AuthCode.php b/CouchDocument/AuthCode.php new file mode 100644 index 00000000..f218973a --- /dev/null +++ b/CouchDocument/AuthCode.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\CouchDocument; + +use FOS\OAuthServerBundle\Model\AuthCode as BaseAuthCode; + +/** + * @author Richard Fullmer + */ +class AuthCode extends BaseAuthCode +{ +} diff --git a/CouchDocument/AuthCodeManager.php b/CouchDocument/AuthCodeManager.php new file mode 100644 index 00000000..90d70793 --- /dev/null +++ b/CouchDocument/AuthCodeManager.php @@ -0,0 +1,86 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\CouchDocument; + +use Doctrine\ODM\CouchDB\DocumentManager; +use Doctrine\ODM\CouchDB\DocumentRepository; +use FOS\OAuthServerBundle\Model\AuthCodeInterface; +use FOS\OAuthServerBundle\Model\AuthCodeManager as BaseAuthCodeManager; + +class AuthCodeManager extends BaseAuthCodeManager +{ + /** + * @var DocumentManager + */ + protected $dm; + + /** + * @var DocumentRepository + */ + protected $repository; + + /** + * @var string + */ + protected $class; + + public function __construct(DocumentManager $dm, $class) + { + $this->dm = $dm; + $this->repository = $dm->getRepository($class); + $this->class = $class; + } + + /** + * {@inheritdoc} + */ + public function getClass() + { + return $this->class; + } + + /** + * {@inheritdoc} + */ + public function findAuthCodeBy(array $criteria) + { + return $this->repository->findOneBy($criteria); + } + + /** + * {@inheritdoc} + */ + public function updateAuthCode(AuthCodeInterface $authCode) + { + $this->dm->persist($authCode); + $this->dm->flush(); + } + + /** + * {@inheritdoc} + */ + public function deleteAuthCode(AuthCodeInterface $authCode) + { + $this->dm->remove($authCode); + $this->dm->flush(); + } + + /** + * {@inheritdoc} + */ + public function deleteExpired() + { + return null; + } +} diff --git a/CouchDocument/Client.php b/CouchDocument/Client.php new file mode 100644 index 00000000..ffa3ef26 --- /dev/null +++ b/CouchDocument/Client.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\CouchDocument; + +use FOS\OAuthServerBundle\Model\Client as BaseClient; + +class Client extends BaseClient +{ +} diff --git a/CouchDocument/ClientManager.php b/CouchDocument/ClientManager.php new file mode 100644 index 00000000..ec436c65 --- /dev/null +++ b/CouchDocument/ClientManager.php @@ -0,0 +1,86 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\CouchDocument; + +use Doctrine\ODM\CouchDB\DocumentManager; +use Doctrine\ODM\CouchDB\DocumentRepository; +use FOS\OAuthServerBundle\Model\ClientInterface; +use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager; + +class ClientManager extends BaseClientManager +{ + /** + * @var DocumentManager + */ + protected $dm; + + /** + * @var DocumentRepository + */ + protected $repository; + + /** + * @var string + */ + protected $class; + + public function __construct(DocumentManager $dm, $class) + { + $this->dm = $dm; + $this->repository = $dm->getRepository($class); + $this->class = $class; + } + + /** + * {@inheritdoc} + */ + public function getClass() + { + return $this->class; + } + + /** + * {@inheritdoc} + */ + public function findClientBy(array $criteria) + { + $client = $this->repository->findOneBy(['randomId' => $criteria['randomId']]); + + if ($client !== null) { + if ($client->getId() === $criteria['id']) { + return $client; + } + } + + return null; + } + + /** + * {@inheritdoc} + */ + public function updateClient(ClientInterface $client) + { + $this->dm->persist($client); + $this->dm->flush(); + } + + /** + * {@inheritdoc} + */ + public function deleteClient(ClientInterface $client) + { + $this->dm->remove($client); + $this->dm->flush(); + } +} diff --git a/CouchDocument/RefreshToken.php b/CouchDocument/RefreshToken.php new file mode 100644 index 00000000..7ccc6b59 --- /dev/null +++ b/CouchDocument/RefreshToken.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\CouchDocument; + +use FOS\OAuthServerBundle\Model\RefreshToken as BaseRefreshToken; + +class RefreshToken extends BaseRefreshToken +{ +} diff --git a/CouchDocument/RefreshTokenManager.php b/CouchDocument/RefreshTokenManager.php new file mode 100644 index 00000000..57277236 --- /dev/null +++ b/CouchDocument/RefreshTokenManager.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\CouchDocument; + +use FOS\OAuthServerBundle\Model\RefreshTokenManagerInterface; + +class RefreshTokenManager extends TokenManager implements RefreshTokenManagerInterface +{ +} diff --git a/CouchDocument/TokenManager.php b/CouchDocument/TokenManager.php new file mode 100644 index 00000000..fcf852f1 --- /dev/null +++ b/CouchDocument/TokenManager.php @@ -0,0 +1,86 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\CouchDocument; + +use Doctrine\ODM\CouchDB\DocumentManager; +use Doctrine\ODM\CouchDB\DocumentRepository; +use FOS\OAuthServerBundle\Model\TokenInterface; +use FOS\OAuthServerBundle\Model\TokenManager as BaseTokenManager; + +class TokenManager extends BaseTokenManager +{ + /** + * @var DocumentManager + */ + protected $dm; + + /** + * @var DocumentRepository + */ + protected $repository; + + /** + * @var string + */ + protected $class; + + public function __construct(DocumentManager $dm, $class) + { + $this->dm = $dm; + $this->repository = $dm->getRepository($class); + $this->class = $class; + } + + /** + * {@inheritdoc} + */ + public function getClass() + { + return $this->class; + } + + /** + * {@inheritdoc} + */ + public function findTokenBy(array $criteria) + { + return $this->repository->findOneBy($criteria); + } + + /** + * {@inheritdoc} + */ + public function updateToken(TokenInterface $token) + { + $this->dm->persist($token); + $this->dm->flush(); + } + + /** + * {@inheritdoc} + */ + public function deleteToken(TokenInterface $token) + { + $this->dm->remove($token); + $this->dm->flush(); + } + + /** + * {@inheritdoc} + */ + public function deleteExpired() + { + return null; + } +} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b715653f..d9ea2a10 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -34,7 +34,7 @@ public function getConfigTreeBuilder() /** @var ArrayNodeDefinition $rootNode */ $rootNode = $treeBuilder->root('fos_oauth_server'); - $supportedDrivers = ['orm', 'mongodb', 'propel']; + $supportedDrivers = ['orm', 'mongodb', 'propel', 'couchdb']; $rootNode ->children() diff --git a/DependencyInjection/FOSOAuthServerExtension.php b/DependencyInjection/FOSOAuthServerExtension.php index f9aeab42..78a950fd 100644 --- a/DependencyInjection/FOSOAuthServerExtension.php +++ b/DependencyInjection/FOSOAuthServerExtension.php @@ -78,6 +78,20 @@ public function load(array $configs, ContainerBuilder $container) } } + // Handle the MongoDB document manager name in a specific way as it does not have a registry to make it easy + // TODO: change it when bumping the requirement to Symfony 2.1 + if ('couchdb' === $config['db_driver']) { + if (null === $config['model_manager_name']) { + $container->setAlias('fos_oauth_server.document_manager', new Alias('doctrine_couchdb.odm.default_document_manager', false)); + } else { + $container->setAlias('fos_oauth_server.document_manager', new Alias( + sprintf('doctrine.odm.%s_couchdb.document_manager', + $config['model_manager_name']), + false + )); + } + } + // Entity manager factory definition // TODO: Go back to xml configuration when bumping the requirement to Symfony >=2.6 if ('orm' === $config['db_driver']) { diff --git a/Resources/config/couchdb.xml b/Resources/config/couchdb.xml index 15df13c5..18324160 100644 --- a/Resources/config/couchdb.xml +++ b/Resources/config/couchdb.xml @@ -25,7 +25,8 @@ %fos_oauth_server.model.refresh_token.class% - + + %fos_oauth_server.model_manager_name% diff --git a/Resources/config/doctrine/AccessToken.couchdb.xml b/Resources/config/doctrine/AccessToken.couchdb.xml index ae715578..f85b4b6d 100644 --- a/Resources/config/doctrine/AccessToken.couchdb.xml +++ b/Resources/config/doctrine/AccessToken.couchdb.xml @@ -1,9 +1,9 @@ - - - + + + diff --git a/Resources/config/doctrine/AuthCode.couchdb.xml b/Resources/config/doctrine/AuthCode.couchdb.xml index f9316f08..75e4939e 100644 --- a/Resources/config/doctrine/AuthCode.couchdb.xml +++ b/Resources/config/doctrine/AuthCode.couchdb.xml @@ -1,10 +1,10 @@ - + - + diff --git a/Resources/config/doctrine/Client.couchdb.xml b/Resources/config/doctrine/Client.couchdb.xml index b3968446..665ea722 100644 --- a/Resources/config/doctrine/Client.couchdb.xml +++ b/Resources/config/doctrine/Client.couchdb.xml @@ -1,8 +1,8 @@ - - + + diff --git a/Resources/config/doctrine/RefreshToken.couchdb.xml b/Resources/config/doctrine/RefreshToken.couchdb.xml index e59ba38b..78c38690 100644 --- a/Resources/config/doctrine/RefreshToken.couchdb.xml +++ b/Resources/config/doctrine/RefreshToken.couchdb.xml @@ -1,9 +1,9 @@ - - - + + + diff --git a/composer.json b/composer.json index 0e301726..26ecfa67 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,7 @@ "php": "^7.1", "friendsofsymfony/oauth2-php": "~1.1", "symfony/framework-bundle": "~3.0|^4.0", - "symfony/security-bundle": "~3.0|^4.0", - "symfony/dependency-injection": "^2.8|~3.0|^4.0" + "symfony/security-bundle": "~3.0|^4.0" }, "require-dev": { "symfony/class-loader": "~3.0|^4.0", @@ -34,6 +33,9 @@ "doctrine/mongodb-odm": "~1.0", "doctrine/doctrine-bundle": "~1.0", "doctrine/orm": "~2.2", + "doctrine/couchdb": "1.0.x-dev", + "doctrine/couchdb-odm": "dev-master", + "doctrine/couchdb-odm-bundle": "@dev", "phpunit/phpunit": "~4.8|~5.0" }, "suggest": {