diff --git a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php index 07ed888..151d379 100644 --- a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php +++ b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php @@ -9,6 +9,48 @@ class EuLoginUserSpec extends ObjectBehavior { + public function it_can_get_groups_when_no_groups_are_available() + { + $data = [ + 'user' => 'user', + 'departmentNumber' => 'departmentNumber', + 'email' => 'email', + 'employeeNumber' => 'employeeNumber', + 'employeeType' => 'employeeType', + 'firstName' => 'firstName', + 'lastName' => 'lastName', + 'domain' => 'domain', + 'domainUsername' => 'domainUsername', + 'telephoneNumber' => 'telephoneNumber', + 'locale' => 'locale', + 'assuranceLevel' => 'assuranceLevel', + 'uid' => 'uid', + 'orgId' => 'orgId', + 'teleworkingPriority' => 'teleworkingPriority', + 'strengths' => [ + 'bar', + ], + 'authenticationFactors' => [ + 'foobar', + ], + 'loginDate' => 'loginDate', + 'sso' => 'sso', + 'ticketType' => 'ticketType', + 'proxyGrantingProtocol' => 'proxyGrantingProtocol', + 'proxyGrantingTicket' => 'proxyGrantingTicket', + 'proxies' => [ + 'proxy1', + ], + ]; + + $this + ->beConstructedWith($data); + + $this + ->getGroups() + ->shouldReturn([]); + } + public function it_can_get_specific_attribute() { $this diff --git a/src/Security/Core/User/EuLoginUser.php b/src/Security/Core/User/EuLoginUser.php index 6354407..d6e6c52 100644 --- a/src/Security/Core/User/EuLoginUser.php +++ b/src/Security/Core/User/EuLoginUser.php @@ -6,6 +6,9 @@ use EcPhp\CasBundle\Security\Core\User\CasUser; +use function array_key_exists; +use function is_array; + /** * Class EuLoginUser. */ @@ -194,7 +197,7 @@ public function getRoles() $default = ['ROLE_CAS_AUTHENTICATED']; if ([] !== $roles = $this->getGroups()) { - if (isset($roles['group'])) { + if (true === array_key_exists('group', $roles) && true === is_array($roles['group'])) { return array_merge($roles['group'], $default); } }