Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"phpunit/phpunit": "^9.0 | ^10.0",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
"SimpleSAML\\Module\\drupalauth\\": "src/"
}
},
"autoload-dev": {
"classmap": ["src/", "tests/"]
},
Expand Down
13 changes: 8 additions & 5 deletions src/DrupalHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\DrupalKernel;
use Drupal\Core\Routing\RouteObjectInterface;
use SimpleSAML\Module\drupalauth\Event\SetAttributesEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;

Expand Down Expand Up @@ -46,7 +47,7 @@ public function getAttributes($drupaluser, $requested_attributes): array
$forbiddenAttributes = $this->forbiddenAttributes;

if (empty($requested_attributes)) {
return $this->getAllAttributes($drupaluser, $forbiddenAttributes);
$attributes = $this->getAllAttributes($drupaluser, $forbiddenAttributes);
} else {
foreach ($requested_attributes as $attribute) {
$field_name = $attribute['field_name'];
Expand Down Expand Up @@ -86,8 +87,10 @@ public function getAttributes($drupaluser, $requested_attributes): array
}
}
}

return $attributes;
$event = new SetAttributesEvent($this, $drupaluser, $requested_attributes, $attributes);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch($event, SetAttributesEvent::EVENT_NAME);
return $event->getAttributes();
}

/**
Expand Down Expand Up @@ -124,7 +127,7 @@ protected function getAllAttributes($drupaluser, $forbiddenAttributes): array
return $attributes;
}

protected function getPropertyName($attribute_definition)
public function getPropertyName($attribute_definition)
{
$property_name = 'value';
if (!empty($attribute_definition['field_property'])) {
Expand All @@ -134,7 +137,7 @@ protected function getPropertyName($attribute_definition)
return $property_name;
}

protected function getAttributeName($attribute_definition)
public function getAttributeName($attribute_definition)
{
if (!empty($attribute_definition['attribute_name'])) {
return $attribute_definition['attribute_name'];
Expand Down
71 changes: 71 additions & 0 deletions src/Event/SetAttributesEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace SimpleSAML\Module\drupalauth\Event;

use Drupal\Component\EventDispatcher\Event;
use Drupal\user\UserInterface;
use SimpleSAML\Module\drupalauth\DrupalHelper;

/**
* Event that is fired after SAML attributes are set
*/
class SetAttributesEvent extends Event
{
public const EVENT_NAME = 'simplesamlphp_drupalauth_set_attributes';


/**
* Contstruct the event.
*
* @param \SimpleSAML\Module\drupalauth\DrupalHelper $drupalHelper
* @param \Drupal\user\UserInterface $user
* @param array $attributes
*/
public function __construct(
protected readonly DrupalHelper $drupalHelper,
protected readonly UserInterface $user,
protected readonly array $requestedAttributes,
protected array $attributes
) {
}

/**
* Get the drupal helper.
*/
public function getDrupalHelper(): DrupalHelper
{
return $this->drupalHelper;
}

/**
* Get the requested attributes.
*/
public function getRequestedAttributes(): array
{
return $this->requestedAttributes;
}

/**
* Get user who logged in.
*/
public function getUser(): UserInterface
{
return $this->user;
}

/**
* Get the attributes set.
*/
public function getAttributes(): array
{
return $this->attributes;
}

/**
* Set the attributes.
*/
public function setAttributes(array $attributes)
{
$this->attributes = $attributes;
}
}