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
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
"require": {
"php": "^8.0",
"simplesamlphp/simplesamlphp": "^2.1",
"simplesamlphp/composer-module-installer": "~1.0"
"simplesamlphp/composer-module-installer": "~1.7"
},
"require-dev": {
"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 @@
$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 @@
}
}
}

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 @@
return $attributes;
}

protected function getPropertyName($attribute_definition)
public function getPropertyName($attribute_definition)

Check warning on line 130 in src/DrupalHelper.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename function "getPropertyName" to match the regular expression ^[a-z][a-z0-9_]*$.

See more on https://sonarcloud.io/project/issues?id=drupalauth_simplesamlphp-module-drupalauth&issues=AZ8_rDADoF4Py3o26907&open=AZ8_rDADoF4Py3o26907&pullRequest=103
{
$property_name = 'value';
if (!empty($attribute_definition['field_property'])) {
Expand All @@ -134,7 +137,7 @@
return $property_name;
}

protected function getAttributeName($attribute_definition)
public function getAttributeName($attribute_definition)

Check warning on line 140 in src/DrupalHelper.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename function "getAttributeName" to match the regular expression ^[a-z][a-z0-9_]*$.

See more on https://sonarcloud.io/project/issues?id=drupalauth_simplesamlphp-module-drupalauth&issues=AZ8_rDADoF4Py3o26908&open=AZ8_rDADoF4Py3o26908&pullRequest=103
{
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;
}
}