Skip to content

Commit 972bbfb

Browse files
authored
Merge pull request #119 from janatjak/master
symfony 6 (requires SF 5.3+)
2 parents b7682aa + 5c5516e commit 972bbfb

File tree

9 files changed

+60
-49
lines changed

9 files changed

+60
-49
lines changed

.travis.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,21 @@ env:
1313
matrix:
1414
fast_finish: true
1515
include:
16-
# Test the latest stable release
17-
- php: 7.2
18-
env: PHPSTAN=true COMPOSER1=true
19-
- php: 7.4
20-
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text" TESTNOSECURITYBUNDLE=true
16+
# Test latest stable features
17+
- php: 8.1
18+
env: PHPSTAN=true COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"
2119

22-
# Test LTS versions.
23-
- php: 7.4
24-
env: DEPENDENCIES="symfony/lts:^4"
20+
- php: 8.0
2521

26-
# Latest commit to master
22+
# Test the oldest possible release - SF 5.4, PHP 7.4, without security-bundle
2723
- php: 7.4
28-
env: STABILITY="dev"
24+
env: PHPSTAN=true COMPOSER1=true TESTNOSECURITYBUNDLE=true COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
2925

3026
allow_failures:
3127
# Minimum supported dependencies with the latest and oldest PHP version
32-
- php: 7.4
28+
- php: 8.1
3329
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
34-
- php: 7.2
30+
- php: 7.4
3531
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
3632
# Dev-master is allowed to fail.
3733
- env: STABILITY="dev"
@@ -52,11 +48,11 @@ script:
5248
- composer validate --strict --no-check-lock
5349
# simple-phpunit is the PHPUnit wrapper provided by the PHPUnit Bridge component and
5450
# it helps with testing legacy code and deprecations (composer require symfony/phpunit-bridge)
55-
#- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
51+
- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
5652
- if [[ $PHPSTAN == true ]]; then composer phpstan; fi
57-
- ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
53+
#- ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
5854
# Let's test without the security bundle
59-
- if [[ $TESTNOSECURITYBUNDLE == true ]]; then composer remove --dev symfony/security-bundle && phpunit Tests/NoSecurityBundleTest.php; fi
55+
- if [[ $TESTNOSECURITYBUNDLE == true ]]; then composer remove --dev symfony/security-bundle && ./vendor/bin/simple-phpunit Tests/NoSecurityBundleTest.php; fi
6056

6157
after_script:
6258
- ./vendor/bin/php-coveralls -v

Controller/GraphQL/LoginController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
namespace TheCodingMachine\GraphQLite\Bundle\Controller\GraphQL;
33

44

5+
use RuntimeException;
56
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
67
use Symfony\Component\HttpFoundation\Request;
78
use Symfony\Component\HttpFoundation\Session\SessionInterface;
9+
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
810
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
911
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
10-
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
1112
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
13+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
14+
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
1215
use Symfony\Component\Security\Core\User\UserInterface;
1316
use Symfony\Component\Security\Core\User\UserProviderInterface;
1417
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
@@ -22,7 +25,7 @@ class LoginController
2225
*/
2326
private $userProvider;
2427
/**
25-
* @var UserPasswordEncoderInterface
28+
* @var UserPasswordHasherInterface
2629
*/
2730
private $passwordEncoder;
2831
/**
@@ -42,7 +45,7 @@ class LoginController
4245
*/
4346
private $eventDispatcher;
4447

