Skip to content

Commit c647ee2

Browse files
committed
Reroll of drupalauth#95
DrupalHelper.php has shifted location.
1 parent 57d623a commit c647ee2

File tree

3 files changed

+84
-4
lines changed

3 files changed

+84
-4
lines changed

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
"phpunit/phpunit": "^5|^6|^7|^8|^9",
3030
"squizlabs/php_codesniffer": "^2.0.0|^3.0.0"
3131
},
32+
"autoload": {
33+
"psr-4": {
34+
"SimpleSAML\\Module\\drupalauth\\": "src/"
35+
}
36+
},
3237
"autoload-dev": {
3338
"classmap": ["lib/", "tests/lib/"]
3439
},

lib/DrupalHelper.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace SimpleSAML\Module\drupalauth;
55

66
use Drupal\Core\DrupalKernel;
7+
use SimpleSAML\Module\drupalauth\Event\SetAttributesEvent;
78
use Symfony\Component\HttpFoundation\Request;
89

910
class DrupalHelper
@@ -40,7 +41,7 @@ public function getAttributes($drupaluser, $requested_attributes)
4041
$forbiddenAttributes = $this->forbiddenAttributes;
4142

4243
if (empty($requested_attributes)) {
43-
return $this->getAllAttributes($drupaluser, $forbiddenAttributes);
44+
$attributes = $this->getAllAttributes($drupaluser, $forbiddenAttributes);
4445
} else {
4546
foreach ($requested_attributes as $attribute) {
4647
$field_name = $attribute['field_name'];
@@ -80,7 +81,10 @@ public function getAttributes($drupaluser, $requested_attributes)
8081
}
8182
}
8283
}
83-
84+
$event = new SetAttributesEvent($this, $drupaluser, $requested_attributes, $attributes);
85+
$event_dispatcher = \Drupal::service('event_dispatcher');
86+
$event_dispatcher->dispatch($event, SetAttributesEvent::EVENT_NAME);
87+
$attributes = $event->getAttributes();
8488
return $attributes;
8589
}
8690

@@ -118,7 +122,7 @@ protected function getAllAttributes($drupaluser, $forbiddenAttributes)
118122
return $attributes;
119123
}
120124

121-
protected function getPropertyName($attribute_definition)
125+
public function getPropertyName($attribute_definition)
122126
{
123127
$property_name = 'value';
124128
if (!empty($attribute_definition['field_property'])) {
@@ -128,7 +132,7 @@ protected function getPropertyName($attribute_definition)
128132
return $property_name;
129133
}
130134

131-
protected function getAttributeName($attribute_definition)
135+
public function getAttributeName($attribute_definition)
132136
{
133137
if (!empty($attribute_definition['attribute_name'])) {
134138
return $attribute_definition['attribute_name'];

src/Event/SetAttributesEvent.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace SimpleSAML\Module\drupalauth\Event;
4+
5+
use Drupal\Component\EventDispatcher\Event;
6+
use Drupal\user\UserInterface;
7+
use SimpleSAML\Module\drupalauth\DrupalHelper;
8+
9+
/**
10+
* Event that is fired after SAML attributes are set
11+
*/
12+
class SetAttributesEvent extends Event
13+
{
14+
public const EVENT_NAME = 'simplesamlphp_drupalauth_set_attributes';
15+
16+
17+
/**
18+
* Contstruct the event.
19+
*
20+
* @param \SimpleSAML\Module\drupalauth\DrupalHelper $drupalHelper
21+
* @param \Drupal\user\UserInterface $user
22+
* @param array $attributes
23+
*/
24+
public function __construct(
25+
protected readonly DrupalHelper $drupalHelper,
26+
protected readonly UserInterface $user,
27+
protected readonly array $requestedAttributes,
28+
protected array $attributes
29+
) {
30+
}
31+
32+
/**
33+
* Get the drupal helper.
34+
*/
35+
public function getDrupalHelper(): DrupalHelper
36+
{
37+
return $this->drupalHelper;
38+
}
39+
40+
/**
41+
* Get the requested attributes.
42+
*/
43+
public function getRequestedAttributes(): array
44+
{
45+
return $this->requestedAttributes;
46+
}
47+
48+
/**
49+
* Get user who logged in.
50+
*/
51+
public function getUser(): UserInterface
52+
{
53+
return $this->user;
54+
}
55+
56+
/**
57+
* Get the attributes set.
58+
*/
59+
public function getAttributes(): array
60+
{
61+
return $this->attributes;
62+
}
63+
64+
/**
65+
* Set the attributes.
66+
*/
67+
public function setAttributes(array $attributes)
68+
{
69+
$this->attributes = $attributes;
70+
}
71+
}

0 commit comments

Comments
 (0)