|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Security; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Control\HTTPRequest; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Core authentication handler / store |
|
9
|
|
|
*/ |
|
10
|
|
|
class RequestAuthenticationHandler implements AuthenticationHandler |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var AuthenticationHandler[] |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $handlers = []; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* This method currently uses a fallback as loading the handlers via YML has proven unstable |
|
19
|
|
|
* |
|
20
|
|
|
* @return AuthenticationHandler[] |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function getHandlers() |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->handlers; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Set an associative array of handlers |
|
29
|
|
|
* |
|
30
|
|
|
* @param AuthenticationHandler[] $handlers |
|
31
|
|
|
* @return $this |
|
32
|
|
|
*/ |
|
33
|
|
|
public function setHandlers(array $handlers) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->handlers = $handlers; |
|
36
|
|
|
return $this; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function authenticateRequest(HTTPRequest $request) |
|
40
|
|
|
{ |
|
41
|
|
|
/** @var AuthenticationHandler $handler */ |
|
42
|
|
|
foreach ($this->getHandlers() as $name => $handler) { |
|
43
|
|
|
// in order to add cookies, etc |
|
44
|
|
|
$member = $handler->authenticateRequest($request); |
|
|
|
|
|
|
45
|
|
|
if ($member) { |
|
46
|
|
|
Security::setCurrentUser($member); |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
/** |
|
52
|
|
|
* Log into the identity-store handlers attached to this request filter |
|
53
|
|
|
* |
|
54
|
|
|
* @param Member $member |
|
55
|
|
|
* @param bool $persistent |
|
56
|
|
|
* @param HTTPRequest $request |
|
57
|
|
|
*/ |
|
58
|
|
|
public function logIn(Member $member, $persistent = false, HTTPRequest $request = null) |
|
59
|
|
|
{ |
|
60
|
|
|
$member->beforeMemberLoggedIn(); |
|
61
|
|
|
|
|
62
|
|
|
foreach ($this->getHandlers() as $handler) { |
|
63
|
|
|
$handler->logIn($member, $persistent, $request); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
Security::setCurrentUser($member); |
|
67
|
|
|
$member->afterMemberLoggedIn(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Log out of all the identity-store handlers attached to this request filter |
|
72
|
|
|
* |
|
73
|
|
|
* @param HTTPRequest $request |
|
74
|
|
|
*/ |
|
75
|
|
|
public function logOut(HTTPRequest $request = null) |
|
76
|
|
|
{ |
|
77
|
|
|
foreach ($this->getHandlers() as $handler) { |
|
78
|
|
|
$handler->logOut($request); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
Security::setCurrentUser(null); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.