-
-
Notifications
You must be signed in to change notification settings - Fork 187
/
TestingProvider.php
103 lines (93 loc) · 2.46 KB
/
TestingProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace Neos\Flow\Security\Authentication\Provider;
/*
* This file is part of the Neos.Flow package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Security\Account;
use Neos\Flow\Security\Authentication\Token\TestingToken;
use Neos\Flow\Security\Authentication\TokenInterface;
/**
* A singleton authentication provider for functional tests with
* mockable authentication.
*/
class TestingProvider extends AbstractProvider
{
/**
* @var Account
*/
protected $account;
/**
* @var integer
*/
protected $authenticationStatus = TokenInterface::NO_CREDENTIALS_GIVEN;
/**
* Returns the class names of the tokens this provider can authenticate.
*
* @return array
*/
public function getTokenClassNames()
{
return [TestingToken::class];
}
/**
* Sets isAuthenticated to true for all tokens.
*
* @param TokenInterface $authenticationToken The token to be authenticated
* @return void
*/
public function authenticate(TokenInterface $authenticationToken)
{
$authenticationToken->setAuthenticationStatus($this->authenticationStatus);
if ($this->authenticationStatus === TokenInterface::AUTHENTICATION_SUCCESSFUL) {
$authenticationToken->setAccount($this->account);
} else {
$authenticationToken->setAccount(null);
}
}
/**
* Set the account that will be authenticated
*
* @param Account $account
* @return void
*/
public function setAccount($account)
{
$this->account = $account;
}
/**
* Set the authentication status for authentication
*
* @param integer $authenticationStatus
* @return void
*/
public function setAuthenticationStatus($authenticationStatus)
{
$this->authenticationStatus = $authenticationStatus;
}
/**
* Set the provider name
*
* @param string $name
* @return void
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Reset the authentication status and account
*
* @return void
*/
public function reset()
{
$this->account = null;
$this->authenticationStatus = TokenInterface::NO_CREDENTIALS_GIVEN;
}
}