|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* \AppserverIo\Stomp\Authenticator |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Lars Roettig <[email protected]> |
|
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/appserver-io/appserver |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace AppserverIo\Stomp\Authenticator; |
|
21
|
|
|
|
|
22
|
|
|
use AppserverIo\Stomp\Exception\ProtocolException; |
|
23
|
|
|
use AppserverIo\Stomp\Interfaces\AuthenticatorInterface; |
|
24
|
|
|
use AppserverIo\Stomp\Utils\ErrorMessages; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Stomp protocol authenticator class. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Lars Roettig <[email protected]> |
|
30
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
32
|
|
|
* @link https://github.com/appserver-io/appserver |
|
33
|
|
|
* @link https://github.com/stomp/stomp-spec/blob/master/src/stomp-specification-1.1.md |
|
34
|
|
|
*/ |
|
35
|
|
|
class SimpleAuthenticator implements AuthenticatorInterface |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* Holds the information is the client authenticated. |
|
39
|
|
|
* |
|
40
|
|
|
* @var bool |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $isAuthenticated = false; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Authenticate user by connect command. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $login The login name |
|
48
|
|
|
* @param string $passCode The password |
|
49
|
|
|
* |
|
50
|
|
|
* @return string token which will be used for authorization requests (though it isn't actually used yet) |
|
51
|
|
|
* |
|
52
|
|
|
* @throws \Exception |
|
53
|
|
|
*/ |
|
54
|
|
|
public function connect($login, $passCode) |
|
55
|
|
|
{ |
|
56
|
|
|
if ($login === "system" && $passCode === "manager") { |
|
57
|
|
|
$this->isAuthenticated = true; |
|
58
|
|
|
return md5(rand()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
throw new ProtocolException(sprintf(ErrorMessages::FAILED_AUTH, $login)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Returns is authenticated user. |
|
66
|
|
|
* |
|
67
|
|
|
* @return bool |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getIsAuthenticated() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->isAuthenticated; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|