From 6451917bf366b6a944d31c97066333e070ee1d9c Mon Sep 17 00:00:00 2001 From: Tobias Gross-Vogt <tgros@tugraz.at> Date: Wed, 9 Nov 2022 11:34:41 +0100 Subject: [PATCH] proxyapi update; rename keycloak -> oidc --- src/Http/ApiConnection.php | 8 ++-- .../AbstractProxyDataEventSubscriber.php | 4 +- src/ProxyApi/ProxyApi.php | 2 - src/ProxyApi/ProxyDataEvent.php | 18 ++++----- src/ProxyApi/ProxyDataEventSubscriber.php | 38 +++++++++++++------ src/Resources/config/services.yaml | 4 ++ 6 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/Http/ApiConnection.php b/src/Http/ApiConnection.php index 2bf5fbd..fb41c14 100644 --- a/src/Http/ApiConnection.php +++ b/src/Http/ApiConnection.php @@ -13,8 +13,8 @@ class ApiConnection { public const API_URL_CONFIG_PARAMETER = 'api_url'; - public const KEYCLOAK_SERVER_URL_CONFIG_PARAMETER = 'keycloak_server_url'; - public const KEYCLOAK_REALM_CONFIG_PARAMETER = 'keycloak_realm'; + public const OIDC_SERVER_URL_CONFIG_PARAMETER = 'oidc_server_url'; + public const OIDC_REALM_CONFIG_PARAMETER = 'oidc_realm'; public const CLIENT_ID_CONFIG_PARAMETER = 'client_id'; public const CLIENT_SECRET_CONFIG_PARAMETER = 'client_secret'; @@ -111,8 +111,8 @@ class ApiConnection private function getAccessToken(): string { if ($this->accessToken === null) { - $idServerUrl = $this->config[self::KEYCLOAK_SERVER_URL_CONFIG_PARAMETER]; - $idServerRealm = $this->config[self::KEYCLOAK_REALM_CONFIG_PARAMETER]; + $idServerUrl = $this->config[self::OIDC_SERVER_URL_CONFIG_PARAMETER]; + $idServerRealm = $this->config[self::OIDC_REALM_CONFIG_PARAMETER]; $clientId = $this->config[self::CLIENT_ID_CONFIG_PARAMETER]; $clientSecret = $this->config[self::CLIENT_SECRET_CONFIG_PARAMETER]; diff --git a/src/ProxyApi/AbstractProxyDataEventSubscriber.php b/src/ProxyApi/AbstractProxyDataEventSubscriber.php index 02128fd..062ae20 100644 --- a/src/ProxyApi/AbstractProxyDataEventSubscriber.php +++ b/src/ProxyApi/AbstractProxyDataEventSubscriber.php @@ -15,7 +15,7 @@ abstract class AbstractProxyDataEventSubscriber implements EventSubscriberInterf public static function getSubscribedEvents(): array { return [ - ProxyApi::PROXY_DATA_EVENT_NAME.static::NAMESPACE => 'onProxyDataEvent', + ProxyDataEvent::NAME.'.'.static::NAMESPACE => 'onProxyDataEvent', ]; } @@ -24,7 +24,7 @@ abstract class AbstractProxyDataEventSubscriber implements EventSubscriberInterf */ public function onProxyDataEvent(ProxyDataEvent $event): void { - $event->setHandled(); + $event->acknowledge(); $proxyData = $event->getProxyData(); $functionName = $proxyData->getFunctionName(); $arguments = $proxyData->getArguments(); diff --git a/src/ProxyApi/ProxyApi.php b/src/ProxyApi/ProxyApi.php index 1e4000f..6f958cd 100644 --- a/src/ProxyApi/ProxyApi.php +++ b/src/ProxyApi/ProxyApi.php @@ -6,8 +6,6 @@ namespace Dbp\Relay\CoreBundle\ProxyApi; class ProxyApi { - public const PROXY_DATA_EVENT_NAME = ''; - public const PROXY_DATA_RETURN_VALUE_KEY = 'data'; public const PROXY_DATA_ERRORS_KEY = 'errors'; } diff --git a/src/ProxyApi/ProxyDataEvent.php b/src/ProxyApi/ProxyDataEvent.php index 8db1e25..637c9a2 100644 --- a/src/ProxyApi/ProxyDataEvent.php +++ b/src/ProxyApi/ProxyDataEvent.php @@ -8,18 +8,18 @@ use Symfony\Contracts\EventDispatcher\Event; class ProxyDataEvent extends Event { - public const NAME = 'dbp.relay.proxy_bundle.proxy_data'; + public const NAME = 'dbp.relay.core_bundle.proxy_data'; /** @var ProxyDataInterface */ private $proxyData; /** @var bool */ - private $wasHandled; + private $wasAcknowledged; public function __construct(ProxyDataInterface $proxyData) { $this->proxyData = $proxyData; - $this->wasHandled = false; + $this->wasAcknowledged = false; } public function getProxyData(): ProxyDataInterface @@ -28,18 +28,18 @@ class ProxyDataEvent extends Event } /** - * Indicate, that the event was handled, e.g. there was an event subscriber for the requested proxy data namespace. + * Acknowledge the event, i.e. tell that there was an event subscriber responsible for the requested proxy data namespace. */ - public function setHandled(): void + public function acknowledge(): void { - $this->wasHandled = true; + $this->wasAcknowledged = true; } /** - * True, if the event was handled, e.g. there was an event subscriber for the requested proxy data namespace, false otherwise. + * True, if the event was acknowledged, e.g. there was an event subscriber responsible for the requested proxy data namespace, false otherwise. */ - public function wasHandled(): bool + public function wasAcknowledged(): bool { - return $this->wasHandled; + return $this->wasAcknowledged; } } diff --git a/src/ProxyApi/ProxyDataEventSubscriber.php b/src/ProxyApi/ProxyDataEventSubscriber.php index 6c56975..04c6603 100644 --- a/src/ProxyApi/ProxyDataEventSubscriber.php +++ b/src/ProxyApi/ProxyDataEventSubscriber.php @@ -22,11 +22,22 @@ class ProxyDataEventSubscriber extends AbstractProxyDataEventSubscriber */ private $provider; + /** @var bool */ + private static $isCurrentlyActive = false; + public function __construct(AuthorizationDataProviderProvider $provider) { $this->provider = $provider; } + /** + * Indicates, that the event subscriber is currently busy handling a proxy data event. + */ + public static function isCurrentlyActive(): bool + { + return self::$isCurrentlyActive; + } + protected function isFunctionDefined(string $functionName): bool { return @@ -46,18 +57,23 @@ class ProxyDataEventSubscriber extends AbstractProxyDataEventSubscriber */ protected function callFunction(string $functionName, array $arguments): ?array { - $returnValue = null; - - switch ($functionName) { - case self::GET_AVAILABLE_ATTRIBUTES_FUNCTION_NAME: - $returnValue = $this->getAvailableAttributes(); - break; - case self::GET_USER_ATTRIBUTES_FUNCTION_NAME: - $returnValue = $this->getUserAttributes($arguments[self::USER_ID_PARAMETER_NAME]); - break; + try { + self::$isCurrentlyActive = true; + $returnValue = null; + + switch ($functionName) { + case self::GET_AVAILABLE_ATTRIBUTES_FUNCTION_NAME: + $returnValue = $this->getAvailableAttributes(); + break; + case self::GET_USER_ATTRIBUTES_FUNCTION_NAME: + $returnValue = $this->getUserAttributes($arguments[self::USER_ID_PARAMETER_NAME]); + break; + } + + return $returnValue; + } finally { + self::$isCurrentlyActive = false; } - - return $returnValue; } private function getAvailableAttributes(): array diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 9a56354..714322c 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -93,3 +93,7 @@ services: Dbp\Relay\CoreBundle\Authorization\DebugCommand: autowire: true autoconfigure: true + + Dbp\Relay\CoreBundle\ProxyApi\ProxyDataEventSubscriber: + autowire: true + autoconfigure: true -- GitLab