vendor/galilee/pimcore-graphql/src/DependencyInjection/Configuration.php line 48

Open in your IDE?
  1. <?php
  2. namespace Galilee\GraphQlBundle\DependencyInjection;
  3. use Galilee\GraphQlBundle\Services\Security\AskResetPasswordSecurityInterface;
  4. use Galilee\GraphQlBundle\Services\Security\ImpersonateUserSecurityInterface;
  5. use Galilee\GraphQlBundle\Services\Security\LoginSecurityInterface;
  6. use Galilee\GraphQlBundle\Services\Security\ResetPasswordSecurityInterface;
  7. use Galilee\GraphQlBundle\Services\Security\SignupSecurityInterface;
  8. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  9. use Symfony\Component\Config\Definition\ConfigurationInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. class Configuration implements ConfigurationInterface
  12. {
  13.     public function getConfigTreeBuilder()
  14.     {
  15.         $treeBuilder = new TreeBuilder('graph_ql');
  16.         $treeBuilder->getRootNode()
  17.                 ->children()
  18.                 ->arrayNode("jwtSecuredRoutes")
  19.                     ->info("DataHub config names exposed as JWT secured")
  20.                     ->useAttributeAsKey('shortName')
  21.                     ->requiresAtLeastOneElement()
  22.                     ->prototype('array')
  23.                     ->children()
  24.                         ->arrayNode('security')
  25.                         ->info("Allow user to impersonate another (attribute must be part of user, front has to manage on its own, back will apply filters based upon impersonated one)")
  26.                         ->addDefaultsIfNotSet()
  27.                             ->children()
  28.                                 ->arrayNode('userConfiguration')
  29.                                 ->info("front user configuration")
  30.                                 ->addDefaultsIfNotSet()
  31.                                     ->children()
  32.                                         ->scalarNode('frontUserPimcoreClass')
  33.                                             ->cannotBeEmpty()
  34.                                             ->isRequired()
  35.                                             ->info('Class or Interface that will represent frontUser, must implement UserInterface')
  36.                                             ->validate()
  37.                                                 ->ifTrue(function ($v) { return !(file_exists(PIMCORE_PROJECT_ROOT '/deploy.flag') || class_exists($v) || interface_exists($vfalse)); })
  38.                                                 ->thenInvalid('The supported class or interface "%s" do not exist')
  39.                                                 ->ifTrue(function ($v) { return !(file_exists(PIMCORE_PROJECT_ROOT '/deploy.flag') || is_subclass_of($vUserInterface::class)); })
  40.                                                 ->thenInvalid('The supported class or interface "%s" do not implement ' UserInterface::class)
  41.                                             ->end()
  42.                                         ->end()
  43.                                         ->scalarNode("frontUserIdentifierAttribute")
  44.                                             ->defaultValue('email')
  45.                                             ->info("User.attribute used to identify user from JWT token, default: 'email'")
  46.                                         ->end()
  47.                                         ->scalarNode("frontUserPasswordAttribute")
  48.                                             ->defaultValue('password')
  49.                                             ->info("User.attribute used as password, default: 'password'")
  50.                                         ->end()
  51.                                     ->end()
  52.                                 ->end()
  53.                                 ->arrayNode('login')
  54.                                 ->info("Allow user to impersonate another (attribute must be part of user, front has to manage on its own, back will apply filters based upon impersonated one)")
  55.                                 ->addDefaultsIfNotSet()
  56.                                     ->children()
  57.                                         ->scalarNode('guard')
  58.                                             ->cannotBeEmpty()
  59.                                             ->isRequired()
  60.                                             ->defaultValue('Galilee\GraphQlBundle\Services\Security\Default\DefaultLoginSecurityService')
  61.                                             ->info('Class or Interface that will validate frontUser login, must implement ' LoginSecurityInterface::class)
  62.                                             ->validate()
  63.                                                 ->ifTrue(function ($v) { return !(class_exists($v) || interface_exists($vfalse)); })
  64.                                                 ->thenInvalid('The supported class or interface "%s" do not exist')
  65.                                                 ->ifTrue(function ($v) { return !is_subclass_of($vLoginSecurityInterface::class); })
  66.                                                 ->thenInvalid('The supported class or interface "%s" do not implement ' LoginSecurityInterface::class)
  67.                                             ->end()
  68.                                         ->end()
  69.                                     ->end()
  70.                                 ->end()
  71.                                 ->arrayNode('signup')
  72.                                 ->info("Allow user to impersonate another (attribute must be part of user, front has to manage on its own, back will apply filters based upon impersonated one)")
  73.                                 ->addDefaultsIfNotSet()
  74.                                     ->children()
  75.                                         ->scalarNode('guard')
  76.                                             ->defaultValue(null)
  77.                                             ->info('Class or Interface that will validate frontUser signup, to disable use null as value, otherwise must implement ' SignupSecurityInterface::class)
  78.                                             ->validate()
  79.                                                 ->ifTrue(function ($v) { return !(is_null($v) || (class_exists($v) || interface_exists($vfalse))); })
  80.                                                 ->thenInvalid('The supported class or interface "%s" do not exist')
  81.                                                 ->ifTrue(function ($v) { return !(is_null($v) || is_subclass_of($vSignupSecurityInterface::class)); })
  82.                                                 ->thenInvalid('The supported class or interface "%s" do not implement ' SignupSecurityInterface::class)
  83.                                             ->end()
  84.                                         ->end()
  85.                                     ->end()
  86.                                 ->end()
  87.                                 ->arrayNode('resetPassword')
  88.                                 ->info("Allow user to impersonate another (attribute must be part of user, front has to manage on its own, back will apply filters based upon impersonated one)")
  89.                                 ->addDefaultsIfNotSet()
  90.                                     ->children()
  91.                                         ->scalarNode('guardAskResetPassword')
  92.                                             ->defaultValue(null)
  93.                                             ->info('Class or Interface that will validate frontUser asking for new password, to disable use null as value, otherwise must implement ' AskResetPasswordSecurityInterface::class)
  94.                                             ->validate()
  95.                                                 ->ifTrue(function ($v) { return !(is_null($v) || (class_exists($v) || interface_exists($vfalse))); })
  96.                                                 ->thenInvalid('The supported class or interface "%s" do not exist')
  97.                                                 ->ifTrue(function ($v) { return !(is_null($v) || is_subclass_of($vAskResetPasswordSecurityInterface::class)); })
  98.                                                 ->thenInvalid('The supported class or interface "%s" do not implement ' AskResetPasswordSecurityInterface::class)
  99.                                             ->end()
  100.                                         ->end()
  101.                                         ->scalarNode('guardResetPassword')
  102.                                             ->defaultValue(null)
  103.                                             ->info('Class or Interface that will validate frontUser resetting his password post asking for reset, to disable use null as value, otherwise must implement ' ResetPasswordSecurityInterface::class)
  104.                                             ->validate()
  105.                                                 ->ifTrue(function ($v) { return !(is_null($v) || (class_exists($v) || interface_exists($vfalse))); })
  106.                                                 ->thenInvalid('The supported class or interface "%s" do not exist')
  107.                                                 ->ifTrue(function ($v) { return !(is_null($v) || is_subclass_of($vResetPasswordSecurityInterface::class)); })
  108.                                                 ->thenInvalid('The supported class or interface "%s" do not implement ' ResetPasswordSecurityInterface::class)
  109.                                             ->end()
  110.                                         ->end()
  111.                                     ->end()
  112.                                 ->end()
  113.                                 ->arrayNode('impersonatingUserFeature')
  114.                                 ->info("Allow user to impersonate another (attribute must be part of user, front has to manage on its own, back will apply filters based upon impersonated one)")
  115.                                 ->addDefaultsIfNotSet()
  116.                                 ->children()
  117.                                     ->scalarNode('userAttributeName')
  118.                                         ->defaultValue('impersonatedUser')
  119.                                     ->end()
  120.                                     ->scalarNode('guard')
  121.                                         ->defaultValue(null)
  122.                                         ->info('Class or Interface that will define permissions to allow some front user to impersonate another, to disable use null as value, otherwise must implement ' ResetPasswordSecurityInterface::class)
  123.                                         ->validate()
  124.                                             ->ifTrue(function ($v) { return !(is_null($v) || (class_exists($v) || interface_exists($vfalse))); })
  125.                                             ->thenInvalid('The supported class or interface "%s" does not exist.')
  126.                                             ->ifTrue(function ($v) { return !(is_null($v) || is_subclass_of($vImpersonateUserSecurityInterface::class)); })
  127.                                             ->thenInvalid('The supported class "%s" do not implement ' ImpersonateUserSecurityInterface::class)
  128.                                     ->end()
  129.                                 ->end()
  130.                             ->end()
  131.                         ->end()
  132.                     ->end()
  133.                 ->end()
  134.                 ->arrayNode("unsecuredOperations")
  135.                         ->scalarPrototype()->end()
  136.                         ->info("Allow gql operations despite absence of JWT token")
  137.                 ->end()
  138.                 ->arrayNode("disabledOperations")
  139.                         ->scalarPrototype()->end()
  140.                         ->info("Disable gql operations despite dataHubConfig")
  141.                 ->end()
  142.                 ->arrayNode("unsecuredClassDefinition")
  143.                     ->info("Allow to define some allowed classDefinitionQuery based upon classname and attributes")
  144.                     ->useAttributeAsKey('className')
  145.                     ->prototype('array')
  146.                     ->children()
  147.                         ->arrayNode("allowedAttributes")
  148.                             ->prototype('scalar')
  149.                         ->end()
  150.                     ->end()
  151.                 ->end()
  152.             ->end();
  153.         return $treeBuilder;
  154.     }
  155. }