Skip to content

Commit

Permalink
Let's do some black magic to retrieve the correct provider instance a…
Browse files Browse the repository at this point in the history
…t compile time.
  • Loading branch information
moufmouf committed Jul 15, 2019
1 parent 4a6f5b9 commit 5d42441
Showing 1 changed file with 12 additions and 2 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

0 comments on commit 5d42441

Please sign in to comment.