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

abstractgetattributesubscribe; re-allowing to update values of existing user attributes

parent 82c367b2
No related branches found
No related tags found
No related merge requests found
Pipeline #212870 passed
......@@ -112,7 +112,6 @@ class AuthorizationDataMuxer
throw new AuthorizationException(sprintf('attribute \'%s\' undefined', $attributeName), AuthorizationException::ATTRIBUTE_UNDEFINED);
}
$wasFound = false;
$value = $defaultValue;
foreach ($this->authorizationDataProviders as $authorizationDataProvider) {
$availableAttributes = $this->getProviderAvailableAttributes($authorizationDataProvider);
......@@ -130,7 +129,7 @@ class AuthorizationDataMuxer
$event = new GetAttributeEvent($this, $attributeName, $value, $userIdentifier);
$event->setAttributeValue($value);
// Avoid endless recursions by only emitting an event for each attribtue only once
// Avoid endless recursions by only emitting an event for each attribute only once
if (!in_array($attributeName, $this->attributeStack, true)) {
array_push($this->attributeStack, $attributeName);
$this->eventDispatcher->dispatch($event);
......
......@@ -23,18 +23,19 @@ abstract class AbstractGetAttributeSubscriber implements EventSubscriberInterfac
public function onGetAvailableAttributes(GetAvailableAttributesEvent $event)
{
$event->addAttributes($this->getAvailableAttributes());
$event->addAttributes($this->getNewAttributes());
}
public function onGetAttributeEvent(GetAttributeEvent $event)
{
try {
$this->event = $event;
$attributeName = $event->getAttributeName();
if (in_array($attributeName, $this->getAvailableAttributes(), true)) {
$event->setAttributeValue($this->getUserAttributeValue($event->getUserIdentifier(), $attributeName, $event->getAttributeValue()));
}
$event->setAttributeValue(in_array($attributeName, $this->getNewAttributes(), true) ?
$this->getNewAttributeValue($event->getUserIdentifier(), $attributeName, $event->getAttributeValue()) :
$this->updateExistingAttributeValue($event->getUserIdentifier(), $attributeName, $event->getAttributeValue())
);
} finally {
$this->event = null;
}
......@@ -50,15 +51,25 @@ abstract class AbstractGetAttributeSubscriber implements EventSubscriberInterfac
return $this->event->getAttribute($attributeName, $defaultValue);
}
/**
* @param mixed|null $attributeValue The current attribute value
*
* @return mixed|null The updated attribute value
*/
protected function updateExistingAttributeValue(?string $userIdentifier, string $attributeName, $attributeValue)
{
return $attributeValue;
}
/*
* @return string[]
* @return string[] The array of new attribute names that this subscriber provides
*/
abstract protected function getAvailableAttributes(): array;
abstract protected function getNewAttributes(): array;
/**
* @param mixed|null $attributeValue
* @param mixed|null $defaultValue the default value if provided explicitly in the authorization expression, else null
*
* @return mixed|null
* @return mixed|null the value for the new attribute with the given name for the given user
*/
abstract protected function getUserAttributeValue(?string $userIdentifier, string $attributeName, $attributeValue);
abstract protected function getNewAttributeValue(?string $userIdentifier, string $attributeName, $defaultValue);
  • Reiter, Christoph :snake: @987FCF504483CBC8 ·
    Owner

    $defaultValue doesn't really work here, since we can only decide if it should be used after all events handlers are done, and this might not be the only one i.e. the event handler must never see the default value.

    Edited by Reiter, Christoph
  • Please register or sign in to reply
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment