1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Ratchet. |
5
|
|
|
* |
6
|
|
|
** (c) 2016 Cees-Jan Kiewiet |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WyriHaximus\Ratchet\Security; |
13
|
|
|
|
14
|
|
|
use Thruway\Event\MessageEvent; |
15
|
|
|
use Thruway\Event\NewRealmEvent; |
16
|
|
|
use Thruway\Module\RealmModuleInterface; |
17
|
|
|
use Thruway\Module\RouterModuleClient; |
18
|
|
|
|
19
|
|
|
class AuthorizationManager extends RouterModuleClient implements RealmModuleInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Listen for Router events. |
23
|
|
|
* Required to add the authorization module to the realm |
24
|
|
|
* |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
public static function getSubscribedEvents() |
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
|
|
'new_realm' => ['handleNewRealm', 10] |
31
|
|
|
]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param NewRealmEvent $newRealmEvent |
36
|
|
|
*/ |
37
|
|
|
public function handleNewRealm(NewRealmEvent $newRealmEvent) |
38
|
|
|
{ |
39
|
|
|
$realm = $newRealmEvent->realm; |
40
|
|
|
|
41
|
|
|
if ($realm->getRealmName() === $this->getRealm()) { |
42
|
|
|
$realm->addModule($this); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
public function getSubscribedRealmEvents() |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
|
|
'PublishMessageEvent' => ['authorize', 100], |
53
|
|
|
'SubscribeMessageEvent' => ['authorize', 100], |
54
|
|
|
'RegisterMessageEvent' => ['authorize', 100], |
55
|
|
|
'CallMessageEvent' => ['authorize', 100], |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param MessageEvent $msg |
61
|
|
|
*/ |
62
|
|
|
public function authorize(MessageEvent $msg) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
/** |
65
|
|
|
* WIP auth handling |
66
|
|
|
*/ |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.