From a776dce44cdfbd623514ce0788a6a14fb65028e5 Mon Sep 17 00:00:00 2001 From: Fred Date: Thu, 12 Nov 2020 14:07:24 +0100 Subject: [PATCH] Get attributes and pass them to the provider if implements CasUserProviderInterface --- Security/CasAuthenticator.php | 13 +++++++++-- Security/User/CasUserProviderInterface.php | 25 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 Security/User/CasUserProviderInterface.php diff --git a/Security/CasAuthenticator.php b/Security/CasAuthenticator.php index 2734d96..a497c58 100644 --- a/Security/CasAuthenticator.php +++ b/Security/CasAuthenticator.php @@ -4,6 +4,7 @@ use GuzzleHttp\Client; use PRayno\CasAuthBundle\Event\CASAuthenticationFailureEvent; +use PRayno\CasAuthBundle\Security\User\CasUserProviderInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -83,12 +84,20 @@ public function getCredentials(Request $request) * Calls the UserProvider providing a valid User * @param array $credentials * @param UserProviderInterface $userProvider - * @return bool + * @return UserInterface|null */ public function getUser($credentials, UserProviderInterface $userProvider) { if (isset($credentials[$this->username_attribute])) { - return $userProvider->loadUserByUsername($credentials[$this->username_attribute]); + if($userProvider instanceof CasUserProviderInterface) + { + $attributes = (isset($credentials['attributes']))? (array)$credentials['attributes'] : []; + return $userProvider->loadUserByUsernameAndAttributes($credentials[$this->username_attribute], $attributes); + } + else + { + return $userProvider->loadUserByUsername($credentials[$this->username_attribute]); + } } else { return null; } diff --git a/Security/User/CasUserProviderInterface.php b/Security/User/CasUserProviderInterface.php new file mode 100644 index 0000000..b0abf99 --- /dev/null +++ b/Security/User/CasUserProviderInterface.php @@ -0,0 +1,25 @@ +