|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of Symnedi. |
|
7
|
|
|
* Copyright (c) 2014 Tomas Votruba (http://tomasvotruba.cz) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Symnedi\Security\Core\Authentication\Token; |
|
11
|
|
|
|
|
12
|
|
|
use Nette\Security\Identity; |
|
13
|
|
|
use Nette\Security\IIdentity; |
|
14
|
|
|
use Nette\Security\User; |
|
15
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
|
16
|
|
|
use Symnedi\Security\Exception\NotImplementedException; |
|
17
|
|
|
|
|
18
|
|
|
final class NetteTokenAdapter implements TokenInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var User |
|
22
|
|
|
*/ |
|
23
|
|
|
private $user; |
|
24
|
|
|
|
|
25
|
1 |
|
public function serialize() |
|
26
|
|
|
{ |
|
27
|
1 |
|
throw new NotImplementedException(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param string $serialized |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function unserialize($serialized) |
|
34
|
|
|
{ |
|
35
|
1 |
|
throw new NotImplementedException(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
1 |
|
public function __toString() |
|
39
|
|
|
{ |
|
40
|
1 |
|
throw new NotImplementedException(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
1 |
|
public function getRoles() : array |
|
44
|
|
|
{ |
|
45
|
1 |
|
return $this->user->getRoles(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return IIdentity|null |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function getCredentials() |
|
52
|
|
|
{ |
|
53
|
1 |
|
return $this->user->getIdentity(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return User |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function getUser() |
|
60
|
|
|
{ |
|
61
|
1 |
|
return $this->user; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param User $user |
|
66
|
|
|
*/ |
|
67
|
15 |
|
public function setUser($user) |
|
68
|
|
|
{ |
|
69
|
15 |
|
$this->user = $user; |
|
70
|
15 |
|
} |
|
71
|
|
|
|
|
72
|
1 |
|
public function getUsername() : bool |
|
73
|
|
|
{ |
|
74
|
1 |
|
return false; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
2 |
|
public function isAuthenticated() : bool |
|
78
|
|
|
{ |
|
79
|
2 |
|
return $this->user->isLoggedIn(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param bool $isAuthenticated |
|
84
|
|
|
*/ |
|
85
|
1 |
|
public function setAuthenticated($isAuthenticated) |
|
86
|
|
|
{ |
|
87
|
1 |
|
$this->user->getStorage()->setAuthenticated($isAuthenticated); |
|
88
|
1 |
|
} |
|
89
|
|
|
|
|
90
|
1 |
|
public function eraseCredentials() |
|
91
|
|
|
{ |
|
92
|
1 |
|
throw new NotImplementedException(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
1 |
|
public function getAttributes() : array |
|
96
|
|
|
{ |
|
97
|
|
|
/** @var Identity $identity */ |
|
98
|
1 |
|
$identity = $this->user->getIdentity(); |
|
99
|
|
|
|
|
100
|
1 |
|
return (array) $identity->getData(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
1 |
|
public function setAttributes(array $attributes) |
|
104
|
|
|
{ |
|
105
|
1 |
|
throw new NotImplementedException(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param string $name |
|
110
|
|
|
*/ |
|
111
|
1 |
|
public function hasAttribute($name) : bool |
|
112
|
|
|
{ |
|
113
|
1 |
|
return false; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param string $name |
|
118
|
|
|
*/ |
|
119
|
1 |
|
public function getAttribute($name) : bool |
|
120
|
|
|
{ |
|
121
|
1 |
|
return false; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param string $name |
|
126
|
|
|
* @param mixed $value |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function setAttribute($name, $value) |
|
129
|
|
|
{ |
|
130
|
1 |
|
throw new NotImplementedException(); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|