From efc81295aead24322e528e42b82aacff1c856891 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Fri, 16 Dec 2011 23:44:45 +0100 Subject: [PATCH] Started to work on FOSOAuthServerBundle --- .gitignore | 1 + Controller/ServerController.php | 18 ++++-- DependencyInjection/Configuration.php | 25 +++++--- ...ension.php => FOSOAuthServerExtension.php} | 32 ++++++---- .../{OAuth2Factory.php => OAuthFactory.php} | 29 +++++---- Document/OAuth2AccessToken.php | 4 +- Document/OAuth2AccessTokenManager.php | 6 +- Document/OAuth2AuthCode.php | 4 +- Document/OAuth2AuthCodeManager.php | 6 +- Document/OAuth2Client.php | 4 +- Document/OAuth2ClientManager.php | 6 +- Document/OAuth2TokenManager.php | 6 +- Entity/OAuth2AccessToken.php | 4 +- Entity/OAuth2AccessTokenManager.php | 6 +- Entity/OAuth2AuthCode.php | 4 +- Entity/OAuth2AuthCodeManager.php | 8 +-- Entity/OAuth2Client.php | 4 +- Entity/OAuth2ClientManager.php | 6 +- Entity/OAuth2TokenManager.php | 6 +- ...rverBundle.php => FOSOAuthServerBundle.php | 18 ++++-- Model/OAuth2AccessToken.php | 2 +- Model/OAuth2AccessTokenInterface.php | 14 +++- Model/OAuth2AccessTokenManagerInterface.php | 2 +- Model/OAuth2AuthCode.php | 2 +- Model/OAuth2AuthCodeInterface.php | 2 +- Model/OAuth2AuthCodeManager.php | 2 +- Model/OAuth2AuthCodeManagerInterface.php | 2 +- Model/OAuth2Client.php | 4 +- Model/OAuth2ClientInterface.php | 2 +- Model/OAuth2ClientManager.php | 2 +- Model/OAuth2ClientManagerInterface.php | 4 +- Model/OAuth2Token.php | 2 +- Model/OAuth2TokenInterface.php | 6 +- Model/OAuth2TokenManager.php | 2 +- Model/OAuth2TokenManagerInterface.php | 4 +- README.md | 45 +++++++------ Resources/config/odm.xml | 21 +++--- Resources/config/orm.xml | 27 ++++---- Resources/config/routing.yml | 6 +- Resources/config/security.yml | 2 +- Resources/config/security_factories.xml | 6 +- Resources/config/services.xml | 64 +++++++++---------- Resources/translations/messages.fr.xliff | 11 ---- .../{OAuth2Provider.php => OAuthProvider.php} | 22 +++++-- .../Token/{OAuth2Token.php => OAuthToken.php} | 17 +++-- ...uth2EntryPoint.php => OAuthEntryPoint.php} | 17 +++-- .../{OAuth2Listener.php => OAuthListener.php} | 27 +++++--- .../OAuthStorage.php | 47 ++++++++------ Tests/Entity/OAuth2TokenManagerTest.php | 8 +-- Tests/Model/OAuth2TokenTest.php | 4 +- ...ProviderTest.php => OAuthProviderTest.php} | 12 ++-- .../OAuthStorageTest.php} | 32 +++++----- Util/Random.php | 2 +- composer.json | 19 +++--- phpunit.xml.dist | 2 +- 55 files changed, 355 insertions(+), 285 deletions(-) rename DependencyInjection/{AlbOAuth2ServerExtension.php => FOSOAuthServerExtension.php} (61%) rename DependencyInjection/Security/Factory/{OAuth2Factory.php => OAuthFactory.php} (57%) rename AlbOAuth2ServerBundle.php => FOSOAuthServerBundle.php (51%) delete mode 100644 Resources/translations/messages.fr.xliff rename Security/Authentification/Provider/{OAuth2Provider.php => OAuthProvider.php} (78%) rename Security/Authentification/Token/{OAuth2Token.php => OAuthToken.php} (53%) rename Security/EntryPoint/{OAuth2EntryPoint.php => OAuthEntryPoint.php} (70%) rename Security/Firewall/{OAuth2Listener.php => OAuthListener.php} (83%) rename Service/OAuth2StorageService.php => Storage/OAuthStorage.php (76%) rename Tests/Security/Authentification/Provider/{OAuth2ProviderTest.php => OAuthProviderTest.php} (81%) rename Tests/{Service/OAuth2StorageServiceTest.php => Storage/OAuthStorageTest.php} (91%) diff --git a/.gitignore b/.gitignore index 66b6efb1..74d252d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ Tests/autoload.php vendor/bundles/Alb/OAuth2ServerBundle +vendor/ diff --git a/Controller/ServerController.php b/Controller/ServerController.php index 30b0b1cb..a477e5fb 100644 --- a/Controller/ServerController.php +++ b/Controller/ServerController.php @@ -1,14 +1,25 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\Controller; use OAuth2\OAuth2; -use Symfony\Component\HttpFoundation\Request; use OAuth2\OAuth2ServerException; +use Symfony\Component\HttpFoundation\Request; + class ServerController { protected $request; + protected $serverService; public function __construct(Request $request, OAuth2 $serverService) @@ -20,8 +31,7 @@ public function __construct(Request $request, OAuth2 $serverService) public function tokenAction() { try { - $response = $this->serverService->grantAccessToken($this->request); - return $response; + return $this->serverService->grantAccessToken($this->request); } catch(OAuth2ServerException $e) { return $e->getHttpResponse(); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f15fd755..be4c47b3 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -1,10 +1,19 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace FOS\OAuthServerBundle\DependencyInjection; + +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; -use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; /** * This is the class that validates and merges configuration from your app/config files @@ -19,17 +28,17 @@ class Configuration implements ConfigurationInterface public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('alb_o_auth2_server'); + $rootNode = $treeBuilder->root('fos_o_auth_server'); $rootNode ->children() ->scalarNode('db_driver')->cannotBeOverwritten()->isRequired()->cannotBeEmpty()->end() - ->scalarNode('storage_service')->defaultValue('alb.oauth2.server.server_service.storage.default')->cannotBeEmpty()->end() + ->scalarNode('storage_service')->defaultValue('fos.oauth_server.server_service.storage.default')->cannotBeEmpty()->end() ->scalarNode('user_provider_service')->end() - ->scalarNode('oauth2_client_class')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('oauth2_access_token_class')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('oauth2_auth_code_class')->isRequired()->cannotBeEmpty()->end() - ->arrayNode('oauth2_options') + ->scalarNode('oauth_client_class')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('oauth_access_token_class')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('oauth_auth_code_class')->isRequired()->cannotBeEmpty()->end() + ->arrayNode('oauth_options') ->useAttributeAsKey('key') ->treatNullLike(array()) ->prototype('scalar')->end() diff --git a/DependencyInjection/AlbOAuth2ServerExtension.php b/DependencyInjection/FOSOAuthServerExtension.php similarity index 61% rename from DependencyInjection/AlbOAuth2ServerExtension.php rename to DependencyInjection/FOSOAuthServerExtension.php index 1173caca..3c33e224 100644 --- a/DependencyInjection/AlbOAuth2ServerExtension.php +++ b/DependencyInjection/FOSOAuthServerExtension.php @@ -1,21 +1,30 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ -use Symfony\Component\DependencyInjection\ContainerBuilder; +namespace FOS\OAuthServerBundle\DependencyInjection; + +use Symfony\Component\Config\Definition\Processor; use Symfony\Component\Config\FileLocator; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; -use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** * This is the class that loads and manages your bundle configuration * * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} */ -class AlbOAuth2ServerExtension extends Extension +class FOSOAuthServerExtension extends Extension { /** * {@inheritDoc} @@ -36,20 +45,19 @@ public function load(array $configs, ContainerBuilder $container) if ($config['storage_service']) { $container - ->setAlias('alb.oauth2.server.server_service.storage', $config['storage_service']); + ->setAlias('fos.oauth_server.server_service.storage', $config['storage_service']); } if (isset($config['user_provider_service'])) { $container - ->getDefinition('alb.oauth2.server.server_service.storage.default') + ->getDefinition('fos.oauth_server.server_service.storage.default') ->replaceArgument(3, new Reference($config['user_provider_service'])) ; } - $container->setParameter('alb.oauth2.server.model.client.class', $config['oauth2_client_class']); - $container->setParameter('alb.oauth2.server.model.access.token.class', $config['oauth2_access_token_class']); - $container->setParameter('alb.oauth2.server.model.auth.code.class', $config['oauth2_auth_code_class']); - - $container->setParameter('alb.oauth2.server.server_service.options', $config['oauth2_options']); + $container->setParameter('fos.oauth_server.model.client.class', $config['oauth2_client_class']); + $container->setParameter('fos.oauth_server.model.access.token.class', $config['oauth2_access_token_class']); + $container->setParameter('fos.oauth_server.model.auth.code.class', $config['oauth2_auth_code_class']); + $container->setParameter('fos.oauth_server.server_service.options', $config['oauth2_options']); } } diff --git a/DependencyInjection/Security/Factory/OAuth2Factory.php b/DependencyInjection/Security/Factory/OAuthFactory.php similarity index 57% rename from DependencyInjection/Security/Factory/OAuth2Factory.php rename to DependencyInjection/Security/Factory/OAuthFactory.php index c300d423..2b9d5e65 100644 --- a/DependencyInjection/Security/Factory/OAuth2Factory.php +++ b/DependencyInjection/Security/Factory/OAuthFactory.php @@ -1,6 +1,15 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\DependencyInjection\Security\Factory; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; use Symfony\Component\Config\Definition\Builder\NodeDefinition; @@ -9,29 +18,27 @@ use Symfony\Component\DependencyInjection\Reference; /** - * OAuth2Factory class. + * OAuthFactory class. * - * @package AlbOAuth2ServerBundle - * @subpackage DependencyInjection * @author Arnaud Le Blanc */ -class OAuth2Factory implements SecurityFactoryInterface +class OAuthFactory implements SecurityFactoryInterface { /** * {@inheritdoc} */ public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint) { - $providerId = 'security.authentication.provider.alb_oauth2_server.'.$id; + $providerId = 'security.authentication.provider.fos_oauth_server.'.$id; $container - ->setDefinition($providerId, new DefinitionDecorator('alb.oauth2.server.security.authentication.provider')) + ->setDefinition($providerId, new DefinitionDecorator('fos.oauth_server.security.authentication.provider')) ->replaceArgument(0, new Reference($userProvider)) ; - $listenerId = 'security.authentication.listener.alb_oauth2_server.'.$id; - $listener = $container->setDefinition($listenerId, new DefinitionDecorator('alb.oauth2.server.security.authentication.listener')); + $listenerId = 'security.authentication.listener.fos_oauth_server.'.$id; + $listener = $container->setDefinition($listenerId, new DefinitionDecorator('fos.oauth_server.security.authentication.listener')); - return array($providerId, $listenerId, 'alb.oauth2.server.security.entry_point'); + return array($providerId, $listenerId, 'fos.oauth_server.security.entry_point'); } /** @@ -47,7 +54,7 @@ public function getPosition() */ public function getKey() { - return 'alb_oauth2'; + return 'fos_oauth'; } /** diff --git a/Document/OAuth2AccessToken.php b/Document/OAuth2AccessToken.php index ff968f35..a9b6be1a 100644 --- a/Document/OAuth2AccessToken.php +++ b/Document/OAuth2AccessToken.php @@ -1,8 +1,8 @@ diff --git a/Document/OAuth2AuthCodeManager.php b/Document/OAuth2AuthCodeManager.php index 82bf522c..7802644b 100644 --- a/Document/OAuth2AuthCodeManager.php +++ b/Document/OAuth2AuthCodeManager.php @@ -1,9 +1,9 @@ diff --git a/Entity/OAuth2AuthCodeManager.php b/Entity/OAuth2AuthCodeManager.php index 8f5c5569..cd24a372 100644 --- a/Entity/OAuth2AuthCodeManager.php +++ b/Entity/OAuth2AuthCodeManager.php @@ -1,10 +1,10 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle; + +use FOS\OAuthServerBundle\DependencyInjection\Security\Factory\OAuth2Factory; -use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Alb\OAuth2ServerBundle\DependencyInjection\Security\Factory\OAuth2Factory; +use Symfony\Component\HttpKernel\Bundle\Bundle; -class AlbOAuth2ServerBundle extends Bundle +class FOSOAuthServerBundle extends Bundle { public function build(ContainerBuilder $container) { diff --git a/Model/OAuth2AccessToken.php b/Model/OAuth2AccessToken.php index 7183e133..d8e75aca 100644 --- a/Model/OAuth2AccessToken.php +++ b/Model/OAuth2AccessToken.php @@ -1,6 +1,6 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\Model; use OAuth2\Model\IOAuth2AccessToken; -interface OAuth2AccessTokenInterface extends OAuth2TokenInterface, IOAuth2AccessToken +interface OAuthAccessTokenInterface extends OAuthTokenInterface, IOAuth2AccessToken { } - diff --git a/Model/OAuth2AccessTokenManagerInterface.php b/Model/OAuth2AccessTokenManagerInterface.php index baccb219..8f96a6aa 100644 --- a/Model/OAuth2AccessTokenManagerInterface.php +++ b/Model/OAuth2AccessTokenManagerInterface.php @@ -1,6 +1,6 @@ diff --git a/Model/OAuth2AuthCodeInterface.php b/Model/OAuth2AuthCodeInterface.php index 9936ab3b..8993998d 100644 --- a/Model/OAuth2AuthCodeInterface.php +++ b/Model/OAuth2AuthCodeInterface.php @@ -3,7 +3,7 @@ * */ -namespace Alb\OAuth2ServerBundle\Model; +namespace FOS\OAuthServerBundle\Model; use OAuth2\Model\IOAuth2AuthCode; diff --git a/Model/OAuth2AuthCodeManager.php b/Model/OAuth2AuthCodeManager.php index 944b3bcc..479b1e5a 100644 --- a/Model/OAuth2AuthCodeManager.php +++ b/Model/OAuth2AuthCodeManager.php @@ -1,6 +1,6 @@ diff --git a/Model/OAuth2Client.php b/Model/OAuth2Client.php index ec07d6b3..70d1006c 100644 --- a/Model/OAuth2Client.php +++ b/Model/OAuth2Client.php @@ -1,9 +1,9 @@ isValid()) { - Arnaud Le Blanc - Inspirated by [BazingaOAuthBundle](https://github.com/willdurand/BazingaOAuthServerBundle) and [FOSUserBundle](https://github.com/FriendsOfSymfony/FOSUserBundle) - Installation doc adapted from [FOSUserBundle](https://github.com/FriendsOfSymfony/FOSUserBundle) doc. - diff --git a/Resources/config/odm.xml b/Resources/config/odm.xml index 4273dd5a..89f54820 100644 --- a/Resources/config/odm.xml +++ b/Resources/config/odm.xml @@ -5,26 +5,21 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Alb\OAuth2ServerBundle\Document\OAuth2ClientManager - Alb\OAuth2ServerBundle\Document\OAuth2AccessTokenManager - + FOS\OAuthServerBundle\Document\OAuthClientManager + FOS\OAuthServerBundle\Document\OAuthAccessTokenManager - - + - %alb.oauth2.server.model.client.class% + %fos.oauth_server.model.client.class% - + - %alb.oauth2.server.model.access.token.class% + %fos.oauth_server.model.access.token.class% - - - diff --git a/Resources/config/orm.xml b/Resources/config/orm.xml index 683b02da..f562173e 100644 --- a/Resources/config/orm.xml +++ b/Resources/config/orm.xml @@ -5,32 +5,29 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Alb\OAuth2ServerBundle\Entity\OAuth2ClientManager - Alb\OAuth2ServerBundle\Entity\OAuth2AccessTokenManager - Alb\OAuth2ServerBundle\Entity\OAuth2AuthCodeManager + FOS\OAuthServerBundle\Entity\OAuthClientManager + FOS\OAuthServerBundle\Entity\OAuthAccessTokenManager + FOS\OAuthServerBundle\Entity\OAuthAuthCodeManager - - + - %alb.oauth2.server.model.client.class% + %fos.oauth_server.model.client.class% - + - %alb.oauth2.server.model.access.token.class% + %fos.oauth_server.model.access.token.class% - + - %alb.oauth2.server.model.auth.code.class% + %fos.oauth_server.model.auth.code.class% - - diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 974628d4..7399a741 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,6 +1,4 @@ - -alb_oauth2_server_token: +fos_oauth_server_token: pattern: /oauth/v2/token defaults: - _controller: alb.oauth2.server.controller.server:tokenAction - + _controller: fos.oauth_server.controller.server:tokenAction diff --git a/Resources/config/security.yml b/Resources/config/security.yml index 5b0a00b1..aeada34d 100644 --- a/Resources/config/security.yml +++ b/Resources/config/security.yml @@ -1,3 +1,3 @@ security: factories: - - "%kernel.root_dir%/../vendor/bundles/Alb/OAuth2ServerBundle/Resources/config/security_factories.xml" + - "%kernel.root_dir%/../vendor/bundles/FOS/OAuthServerBundle/Resources/config/security_factories.xml" diff --git a/Resources/config/security_factories.xml b/Resources/config/security_factories.xml index d9607c3f..dc94c345 100644 --- a/Resources/config/security_factories.xml +++ b/Resources/config/security_factories.xml @@ -3,12 +3,12 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Alb\OAuth2ServerBundle\DependencyInjection\Security\Factory\OAuth2Factory + FOS\OAuthServerBundle\DependencyInjection\Security\Factory\OAuthFactory - + diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 53ef6a59..2010fa1c 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -5,66 +5,62 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Alb\OAuth2ServerBundle\Controller\ServerController + FOS\OAuthServerBundle\Controller\ServerController - OAuth2\OAuth2 - Alb\OAuth2ServerBundle\Service\OAuth2StorageService + OAuth2\OAuth2 + FOS\OAuthServerBundle\Storage\OAuthStorage - Alb\OAuth2ServerBundle\Security\Authentification\Provider\OAuth2Provider - Alb\OAuth2ServerBundle\Security\Firewall\OAuth2Listener + FOS\OAuthServerBundle\Security\Authentification\Provider\OAuthProvider + FOS\OAuthServerBundle\Security\Firewall\OAuthListener - Alb\OAuth2ServerBundle\Security\EntryPoint\OAuth2EntryPoint + FOS\OAuthServerBundle\Security\EntryPoint\OAuthEntryPoint - - + - + - - - - - + + + + null - + - - - %alb.oauth2.server.server_service.options% + + + %fos.oauth_server.server_service.options% - + - + - + + - + - - + + - - - - - + + + - diff --git a/Resources/translations/messages.fr.xliff b/Resources/translations/messages.fr.xliff deleted file mode 100644 index fd59e6c1..00000000 --- a/Resources/translations/messages.fr.xliff +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - Symfony2 is great - J'aime Symfony2 - - - - diff --git a/Security/Authentification/Provider/OAuth2Provider.php b/Security/Authentification/Provider/OAuthProvider.php similarity index 78% rename from Security/Authentification/Provider/OAuth2Provider.php rename to Security/Authentification/Provider/OAuthProvider.php index d9004079..e8240f79 100644 --- a/Security/Authentification/Provider/OAuth2Provider.php +++ b/Security/Authentification/Provider/OAuthProvider.php @@ -1,6 +1,15 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\Security\Authentification\Provider; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface; @@ -8,19 +17,18 @@ use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\User\UserProviderInterface; -use Alb\OAuth2ServerBundle\Model\Provider\OAuth2TokenProviderInterface; -use Alb\OAuth2ServerBundle\Security\Authentification\Token\OAuth2Token; +use FOS\OAuthServerBundle\Model\Provider\OAuth2TokenProviderInterface; +use FOS\OAuthServerBundle\Security\Authentification\Token\OAuth2Token; + use OAuth2\OAuth2; use OAuth2\OAuth2ServerException; /** - * OAuth2Provider class. + * OAuthProvider class. * - * @package AlbOAuth2ServerBundle - * @subpackage Security * @author Arnaud Le Blanc */ -class OAuth2Provider implements AuthenticationProviderInterface +class OAuthProvider implements AuthenticationProviderInterface { /** * @var \Symfony\Component\Security\Core\User\UserProviderInterface diff --git a/Security/Authentification/Token/OAuth2Token.php b/Security/Authentification/Token/OAuthToken.php similarity index 53% rename from Security/Authentification/Token/OAuth2Token.php rename to Security/Authentification/Token/OAuthToken.php index c8a3667c..c70cac85 100644 --- a/Security/Authentification/Token/OAuth2Token.php +++ b/Security/Authentification/Token/OAuthToken.php @@ -1,17 +1,24 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\Security\Authentification\Token; use Symfony\Component\Security\Core\Authentication\Token\AbstractToken; /** - * OAuth2Token class. + * OAuthToken class. * - * @package AlbOAuth2ServerBundle - * @subpackage Security * @author Arnaud Le Blanc */ -class OAuth2Token extends AbstractToken +class OAuthToken extends AbstractToken { /** * @var string diff --git a/Security/EntryPoint/OAuth2EntryPoint.php b/Security/EntryPoint/OAuthEntryPoint.php similarity index 70% rename from Security/EntryPoint/OAuth2EntryPoint.php rename to Security/EntryPoint/OAuthEntryPoint.php index 9f0ca59b..77a4b52b 100644 --- a/Security/EntryPoint/OAuth2EntryPoint.php +++ b/Security/EntryPoint/OAuthEntryPoint.php @@ -1,15 +1,25 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\Security\EntryPoint; use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; + use OAuth2\OAuth2AuthenticateException; use OAuth2\OAuth2; -class OAuth2EntryPoint implements AuthenticationEntryPointInterface +class OAuthEntryPoint implements AuthenticationEntryPointInterface { protected $serverService; @@ -27,8 +37,7 @@ public function start(Request $request, AuthenticationException $authException = , 'access_denied' , 'OAuth2 authentication required' ); - + return $exception->getHttpResponse(); } } - diff --git a/Security/Firewall/OAuth2Listener.php b/Security/Firewall/OAuthListener.php similarity index 83% rename from Security/Firewall/OAuth2Listener.php rename to Security/Firewall/OAuthListener.php index 6fa0fdec..9968e06f 100644 --- a/Security/Firewall/OAuth2Listener.php +++ b/Security/Firewall/OAuthListener.php @@ -1,39 +1,48 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\Security\Firewall; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use Symfony\Component\Security\Http\Firewall\ListenerInterface; +use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Http\Firewall\ListenerInterface; + +use FOS\OAuthServerBundle\Security\Authentification\Token\OAuth2Token; -use Alb\OAuth2ServerBundle\Security\Authentification\Token\OAuth2Token; use OAuth2\OAuth2; use OAuth2\OAuth2ServerException; -use Symfony\Component\Security\Core\Exception\AuthenticationException; /** - * OAuth2Listener class. + * OAuthListener class. * - * @package AlbOAuth2ServerBundle - * @subpackage Security * @author Arnaud Le Blanc */ -class OAuth2Listener implements ListenerInterface +class OAuthListener implements ListenerInterface { /** * @var \Symfony\Component\Security\Core\SecurityContextInterface */ protected $securityContext; + /** * @var \Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface */ protected $authenticationManager; /** - * @var OAuth2\OAuth2 + * @var \OAuth2\OAuth2 */ protected $serverService; diff --git a/Service/OAuth2StorageService.php b/Storage/OAuthStorage.php similarity index 76% rename from Service/OAuth2StorageService.php rename to Storage/OAuthStorage.php index c5689b07..ed3c6560 100644 --- a/Service/OAuth2StorageService.php +++ b/Storage/OAuthStorage.php @@ -1,33 +1,44 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\OAuthServerBundle\Storage; + +use FOS\OAuthServerBundle\Model\OAuth2AccessTokenManagerInterface; +use FOS\OAuthServerBundle\Model\OAuth2AuthCodeManagerInterface; +use FOS\OAuthServerBundle\Model\OAuth2ClientManagerInterface; +use FOS\OAuthServerBundle\Model\OAuth2ClientInterface; -use OAuth2\IOAuth2Storage; -use Alb\OAuth2ServerBundle\Model\OAuth2ClientManagerInterface; -use OAuth2\Model\IOAuth2Client; -use Alb\OAuth2ServerBundle\Model\OAuth2ClientInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; +use Symfony\Component\Security\Core\Exception\AuthenticationException; + +use OAuth2\IOAuth2Storage; use OAuth2\IOAuth2GrantUser; use OAuth2\IOAuth2GrantCode; -use Alb\OAuth2ServerBundle\Model\OAuth2AccessTokenManagerInterface; -use Alb\OAuth2ServerBundle\Model\OAuth2AuthCodeManagerInterface; -use Symfony\Component\Security\Core\Exception\AuthenticationException; +use OAuth2\Model\IOAuth2Client; -class OAuth2StorageService implements IOAuth2Storage, IOAuth2GrantUser, IOAuth2GrantCode +class OAuth2Storage implements IOAuth2Storage, IOAuth2GrantUser, IOAuth2GrantCode { /** - * @var \Alb\OAuth2ServerBundle\Model\OAuth2ClientManagerInterface + * @var \FOS\OAuthServerBundle\Model\OAuth2ClientManagerInterface */ protected $clientManager; /** - * @var \Alb\OAuth2ServerBundle\Model\OAuth2AccessTokenManagerInterface + * @var \FOS\OAuthServerBundle\Model\OAuth2AccessTokenManagerInterface */ protected $accessTokenManager; /** - * @var \Alb\OAuth2ServerBundle\Model\OAuth2AuthCodeManagerInterface; + * @var \FOS\OAuthServerBundle\Model\OAuth2AuthCodeManagerInterface; */ protected $authCodeManager; @@ -42,13 +53,14 @@ class OAuth2StorageService implements IOAuth2Storage, IOAuth2GrantUser, IOAuth2G protected $encoderFactory; /** - * @param \Alb\OAuth2ServerBundle\Model\OAuth2ClientManagerInterface $clientManager - * @param \Alb\OAuth2ServerBundle\Model\OAuth2AccessTokenManagerInterface $accessTokenManager - * @param \Alb\OAuth2ServerBundle\Model\OAuth2AuthCodeManagerInterface $authCodeManager + * @param \FOS\OAuthServerBundle\Model\OAuth2ClientManagerInterface $clientManager + * @param \FOS\OAuthServerBundle\Model\OAuth2AccessTokenManagerInterface $accessTokenManager + * @param \FOS\OAuthServerBundle\Model\OAuth2AuthCodeManagerInterface $authCodeManager * @param null|\Symfony\Component\Security\Core\User\UserProviderInterface $userProvider * @param null|\Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface $encoderFactory */ - public function __construct(OAuth2ClientManagerInterface $clientManager, OAuth2AccessTokenManagerInterface $accessTokenManager, OAuth2AuthCodeManagerInterface $authCodeManager, UserProviderInterface $userProvider = null, EncoderFactoryInterface $encoderFactory = null) + public function __construct(OAuth2ClientManagerInterface $clientManager, OAuth2AccessTokenManagerInterface $accessTokenManager, + OAuth2AuthCodeManagerInterface $authCodeManager, UserProviderInterface $userProvider = null, EncoderFactoryInterface $encoderFactory = null) { $this->clientManager = $clientManager; $this->accessTokenManager = $accessTokenManager; @@ -157,7 +169,4 @@ public function createAuthCode($code, IOAuth2Client $client, $data, $redirect_ur return $authCode; } - - } - diff --git a/Tests/Entity/OAuth2TokenManagerTest.php b/Tests/Entity/OAuth2TokenManagerTest.php index 760abfb3..f47181c4 100644 --- a/Tests/Entity/OAuth2TokenManagerTest.php +++ b/Tests/Entity/OAuth2TokenManagerTest.php @@ -1,9 +1,9 @@ class = 'Alb\OAuth2ServerBundle\Entity\OAuth2AccessToken'; + $this->class = 'FOS\OAuthServerBundle\Entity\OAuth2AccessToken'; $this->repository = $this->getMock('Doctrine\ORM\EntityRepository', array(), array(), '', false); $this->em = $this->getMock('Doctrine\ORM\EntityManager', array(), array(), '', false); $this->em->expects($this->once()) diff --git a/Tests/Model/OAuth2TokenTest.php b/Tests/Model/OAuth2TokenTest.php index 604d2f8a..7e8d26ac 100644 --- a/Tests/Model/OAuth2TokenTest.php +++ b/Tests/Model/OAuth2TokenTest.php @@ -1,8 +1,8 @@ setToken('x'); - $accessToken = new OAuth2AccessToken; + $accessToken = new OAuthAccessToken(); $accessToken->setData($this->user); $this->serverService->expects($this->once()) @@ -44,7 +44,7 @@ public function testAuthenticateReturnsTokenIfValidEvenIfNullData() $token = new OAuth2Token; $token->setToken('x'); - $accessToken = new OAuth2AccessToken; + $accessToken = new OAuthAccessToken(); $accessToken->setData(null); $this->serverService->expects($this->once()) diff --git a/Tests/Service/OAuth2StorageServiceTest.php b/Tests/Storage/OAuthStorageTest.php similarity index 91% rename from Tests/Service/OAuth2StorageServiceTest.php rename to Tests/Storage/OAuthStorageTest.php index 2a2732a2..89455b4f 100644 --- a/Tests/Service/OAuth2StorageServiceTest.php +++ b/Tests/Storage/OAuthStorageTest.php @@ -1,30 +1,35 @@ clientManager = $this->getMock('Alb\OAuth2ServerBundle\Model\OAuth2ClientManagerInterface'); - $this->accessTokenManager = $this->getMock('Alb\OAuth2ServerBundle\Model\OAuth2AccessTokenManagerInterface'); - $this->authCodeManager = $this->getMock('Alb\OAuth2ServerBundle\Model\OAuth2AuthCodeManagerInterface'); + $this->clientManager = $this->getMock('FOS\OAuthServerBundle\Model\OAuth2ClientManagerInterface'); + $this->accessTokenManager = $this->getMock('FOS\OAuthServerBundle\Model\OAuth2AccessTokenManagerInterface'); + $this->authCodeManager = $this->getMock('FOS\OAuthServerBundle\Model\OAuth2AuthCodeManagerInterface'); $this->userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface'); $this->encoderFactory = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface'); - $this->storage = new OAuth2StorageService($this->clientManager, $this->accessTokenManager, $this->authCodeManager, $this->userProvider, $this->encoderFactory); + $this->storage = new OAuthStorage($this->clientManager, $this->accessTokenManager, $this->authCodeManager, $this->userProvider, $this->encoderFactory); } public function testGetClientReturnsClientWithGivenId() @@ -278,7 +283,7 @@ public function testCreateAuthCode() public function testGetAuthCodeReturnsAuthCodeWithGivenId() { - $code = new OAuth2AuthCode; + $code = new OAuthAuthCode(); $this->authCodeManager->expects($this->once()) ->method('findAuthCodeByToken') @@ -290,7 +295,7 @@ public function testGetAuthCodeReturnsAuthCodeWithGivenId() public function testGetAuthCodeReturnsNullIfNotExists() { - $code = new OAuth2AuthCode; + $code = new OAuthAuthCode(); $this->authCodeManager->expects($this->once()) ->method('findAuthCodeByToken') @@ -299,7 +304,4 @@ public function testGetAuthCodeReturnsNullIfNotExists() $this->assertNull($this->storage->getAuthCode('123_abc')); } - - } - diff --git a/Util/Random.php b/Util/Random.php index f81d17df..c95db49f 100644 --- a/Util/Random.php +++ b/Util/Random.php @@ -1,6 +1,6 @@ =5.3.2", "alb/oauth2-php": "*", "symfony/framework-bundle": "2.*" }, - "suggest": { - "symfony/doctrine-bundle": "*", - "symfony/mongodb-odm-bundle": "*" - }, "autoload": { - "psr-0": { "Alb\\OAuth2ServerBundle": "" } + "psr-0": { "FOS\\OAuthServerBundle": "" } }, - "target-dir": "Alb/OAuth2ServerBundle" + "target-dir": "FOS/OAuthServerBundle" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2029c183..625c7ddb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,7 @@ --> - + ./Tests