diff --git a/composer.json b/composer.json index 8bd288609d888654e8d453ff368bfd3ae097a64d..82c9e8e393808debdc188f418e9052e78a59cbb4 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "adldap2/adldap2": "^10.3", "dbp/relay-auth-bundle": "^0.1.6", "dbp/relay-base-person-bundle": "^0.2.3", - "dbp/relay-core-bundle": "^0.1.38", + "dbp/relay-core-bundle": "dev-main as 0.1.70", "guzzlehttp/guzzle": "^7.3", "league/uri": "^6.5", "symfony/event-dispatcher": "^5.4", diff --git a/composer.lock b/composer.lock index 1d5357bc8f2d0a737fc3f5a131dc0ddbe90e7ba7..fb2605c65b599b6b7db69aae643ebac470b14cb3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3bae2dabba694977c46a0557c76fcef7", + "content-hash": "8a41e103e0332f92f063b1f9f8a437a3", "packages": [ { "name": "adldap2/adldap2", @@ -397,11 +397,11 @@ }, { "name": "dbp/relay-core-bundle", - "version": "v0.1.70", + "version": "dev-main", "source": { "type": "git", "url": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-core-bundle", - "reference": "fb3da145b43da96a8abf0d024ab2c4a551edf186" + "reference": "2afa838323465318bb01c7470e822536aef57067" }, "require": { "api-platform/core": "^2.6.8 <2.7.0", @@ -447,6 +447,7 @@ "symfony/phpunit-bridge": "^5.4.11", "vimeo/psalm": "^4.27" }, + "default-branch": true, "type": "symfony-bundle", "extra": { "hooks": { @@ -465,7 +466,7 @@ "AGPL-3.0-or-later" ], "description": "The core bundle of the Relay API gateway", - "time": "2022-12-14T13:19:53+00:00" + "time": "2023-01-26T11:56:06+00:00" }, { "name": "doctrine/annotations", @@ -11184,9 +11185,18 @@ "time": "2015-12-17T08:42:14+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "dbp/relay-core-bundle", + "version": "dev-main", + "alias": "0.1.70", + "alias_normalized": "0.1.70.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "dbp/relay-core-bundle": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -11198,5 +11208,5 @@ "platform-overrides": { "php": "7.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index c03bb4a68a4026f01ab28371ab9da9ea81d3b6ec..863ca33ac1c12c2688ac9bb2a6899f946c0693ae 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Dbp\Relay\BasePersonConnectorLdapBundle\DependencyInjection; -use Dbp\Relay\BasePersonConnectorLdapBundle\EventSubscriber\PersonPostEventSubscriber; +use Dbp\Relay\BasePersonConnectorLdapBundle\EventSubscriber\PersonEventSubscriber; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -44,7 +44,7 @@ class Configuration implements ConfigurationInterface $ldapNode->append($attributesNode); $rootNode->append($ldapNode); - $rootNode->append(PersonPostEventSubscriber::getLocalDataMappingConfigNodeDefinition()); + $rootNode->append(PersonEventSubscriber::getLocalDataMappingConfigNodeDefinition()); return $treeBuilder; } diff --git a/src/DependencyInjection/DbpRelayBasePersonConnectorLdapExtension.php b/src/DependencyInjection/DbpRelayBasePersonConnectorLdapExtension.php index 695787d3fac0e35717011e80638b8212ec705a5d..d8cf187192428e4e749986bd01c86841ac4c2797 100644 --- a/src/DependencyInjection/DbpRelayBasePersonConnectorLdapExtension.php +++ b/src/DependencyInjection/DbpRelayBasePersonConnectorLdapExtension.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Dbp\Relay\BasePersonConnectorLdapBundle\DependencyInjection; -use Dbp\Relay\BasePersonConnectorLdapBundle\EventSubscriber\PersonPostEventSubscriber; +use Dbp\Relay\BasePersonConnectorLdapBundle\EventSubscriber\PersonEventSubscriber; use Dbp\Relay\BasePersonConnectorLdapBundle\Service\LDAPApi; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Config\FileLocator; @@ -37,7 +37,7 @@ class DbpRelayBasePersonConnectorLdapExtension extends ConfigurableExtension $definition->addMethodCall('setLDAPCache', [$ldapCache, 360]); $definition->addMethodCall('setPersonCache', [$personCacheDef]); - $postEventSubscriber = $container->getDefinition(PersonPostEventSubscriber::class); + $postEventSubscriber = $container->getDefinition(PersonEventSubscriber::class); $postEventSubscriber->addMethodCall('setConfig', [$mergedConfig]); } diff --git a/src/EventSubscriber/PersonEventSubscriber.php b/src/EventSubscriber/PersonEventSubscriber.php new file mode 100644 index 0000000000000000000000000000000000000000..d49c68ebcfc557700f2884e112fe2fe0e5847718 --- /dev/null +++ b/src/EventSubscriber/PersonEventSubscriber.php @@ -0,0 +1,27 @@ +<?php + +declare(strict_types=1); + +namespace Dbp\Relay\BasePersonConnectorLdapBundle\EventSubscriber; + +use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonPostEvent; +use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonPreEvent; +use Dbp\Relay\BasePersonConnectorLdapBundle\Service\LDAPApi; +use Dbp\Relay\CoreBundle\LocalData\AbstractLocalDataEventSubscriber; +use Dbp\Relay\CoreBundle\LocalData\LocalDataPreEvent; + +class PersonEventSubscriber extends AbstractLocalDataEventSubscriber +{ + public static function getSubscribedEventNames(): array + { + return [ + PersonPreEvent::class, + PersonPostEvent::class, + ]; + } + + protected function onPre(LocalDataPreEvent $preEvent) + { + $preEvent->setQueryParameters([LDAPApi::FILTERS_OPTION => $preEvent->getQueryParameters()]); + } +} diff --git a/src/EventSubscriber/PersonPostEventSubscriber.php b/src/EventSubscriber/PersonPostEventSubscriber.php deleted file mode 100644 index e4f79217fe7ee01078c198f1306ed2c1850e5fa7..0000000000000000000000000000000000000000 --- a/src/EventSubscriber/PersonPostEventSubscriber.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\BasePersonConnectorLdapBundle\EventSubscriber; - -use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonPostEvent; -use Dbp\Relay\CoreBundle\LocalData\AbstractLocalDataPostEventSubscriber; - -class PersonPostEventSubscriber extends AbstractLocalDataPostEventSubscriber -{ - public static function getSubscribedEventName(): string - { - return PersonPostEvent::class; - } -} diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 89f2868c3ae1539755d5fa1958a338e354352ff7..64e574673d14d36c1d5b3b835ff70aa904c28c2f 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -4,7 +4,7 @@ services: autowire: true autoconfigure: true - Dbp\Relay\BasePersonConnectorLdapBundle\EventSubscriber\PersonPostEventSubscriber: + Dbp\Relay\BasePersonConnectorLdapBundle\EventSubscriber\PersonEventSubscriber: autowire: true autoconfigure: true diff --git a/src/Service/LDAPApi.php b/src/Service/LDAPApi.php index 6b230fc7b28f4e16ee8b87715f03547474c8cda9..34d183e497ddce36ba9fb2d8012888873c1b43f6 100644 --- a/src/Service/LDAPApi.php +++ b/src/Service/LDAPApi.php @@ -36,6 +36,9 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface { use LoggerAwareTrait; + public const SEARCH_OPTION = 'search'; + public const FILTERS_OPTION = 'filters'; + /** @var ProviderInterface|null */ private $provider; @@ -203,10 +206,10 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface $builder = $this->getCachedBuilder($provider); $search = $builder - ->where('objectClass', '=', $provider->getSchema()->person()); + ->whereEquals('objectClass', $provider->getSchema()->person()); - if (isset($options['search'])) { - $items = explode(' ', $options['search']); + if (($searchOption = $options[self::SEARCH_OPTION] ?? null) !== null) { + $items = explode(' ', $searchOption); // search for all substrings foreach ($items as $item) { @@ -214,6 +217,12 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface } } + if (($filtersOption = $options[self::FILTERS_OPTION] ?? null) !== null) { + foreach ($filtersOption as $fieldName => $fieldValue) { + $search->whereContains($fieldName, $fieldValue); + } + } + // API platform's first page is 1, Adldap's first page is 0 $currentPageIndex = $currentPageNumber - 1; @@ -226,6 +235,11 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface } /* + * @param array $options Available options are: + * * LDAPApi::SEARCH_OPTION (string) Return all persons whose full name contains the given whitespace separated list of strings + * * LDAPApi::FILTERS_OPTIONS (array) Return all persons, where the given field names (array keys) contain the given field values (array values). Multiple filters are combined with a logical 'and'. + * E.g. [ 'some-attribute' => 'some-value', .... ] + * * @return Person[] * * @throws ApiError @@ -265,7 +279,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface /** @var User $user */ $user = $builder - ->where('objectClass', '=', $provider->getSchema()->person()) + ->whereEquals('objectClass', $provider->getSchema()->person()) ->whereEquals($this->identifierAttributeName, $identifier) ->first();