Skip to content

Commit

Permalink
fix: get rid of XML data handling in favor of JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 15, 2022
1 parent 7d3bc41 commit c4edf50
Showing 1 changed file with 5 additions and 83 deletions.
88 changes: 5 additions & 83 deletions src/Security/Core/User/EuLoginUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use EcPhp\CasBundle\Security\Core\User\CasUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;

use function array_key_exists;

final class EuLoginUser implements EuLoginUserInterface
{
private CasUserInterface $user;
Expand Down Expand Up @@ -52,35 +50,7 @@ public function getAttribute(string $key, $default = null)

public function getAttributes(): array
{
$attributes = $this->user->getAttributes();

/** @Todo Ugly. Refactor this when JSON format will be available. */
$propertyToMangle = [
['extendedAttributes', 'extendedAttribute'],
['groups', 'group'],
['strengths', 'strength'],
['authenticationFactors', 'authenticationFactor'],
];

foreach ($propertyToMangle as [$parent, $child]) {
if (!array_key_exists($parent, $attributes)) {
continue;
}

if (!array_key_exists($child, $attributes[$parent])) {
continue;
}

$attributes[$parent][$child] = (array) $attributes[$parent][$child];

if (array_key_exists(0, $attributes[$parent][$child])) {
continue;
}

$attributes[$parent][$child] = [$attributes[$parent][$child]];
}

return $attributes;
return $this->user->getAttributes();
}

public function getAuthenticationFactors(): array
Expand Down Expand Up @@ -120,29 +90,7 @@ public function getEmployeeType(): ?string

public function getExtendedAttributes(): array
{
$attributes = $this->getAttributes();

if (!array_key_exists('extendedAttributes', $attributes)) {
return [];
}

$extendedAttributes = $attributes['extendedAttributes'];

if (!array_key_exists('extendedAttribute', $extendedAttributes)) {
return [];
}

$extendedAttributes = $attributes['extendedAttributes']['extendedAttribute'];

return array_reduce(
$extendedAttributes,
static function (array $carry, array $item): array {
$carry[$item['@attributes']['name']] = $item['attributeValue'];

return $carry;
},
[]
);
return $this->getAttributes()['extendedAttributes'] ?? [];
}

public function getFirstName(): ?string
Expand All @@ -152,19 +100,7 @@ public function getFirstName(): ?string

public function getGroups(): array
{
$attributes = $this->getAttributes();

if (!array_key_exists('groups', $attributes)) {
return [];
}

$groups = $attributes['groups'];

if (!array_key_exists('group', $groups)) {
return [];
}

return $groups['group'];
return $this->getAttributes()['groups'] ?? [];
}

public function getLastName(): ?string
Expand Down Expand Up @@ -204,9 +140,7 @@ public function getProxyGrantingProtocol(): ?string

public function getRoles(): array
{
$default = ['ROLE_CAS_AUTHENTICATED'];

return array_merge($this->getGroups(), $default);
return array_merge($this->getGroups(), ['ROLE_CAS_AUTHENTICATED']);
}

public function getSalt()
Expand All @@ -221,19 +155,7 @@ public function getSso(): ?string

public function getStrengths(): array
{
$attributes = $this->getAttributes();

if (!array_key_exists('strengths', $attributes)) {
return [];
}

$strengths = $attributes['strengths'];

if (!array_key_exists('strength', $strengths)) {
return [];
}

return (array) $strengths['strength'];
return $this->getAttributes()['strengths'] ?? [];
}

public function getTelephoneNumber(): ?string
Expand Down

0 comments on commit c4edf50

Please sign in to comment.