Skip to content

Commit

Permalink
Merge 5d42441 into 22b829f
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Jul 15, 2019
2 parents 22b829f + 5d42441 commit 1eec2cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 12 additions & 2 deletions DependencyInjection/GraphqliteCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public function process(ContainerBuilder $container)
$controllersNamespaces = $container->getParameter('graphqlite.namespace.controllers');
$typesNamespaces = $container->getParameter('graphqlite.namespace.types');

$firewallName = $container->getParameter('graphqlite.security.firewall_name');
$firewallConfigServiceName = 'security.firewall.map.config.'.$firewallName;

// 2 seconds of TTL in environment mode. Otherwise, let's cache forever!

$schemaFactory = $container->getDefinition(SchemaFactory::class);
Expand All @@ -99,7 +102,7 @@ public function process(ContainerBuilder $container)

$disableLogin = false;
if ($container->getParameter('graphqlite.security.enable_login') === 'auto'
&& (!$container->has(UserProviderInterface::class) ||
&& (!$container->has($firewallConfigServiceName) ||
!$container->has(UserPasswordEncoderInterface::class) ||
!$container->has(TokenStorageInterface::class) ||
!$container->has(SessionInterface::class)
Expand All @@ -119,11 +122,18 @@ public function process(ContainerBuilder $container)
if (!$container->has(SessionInterface::class)) {
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).');
}
if (!$container->has(UserPasswordEncoderInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has(UserProviderInterface::class)) {
if (!$container->has(UserPasswordEncoderInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has($firewallConfigServiceName)) {
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)');
}
}

if ($disableLogin === false) {
// Let's do some dark magic. We need the user provider. We need its name. It is stored in the "config" object.
$provider = $container->findDefinition('security.firewall.map.config.'.$firewallName)->getArgument(5);

$container->findDefinition(LoginController::class)->setArgument(0, new Reference($provider));
}


foreach ($container->getDefinitions() as $id => $definition) {
if ($definition->isAbstract() || $definition->getClass() === null) {
Expand Down
13 changes: 12 additions & 1 deletion Tests/GraphqliteTestingKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,21 @@ public function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
],
],
],
'in_memory_other' => [
'memory' => [
'users' => [
'foo' => [
'password' => 'bar',
'roles' => 'ROLE_USER',
],
],
],
],
],
'firewalls' => [
'main' => [
'anonymous' => true
'anonymous' => true,
'provider' => 'in_memory'
]
],
'encoders' => [
Expand Down

0 comments on commit 1eec2cb

Please sign in to comment.