diff --git a/src/Symfony/Component/Security/Http/AccessToken/Cas/Cas2Handler.php b/src/Symfony/Component/Security/Http/AccessToken/Cas/Cas2Handler.php
index 61bcdbeb9fe9d..6223eab75baf3 100644
--- a/src/Symfony/Component/Security/Http/AccessToken/Cas/Cas2Handler.php
+++ b/src/Symfony/Component/Security/Http/AccessToken/Cas/Cas2Handler.php
@@ -50,7 +50,23 @@ public function getUserBadgeFrom(string $accessToken): UserBadge
$xml = new \SimpleXMLElement($response->getContent(), 0, false, $this->prefix, true);
if (isset($xml->authenticationSuccess)) {
- return new UserBadge((string) $xml->authenticationSuccess->user);
+ $userIdentifier = (string) $xml->authenticationSuccess->user;
+ $attributes = [];
+ if (isset($xml->authenticationSuccess->attributes)) {
+ // Extract all attributes without using namespace
+ foreach ($xml->authenticationSuccess->attributes->children($this->prefix, true) as $child) {
+ $key = $child->getName();
+ if (isset($attributes[$key])) {
+ if (!\is_array($attributes[$key])) {
+ $attributes[$key] = [$attributes[$key]];
+ }
+ $attributes[$key][] = (string) $child;
+ } else {
+ $attributes[$key] = (string) $child;
+ }
+ }
+ }
+ return new UserBadge($userIdentifier, null, $attributes);
}
if (isset($xml->authenticationFailure)) {
diff --git a/src/Symfony/Component/Security/Http/Tests/AccessToken/Cas/Cas2HandlerTest.php b/src/Symfony/Component/Security/Http/Tests/AccessToken/Cas/Cas2HandlerTest.php
index 728b7ca529a79..e6d024201bc80 100644
--- a/src/Symfony/Component/Security/Http/Tests/AccessToken/Cas/Cas2HandlerTest.php
+++ b/src/Symfony/Component/Security/Http/Tests/AccessToken/Cas/Cas2HandlerTest.php
@@ -29,6 +29,10 @@ public function testWithValidTicket()