Skip to content

Commit

Permalink
fix(symfony): graphql security/validator only when enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Sep 5, 2023
1 parent 31b7a61 commit 7ecfdff
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/GraphQl/Tests/Util/ArrayTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace ApiPlatform\Tests\Util;
namespace ApiPlatform\GraphQl\Tests\Util;

use ApiPlatform\GraphQl\Util\ArrayTrait;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,10 @@ private function registerValidatorConfiguration(ContainerBuilder $container, arr
$loader->load('metadata/validator.xml');
$loader->load('symfony/validator.xml');

if ($this->isConfigEnabled($container, $config['graphql'])) {
$loader->load('graphql/validator.xml');
}

$container->registerForAutoconfiguration(ValidationGroupsGeneratorInterface::class)
->addTag('api_platform.validation_groups_generator');
$container->registerForAutoconfiguration(PropertySchemaRestrictionMetadataInterface::class)
Expand Down Expand Up @@ -808,6 +812,10 @@ private function registerSecurityConfiguration(ContainerBuilder $container, arra

$loader->load('security.xml');
$loader->load('legacy/security.xml');

if ($this->isConfigEnabled($container, $config['graphql'])) {
$loader->load('graphql/security.xml');
}
}

private function registerOpenApiConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
Expand Down
23 changes: 23 additions & 0 deletions src/Symfony/Bundle/Resources/config/graphql/security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="api_platform.graphql.state_provider.access_checker" class="ApiPlatform\Symfony\Security\State\AccessCheckerProvider" decorates="api_platform.graphql.state_provider.read">
<argument type="service" id="api_platform.graphql.state_provider.access_checker.inner" />
<argument type="service" id="api_platform.security.resource_access_checker" />
</service>

<service id="api_platform.graphql.state_provider.access_checker.post_deserialize" class="ApiPlatform\Symfony\Security\State\AccessCheckerProvider" decorates="api_platform.graphql.state_provider.denormalizer">
<argument type="service" id="api_platform.graphql.state_provider.access_checker.post_deserialize.inner" />
<argument type="service" id="api_platform.security.resource_access_checker" />
<argument>post_denormalize</argument>
</service>

<service id="api_platform.graphql.state_provider.access_checker.post_validate" class="ApiPlatform\Symfony\Security\State\AccessCheckerProvider" decorates="api_platform.graphql.state_provider.validate">
<argument type="service" id="api_platform.graphql.state_provider.access_checker.post_validate.inner" />
<argument type="service" id="api_platform.security.resource_access_checker" />
<argument>post_validate</argument>
</service>
</services>
</container>
10 changes: 10 additions & 0 deletions src/Symfony/Bundle/Resources/config/graphql/validator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="api_platform.graphql.state_provider.validate" class="ApiPlatform\Symfony\Validator\State\ValidateProvider" decorates="api_platform.graphql.state_provider" decoration-priority="200">
<argument type="service" id="api_platform.graphql.state_provider.validate.inner" />
<argument type="service" id="api_platform.validator" />
</service>
</services>
</container>
17 changes: 0 additions & 17 deletions src/Symfony/Bundle/Resources/config/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@
<argument>post_validate</argument>
</service>

<service id="api_platform.graphql.state_provider.access_checker" class="ApiPlatform\Symfony\Security\State\AccessCheckerProvider" decorates="api_platform.graphql.state_provider.read">
<argument type="service" id="api_platform.graphql.state_provider.access_checker.inner" />
<argument type="service" id="api_platform.security.resource_access_checker" />
</service>

<service id="api_platform.graphql.state_provider.access_checker.post_deserialize" class="ApiPlatform\Symfony\Security\State\AccessCheckerProvider" decorates="api_platform.graphql.state_provider.denormalizer">
<argument type="service" id="api_platform.graphql.state_provider.access_checker.post_deserialize.inner" />
<argument type="service" id="api_platform.security.resource_access_checker" />
<argument>post_denormalize</argument>
</service>

<service id="api_platform.graphql.state_provider.access_checker.post_validate" class="ApiPlatform\Symfony\Security\State\AccessCheckerProvider" decorates="api_platform.graphql.state_provider.validate">
<argument type="service" id="api_platform.graphql.state_provider.access_checker.post_validate.inner" />
<argument type="service" id="api_platform.security.resource_access_checker" />
<argument>post_validate</argument>
</service>

<service id="api_platform.security.expression_language_provider" class="ApiPlatform\Symfony\Security\Core\Authorization\ExpressionLanguageProvider" public="false">
<tag name="security.expression_language_provider" />
</service>
Expand Down
5 changes: 0 additions & 5 deletions src/Symfony/Bundle/Resources/config/symfony/validator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
<argument type="service" id="api_platform.validator" />
</service>

<service id="api_platform.graphql.state_provider.validate" class="ApiPlatform\Symfony\Validator\State\ValidateProvider" decorates="api_platform.graphql.state_provider" decoration-priority="200">
<argument type="service" id="api_platform.graphql.state_provider.validate.inner" />
<argument type="service" id="api_platform.validator" />
</service>

</services>

</container>

0 comments on commit 7ecfdff

Please sign in to comment.