45-
public function __construct(UserProviderInterface $userProvider, UserPasswordEncoderInterface $passwordEncoder, TokenStorageInterface $tokenStorage, SessionInterface $session, EventDispatcherInterface $eventDispatcher, string $firewallName)
48+
public function __construct(UserProviderInterface $userProvider, UserPasswordHasherInterface $passwordEncoder, TokenStorageInterface $tokenStorage, SessionInterface $session, EventDispatcherInterface $eventDispatcher, string $firewallName)
4649
{
4750
$this->userProvider = $userProvider;
4851
$this->passwordEncoder = $passwordEncoder;
@@ -58,12 +61,16 @@ public function __construct(UserProviderInterface $userProvider, UserPasswordEnc
5861
public function login(string $userName, string $password, Request $request): UserInterface
5962
{
6063
try {
61-
$user = $this->userProvider->loadUserByUsername($userName);
62-
} catch (UsernameNotFoundException $e) {
64+
$user = $this->userProvider->loadUserByIdentifier($userName);
65+
} catch (UserNotFoundException $e) {
6366
// FIXME: should we return null instead???
6467
throw InvalidUserPasswordException::create($e);
6568
}
6669

70+
if (!$user instanceof PasswordAuthenticatedUserInterface) {
71+
throw new RuntimeException('$user has to implements ' . PasswordAuthenticatedUserInterface::class);
72+
}
73+
6774
if (!$this->passwordEncoder->isPasswordValid($user, $password)) {
6875
throw InvalidUserPasswordException::create();
6976
}
@@ -72,7 +79,7 @@ public function login(string $userName, string $password, Request $request): Use
7279

7380
// Handle getting or creating the user entity likely with a posted form
7481
// The third parameter "main" can change according to the name of your firewall in security.yml
75-
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
82+
$token = new UsernamePasswordToken($user, 'main', $user->getRoles());
7683
$this->tokenStorage->setToken($token);
7784

7885
// If the firewall name is not main, then the set value would be instead:

DependencyInjection/GraphQLiteCompilerPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Symfony\Component\Cache\Adapter\ApcuAdapter;
1313
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
1414
use Symfony\Component\Cache\Psr16Cache;
15+
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
1516
use TheCodingMachine\GraphQLite\Mappers\StaticClassListTypeMapperFactory;
1617
use Webmozart\Assert\Assert;
1718
use function class_exists;
@@ -33,7 +34,6 @@
3334
use Symfony\Component\DependencyInjection\Reference;
3435
use Symfony\Component\HttpFoundation\Session\SessionInterface;
3536
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
36-
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
3737
use Symfony\Component\Security\Core\User\UserInterface;
3838
use TheCodingMachine\CacheUtils\ClassBoundCache;
3939
use TheCodingMachine\CacheUtils\ClassBoundCacheContract;
@@ -104,7 +104,7 @@ public function process(ContainerBuilder $container): void
104104
$disableLogin = false;
105105
if ($container->getParameter('graphqlite.security.enable_login') === 'auto'
106106
&& (!$container->has($firewallConfigServiceName) ||
107-
!$container->has(UserPasswordEncoderInterface::class) ||
107+
!$container->has(UserPasswordHasherInterface::class) ||
108108
!$container->has(TokenStorageInterface::class) ||
109109
!$container->has(SessionInterface::class)
110110
)) {
@@ -122,7 +122,7 @@ public function process(ContainerBuilder $container): void
122122
if (!$container->has(SessionInterface::class)) {
123123
throw new GraphQLException('In order to enable the login/logout mutations (via the graphqlite.security.enable_login parameter), you need to enable session support (via the "framework.session.enabled" config parameter).');
124124
}
125-
if (!$container->has(UserPasswordEncoderInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has($firewallConfigServiceName)) {
125+
if (!$container->has(UserPasswordHasherInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has($firewallConfigServiceName)) {
126126
throw new GraphQLException('In order to enable the login/logout mutations (via the graphqlite.security.enable_login parameter), you need to install the security bundle. Please be sure to correctly configure the user provider (in the security.providers configuration settings)');
127127
}
128128
}

DependencyInjection/GraphQLiteExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class GraphQLiteExtension extends Extension
1919
{
2020

21-
public function getAlias()
21+
public function getAlias(): string
2222
{
2323
return 'graphqlite';
2424
}

GraphQLiteBundle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace TheCodingMachine\GraphQLite\Bundle;
55

6+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
67
use TheCodingMachine\GraphQLite\Bundle\DependencyInjection\GraphQLiteExtension;
78
use TheCodingMachine\GraphQLite\Bundle\DependencyInjection\OverblogGraphiQLEndpointWiringPass;
89
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
@@ -20,7 +21,7 @@ public function build(ContainerBuilder $container): void
2021
$container->addCompilerPass(new OverblogGraphiQLEndpointWiringPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1);
2122
}
2223

23-
public function getContainerExtension()
24+
public function getContainerExtension(): ?ExtensionInterface
2425
{
2526
if (null === $this->extension) {
2627
$this->extension = new GraphQLiteExtension();

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
# GraphQLite bundle
99

10-
Symfony 4 bundle for the thecodingmachine/graphqlite package.
10+
Symfony 5 bundle for the thecodingmachine/graphqlite package.
1111

1212
See [thecodingmachine/graphqlite](https://github.com/thecodingmachine/graphqlite)

Tests/FunctionalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace TheCodingMachine\GraphQLite\Bundle\Tests;
44

5+
use Symfony\Component\Security\Core\User\InMemoryUser;
56
use function json_decode;
67
use PHPUnit\Framework\TestCase;
78
use Psr\Container\ContainerInterface;
89
use Symfony\Component\HttpFoundation\Request;
910
use Symfony\Component\HttpFoundation\Session\Session;
1011
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
1112
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
12-
use Symfony\Component\Security\Core\User\User;
1313
use TheCodingMachine\GraphQLite\Bundle\Controller\GraphQLiteController;
1414
use TheCodingMachine\GraphQLite\GraphQLRuntimeException as GraphQLException;
1515
use TheCodingMachine\GraphQLite\Schema;
@@ -545,9 +545,9 @@ public function testMaxQueryDepth(): void
545545
private function logIn(ContainerInterface $container)
546546
{
547547
// put a token into the storage so the final calls can function
548-
$user = new User('foo', 'pass');
549-
$token = new UsernamePasswordToken($user, '', 'provider', ['ROLE_USER']);
550-
$container->get('security.token_storage')->setToken($token);
548+
$user = new InMemoryUser('foo', 'pass');
549+
$token = new UsernamePasswordToken($user, 'provider', ['ROLE_USER']);
550+
$container->get('security.untracked_token_storage')->setToken($token);
551551
}
552552

553553
/**

Tests/GraphQLiteTestingKernel.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
99
use Symfony\Bundle\SecurityBundle\SecurityBundle;
1010
use Symfony\Component\Config\Loader\LoaderInterface;
11+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1112
use Symfony\Component\DependencyInjection\ContainerBuilder;
12-
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
1313
use Symfony\Component\HttpKernel\Kernel;
1414
use TheCodingMachine\GraphQLite\Bundle\GraphQLiteBundle;
15-
use Symfony\Component\Security\Core\User\User;
15+
use Symfony\Component\Security\Core\User\InMemoryUser;
1616
use function class_exists;
1717
use function serialize;
1818

19-
class GraphQLiteTestingKernel extends Kernel
19+
class GraphQLiteTestingKernel extends Kernel implements CompilerPassInterface
2020
{
2121
use MicroKernelTrait;
2222

@@ -84,7 +84,7 @@ public function __construct(bool $enableSession = true,
8484
$this->typesNamespace = $typesNamespace;
8585
}
8686

87-
public function registerBundles()
87+
public function registerBundles(): iterable
8888
{
8989
$bundles = [ new FrameworkBundle() ];
9090
if (class_exists(SecurityBundle::class)) {
@@ -112,13 +112,14 @@ public function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
112112
if ($this->enableSession) {
113113
$frameworkConf['session'] =[
114114
'enabled' => true,
115-
'handler_id' => NullSessionHandler::class
115+
'storage_factory_id' => 'session.storage.factory.mock_file',
116116
];
117117
}
118118

119119
$container->loadFromExtension('framework', $frameworkConf);
120120
if ($this->enableSecurity) {
121121
$container->loadFromExtension('security', array(
122+
'enable_authenticator_manager' => true,
122123
'providers' => [
123124
'in_memory' => [
124125
'memory' => [
@@ -143,12 +144,11 @@ public function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
143144
],
144145
'firewalls' => [
145146
'main' => [
146-
'anonymous' => true,
147147
'provider' => 'in_memory'
148148
]
149149
],
150-
'encoders' => [
151-
User::class => 'plaintext',
150+
'password_hashers' => [
151+
InMemoryUser::class => 'plaintext',
152152
],
153153
));
154154
}
@@ -196,8 +196,15 @@ protected function configureRoutes(/*RoutingConfigurator*/ $routes)
196196
$routes->import(__DIR__.'/../Resources/config/routes.xml');
197197
}
198198

199-
public function getCacheDir()
199+
public function getCacheDir(): string
200200
{
201201
return __DIR__.'/../cache/'.($this->enableSession?'withSession':'withoutSession').$this->enableLogin.($this->enableSecurity?'withSecurity':'withoutSecurity').$this->enableMe.'_'.($this->introspection?'withIntrospection':'withoutIntrospection').'_'.$this->maximumQueryComplexity.'_'.$this->maximumQueryDepth.'_'.md5(serialize($this->controllersNamespace).'_'.md5(serialize($this->typesNamespace)));
202202
}
203+
204+
public function process(ContainerBuilder $container): void
205+
{
206+
if ($container->hasDefinition('security.untracked_token_storage')) {
207+
$container->getDefinition('security.untracked_token_storage')->setPublic(true);
208+
}
209+
}
203210
}

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@
1616
}
1717
],
1818
"require" : {
19-
"php" : ">=7.2",
19+
"php" : ">=7.4",
2020
"ext-json": "*",
2121
"thecodingmachine/graphqlite" : "^5.0",
2222
"thecodingmachine/graphqlite-symfony-validator-bridge" : "^5.0",
23-
"symfony/framework-bundle": "^4.2 || ^5",
24-
"symfony/validator": "^4.2 || ^5",
25-
"symfony/translation": "^4.2 || ^5",
23+
"symfony/framework-bundle": "^5.4 || ^6",
24+
"symfony/validator": "^5.4 || ^6",
25+
"symfony/translation": "^5.4 || ^6",
2626
"doctrine/annotations": "^1.13",
2727
"symfony/psr-http-message-bridge": "^2.0",
2828
"nyholm/psr7": "^1.1",
2929
"laminas/laminas-diactoros": "^2.2.2",
30-
"overblog/graphiql-bundle": "^0.1.2 | ^0.2",
30+
"overblog/graphiql-bundle": "^0.2 || ^0.3",
3131
"thecodingmachine/cache-utils": "^1",
32-
"symfony/console": "^4.1.9 | ^5"
32+
"symfony/console": "^5.4 || ^6"
3333
},
3434
"require-dev": {
35-
"symfony/security-bundle": "^4.2 || ^5",
36-
"symfony/yaml": "^4.2 || ^5",
35+
"symfony/security-bundle": "^5.4 || ^6",
36+
"symfony/yaml": "^5.4 || ^6",
3737
"phpstan/phpstan": "^0.12.90",
3838
"beberlei/porpaginas": "^1.2",
3939
"php-coveralls/php-coveralls": "^2.1.0",
40-
"symfony/phpunit-bridge": "^5.3",
40+
"symfony/phpunit-bridge": "^5.4 || ^6",
4141
"thecodingmachine/phpstan-strict-rules": "^v0.12.1",
4242
"composer/package-versions-deprecated": "^1.8",
4343
"phpstan/phpstan-webmozart-assert": "^0.12.12"

0 commit comments

Comments
 (0)