Skip to content
Snippets Groups Projects
Commit 1a000e92 authored by Groß-Vogt, Tobias's avatar Groß-Vogt, Tobias
Browse files

person event subscriber handling pre and post event allowing persons to be...

person event subscriber handling pre and post event allowing persons to be filtered by local data attributes configured in bundle config
parent 30b33954
No related branches found
No related tags found
No related merge requests found
Pipeline #229225 passed
......@@ -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"
}
......@@ -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;
}
......
......@@ -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]);
}
......
<?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()]);
}
}
<?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;
}
}
......@@ -4,7 +4,7 @@ services:
autowire: true
autoconfigure: true
Dbp\Relay\BasePersonConnectorLdapBundle\EventSubscriber\PersonPostEventSubscriber:
Dbp\Relay\BasePersonConnectorLdapBundle\EventSubscriber\PersonEventSubscriber:
autowire: true
autoconfigure: true
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment