|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* For the full copyright and license information, please view |
|
5
|
|
|
* the LICENSE file that was distributed with this source code. |
|
6
|
|
|
* |
|
7
|
|
|
* @see https://github.com/ecphp |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace EcPhp\CasBundle\Security\Core\User; |
|
13
|
|
|
|
|
14
|
|
|
use EcPhp\CasLib\Introspection\Contract\IntrospectorInterface; |
|
15
|
|
|
use EcPhp\CasLib\Introspection\Contract\ServiceValidate; |
|
16
|
|
|
use InvalidArgumentException; |
|
17
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
18
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException; |
|
19
|
|
|
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; |
|
20
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
21
|
|
|
|
|
22
|
|
|
use function get_class; |
|
23
|
|
|
|
|
24
|
|
|
class CasUserProvider implements CasUserProviderInterface |
|
25
|
|
|
{ |
|
26
|
|
|
private IntrospectorInterface $introspector; |
|
27
|
|
|
|
|
28
|
5 |
|
public function __construct(IntrospectorInterface $introspector) |
|
29
|
|
|
{ |
|
30
|
5 |
|
$this->introspector = $introspector; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function loadUserByIdentifier($identifier): UserInterface |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
throw new UnsupportedUserException('Unsupported operation.'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
1 |
|
public function loadUserByResponse(ResponseInterface $response): CasUserInterface |
|
39
|
|
|
{ |
|
40
|
|
|
try { |
|
41
|
1 |
|
$introspect = $this->introspector->detect($response); |
|
42
|
|
|
} catch (InvalidArgumentException $exception) { |
|
43
|
|
|
throw new AuthenticationException($exception->getMessage()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
if ($introspect instanceof ServiceValidate) { |
|
47
|
1 |
|
return new CasUser($introspect->getCredentials()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
throw new AuthenticationException('Unable to load user from response.'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
public function loadUserByUsername(string $username): UserInterface |
|
54
|
|
|
{ |
|
55
|
1 |
|
throw new UnsupportedUserException(sprintf('Username "%s" does not exist.', $username)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
public function refreshUser(UserInterface $user): UserInterface |
|
59
|
|
|
{ |
|
60
|
1 |
|
if (!$user instanceof CasUserInterface) { |
|
61
|
1 |
|
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
return $user; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
public function supportsClass(string $class): bool |
|
68
|
|
|
{ |
|
69
|
1 |
|
return CasUser::class === $class; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.