Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Security/CasAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
25 changes: 25 additions & 0 deletions Security/User/CasUserProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php


namespace PRayno\CasAuthBundle\Security\User;


use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;

/**
* Interface CasUserProviderInterface
* @package Security\User
*/
interface CasUserProviderInterface extends UserProviderInterface
{
/**
* @param string $username
* @param array $attributes
* @return UserInterface
* @throws UsernameNotFoundException if the user is not found
*/
public function loadUserByUsernameAndAttributes(string $username, array $attributes);

}