Skip to content
Snippets Groups Projects
Commit ae3bb5d9 authored by Tobias Gross-Vogt's avatar Tobias Gross-Vogt
Browse files

new tags

parent f0c4ef29
No related branches found
No related tags found
No related merge requests found
Pipeline #191567 passed
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "1262fab1c713ea8767e23bf5b9729efc", "content-hash": "f9348007e76a9114cc35c21e3312c9b4",
"packages": [ "packages": [
{ {
"name": "adldap2/adldap2", "name": "adldap2/adldap2",
...@@ -347,15 +347,15 @@ ...@@ -347,15 +347,15 @@
}, },
{ {
"name": "dbp/relay-base-person-bundle", "name": "dbp/relay-base-person-bundle",
"version": "v0.2.1", "version": "v0.2.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-base-person-bundle", "url": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-base-person-bundle",
"reference": "b304723071831c2e5e01ffbd254106fc868e825f" "reference": "41add7e3408b9e3085c23ea770e07995480b9df3"
}, },
"require": { "require": {
"api-platform/core": "^2.6.3", "api-platform/core": "^2.6.3",
"dbp/relay-core-bundle": "^0.1.35", "dbp/relay-core-bundle": "^0.1.38",
"ext-json": "*", "ext-json": "*",
"guzzlehttp/guzzle": "^7.0", "guzzlehttp/guzzle": "^7.0",
"nelmio/cors-bundle": "^2.1.0", "nelmio/cors-bundle": "^2.1.0",
...@@ -392,15 +392,15 @@ ...@@ -392,15 +392,15 @@
"license": [ "license": [
"AGPL-3.0-or-later" "AGPL-3.0-or-later"
], ],
"time": "2022-05-02T07:24:36+00:00" "time": "2022-08-16T11:01:05+00:00"
}, },
{ {
"name": "dbp/relay-core-bundle", "name": "dbp/relay-core-bundle",
"version": "dev-main", "version": "v0.1.38",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-core-bundle", "url": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-core-bundle",
"reference": "71f304347b8e970ed8d56934243a455b0bd6cfb1" "reference": "d4686f81efdec53c082808c1c827c3d2912dabac"
}, },
"require": { "require": {
"api-platform/core": "^2.6.6", "api-platform/core": "^2.6.6",
...@@ -445,7 +445,6 @@ ...@@ -445,7 +445,6 @@
"symfony/phpunit-bridge": "^5.3", "symfony/phpunit-bridge": "^5.3",
"vimeo/psalm": "^4.4" "vimeo/psalm": "^4.4"
}, },
"default-branch": true,
"type": "symfony-bundle", "type": "symfony-bundle",
"extra": { "extra": {
"hooks": { "hooks": {
...@@ -464,7 +463,7 @@ ...@@ -464,7 +463,7 @@
"AGPL-3.0-or-later" "AGPL-3.0-or-later"
], ],
"description": "The core bundle of the Relay API gateway", "description": "The core bundle of the Relay API gateway",
"time": "2022-08-15T00:28:21+00:00" "time": "2022-08-16T08:35:41+00:00"
}, },
{ {
"name": "doctrine/annotations", "name": "doctrine/annotations",
...@@ -11187,18 +11186,9 @@ ...@@ -11187,18 +11186,9 @@
"time": "2015-12-17T08:42:14+00:00" "time": "2015-12-17T08:42:14+00:00"
} }
], ],
"aliases": [ "aliases": [],
{
"package": "dbp/relay-core-bundle",
"version": "dev-main",
"alias": "0.1.37",
"alias_normalized": "0.1.37.0"
}
],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": { "stability-flags": [],
"dbp/relay-core-bundle": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
...@@ -11210,5 +11200,5 @@ ...@@ -11210,5 +11200,5 @@
"platform-overrides": { "platform-overrides": {
"php": "7.3" "php": "7.3"
}, },
"plugin-api-version": "2.3.0" "plugin-api-version": "2.2.0"
} }
<?php
declare(strict_types=1);
namespace Dbp\Relay\BasePersonConnectorLdapBundle\Event;
use Dbp\Relay\CoreBundle\LocalData\LocalDataAwarePreEvent;
class PersonPreEvent extends LocalDataAwarePreEvent
{
public const NAME = 'dbp.relay.base_person_connector_ldap_bundle.person_event.pre';
}
...@@ -16,6 +16,7 @@ use Adldap\Models\User; ...@@ -16,6 +16,7 @@ use Adldap\Models\User;
use Adldap\Query\Builder; use Adldap\Query\Builder;
use Dbp\Relay\BasePersonBundle\Entity\Person; use Dbp\Relay\BasePersonBundle\Entity\Person;
use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonFromUserItemPostEvent; use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonFromUserItemPostEvent;
use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonPreEvent;
use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonUserItemPreEvent; use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonUserItemPreEvent;
use Dbp\Relay\CoreBundle\API\UserSessionInterface; use Dbp\Relay\CoreBundle\API\UserSessionInterface;
use Dbp\Relay\CoreBundle\Exception\ApiError; use Dbp\Relay\CoreBundle\Exception\ApiError;
...@@ -28,7 +29,6 @@ use Psr\Log\LoggerAwareTrait; ...@@ -28,7 +29,6 @@ use Psr\Log\LoggerAwareTrait;
use Symfony\Component\Cache\Psr16Cache; use Symfony\Component\Cache\Psr16Cache;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Contracts\Service\ServiceSubscriberInterface; use Symfony\Contracts\Service\ServiceSubscriberInterface;
class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
...@@ -194,6 +194,9 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface ...@@ -194,6 +194,9 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
return $builder; return $builder;
} }
/*
* @throws ApiError
*/
private function getPeopleUserItems(array $filters): array private function getPeopleUserItems(array $filters): array
{ {
try { try {
...@@ -215,16 +218,23 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface ...@@ -215,16 +218,23 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
return $search->sortBy($this->familyNameAttributeName, 'asc')->paginate($this->PAGESIZE)->getResults(); return $search->sortBy($this->familyNameAttributeName, 'asc')->paginate($this->PAGESIZE)->getResults();
} catch (\Adldap\Auth\BindException $e) { } catch (\Adldap\Auth\BindException $e) {
// There was an issue binding / connecting to the server. // There was an issue binding / connecting to the server.
throw new ApiError(Response::HTTP_BAD_GATEWAY, sprintf('People could not be loaded! Message: %s', CoreTools::filterErrorMessage($e->getMessage()))); throw ApiError::withDetails(Response::HTTP_BAD_GATEWAY, sprintf('People could not be loaded! Message: %s', CoreTools::filterErrorMessage($e->getMessage())));
} }
} }
public function getPersons(array $filters): array /*
* @throws ApiError
*/
public function getPersons(array $options): array
{ {
$this->eventDispatcher->onNewOperation($filters); $this->eventDispatcher->onNewOperation($options);
$preEvent = new PersonPreEvent();
$this->eventDispatcher->dispatch($preEvent, PersonPreEvent::NAME);
$options = array_merge($options, $preEvent->getQueryParameters());
$persons = []; $persons = [];
$items = $this->getPeopleUserItems($filters); $items = $this->getPeopleUserItems($options);
foreach ($items as $item) { foreach ($items as $item) {
$person = $this->personFromUserItem($item, false); $person = $this->personFromUserItem($item, false);
$persons[] = $person; $persons[] = $person;
...@@ -233,6 +243,9 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface ...@@ -233,6 +243,9 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
return $persons; return $persons;
} }
/*
* @throws ApiError
*/
private function getPersonUserItem(string $identifier): User private function getPersonUserItem(string $identifier): User
{ {
$preEvent = new PersonUserItemPreEvent($identifier); $preEvent = new PersonUserItemPreEvent($identifier);
...@@ -250,7 +263,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface ...@@ -250,7 +263,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
->first(); ->first();
if ($user === null) { if ($user === null) {
throw new NotFoundHttpException(sprintf("Person with id '%s' could not be found!", $identifier)); throw ApiError::withDetails(Response::HTTP_NOT_FOUND, sprintf("Person with id '%s' could not be found!", $identifier));
} }
assert($identifier === $user->getFirstAttribute($this->identifierAttributeName)); assert($identifier === $user->getFirstAttribute($this->identifierAttributeName));
...@@ -259,7 +272,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface ...@@ -259,7 +272,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
return $user; return $user;
} catch (\Adldap\Auth\BindException $e) { } catch (\Adldap\Auth\BindException $e) {
// There was an issue binding / connecting to the server. // There was an issue binding / connecting to the server.
throw new ApiError(Response::HTTP_BAD_GATEWAY, sprintf("Person with id '%s' could not be loaded! Message: %s", $identifier, CoreTools::filterErrorMessage($e->getMessage()))); throw ApiError::withDetails(Response::HTTP_BAD_GATEWAY, sprintf("Person with id '%s' could not be loaded! Message: %s", $identifier, CoreTools::filterErrorMessage($e->getMessage())));
} }
} }
...@@ -305,6 +318,9 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface ...@@ -305,6 +318,9 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
return $postEvent->getPerson(); return $postEvent->getPerson();
} }
/**
* @thorws ApiError
*/
public function getPerson(string $id, array $options = []): Person public function getPerson(string $id, array $options = []): Person
{ {
$this->eventDispatcher->onNewOperation($options); $this->eventDispatcher->onNewOperation($options);
...@@ -334,7 +350,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface ...@@ -334,7 +350,7 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
} }
/** /**
* @thorws NotFoundHttpException * @thorws ApiError
*/ */
private function getCurrentPersonCached(bool $checkLocalDataAttributes): ?Person private function getCurrentPersonCached(bool $checkLocalDataAttributes): ?Person
{ {
...@@ -371,7 +387,10 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface ...@@ -371,7 +387,10 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
try { try {
$user = $this->getPersonUserItem($currentIdentifier); $user = $this->getPersonUserItem($currentIdentifier);
$person = $this->personFromUserItem($user, true); $person = $this->personFromUserItem($user, true);
} catch (NotFoundHttpException $e) { } catch (ApiError $exc) {
if ($exc->getStatusCode() !== Response::HTTP_NOT_FOUND) {
throw $exc;
}
} }
$item->set($person); $item->set($person);
$item->expiresAfter($cacheTTL); $item->expiresAfter($cacheTTL);
...@@ -381,12 +400,15 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface ...@@ -381,12 +400,15 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
$this->currentPerson = $person; $this->currentPerson = $person;
if ($this->currentPerson === null) { if ($this->currentPerson === null) {
throw new NotFoundHttpException(); throw ApiError::withDetails(Response::HTTP_NOT_FOUND, sprintf("Current person with id '%s' could not be found!", $currentIdentifier));
} }
return $this->currentPerson; return $this->currentPerson;
} }
/**
* @thorws ApiError
*/
public function getCurrentPerson(): ?Person public function getCurrentPerson(): ?Person
{ {
return $this->getCurrentPersonCached(false); return $this->getCurrentPersonCached(false);
......
...@@ -6,6 +6,7 @@ namespace Dbp\Relay\BasePersonConnectorLdapBundle\Service; ...@@ -6,6 +6,7 @@ namespace Dbp\Relay\BasePersonConnectorLdapBundle\Service;
use Dbp\Relay\BasePersonBundle\API\PersonProviderInterface; use Dbp\Relay\BasePersonBundle\API\PersonProviderInterface;
use Dbp\Relay\BasePersonBundle\Entity\Person; use Dbp\Relay\BasePersonBundle\Entity\Person;
use Dbp\Relay\CoreBundle\Exception\ApiError;
class LDAPPersonProvider implements PersonProviderInterface class LDAPPersonProvider implements PersonProviderInterface
{ {
...@@ -18,15 +19,28 @@ class LDAPPersonProvider implements PersonProviderInterface ...@@ -18,15 +19,28 @@ class LDAPPersonProvider implements PersonProviderInterface
} }
/** /**
* @param array $filters $filters['search'] can be a string to search for people (e.g. part of the name) * @param array $options Available options:
* * Person::SEARCH_PARAMETER_NAME (whitespace separated list of search terms to perform a partial case-insensitive text search on person's full name)
* * LocalData::INCLUDE_PARAMETER_NAME
* * LocalData::QUERY_PARAMETER_NAME
*
* @throws ApiError
* *
* @return Person[] * @return Person[]
*/ */
public function getPersons(array $filters): array public function getPersons(array $options): array
{ {
return $this->ldapApi->getPersons($filters); return $this->ldapApi->getPersons($options);
} }
/**
* Throws an HTTP_NOT_FOUND exception if no person with the given ID can be found.
*
* @param array $options Available options:
* * LocalData::INCLUDE_PARAMETER_NAME
*
* @throws ApiError
*/
public function getPerson(string $id, array $options = []): Person public function getPerson(string $id, array $options = []): Person
{ {
return $this->ldapApi->getPerson($id, $options); return $this->ldapApi->getPerson($id, $options);
...@@ -34,7 +48,9 @@ class LDAPPersonProvider implements PersonProviderInterface ...@@ -34,7 +48,9 @@ class LDAPPersonProvider implements PersonProviderInterface
/** /**
* Returns the Person matching the current user. Or null if there is no associated person * Returns the Person matching the current user. Or null if there is no associated person
* like when the client is another server. * like when the client is another server. Throws an HTTP_NOT_FOUND exception if no person is found for the current user.
*
* @throws ApiError
*/ */
public function getCurrentPerson(): ?Person public function getCurrentPerson(): ?Person
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment