13
13
14
14
namespace Laudis \Neo4j \Authentication ;
15
15
16
- use Bolt \enum \Signature ;
17
- use Bolt \protocol \Response ;
18
- use Bolt \protocol \V4_4 ;
19
- use Bolt \protocol \V5 ;
20
- use Bolt \protocol \V5_1 ;
21
- use Bolt \protocol \V5_2 ;
22
- use Bolt \protocol \V5_3 ;
23
- use Bolt \protocol \V5_4 ;
24
16
use Exception ;
17
+ use Laudis \Neo4j \Bolt \BoltConnection ;
25
18
use Laudis \Neo4j \Bolt \BoltMessageFactory ;
26
19
use Laudis \Neo4j \Common \Neo4jLogger ;
27
20
use Laudis \Neo4j \Contracts \AuthenticateInterface ;
28
- use Laudis \Neo4j \Exception \Neo4jException ;
29
- use Psr \Http \Message \RequestInterface ;
21
+ use Laudis \Neo4j \Enum \ConnectionProtocol ;
30
22
use Psr \Http \Message \UriInterface ;
31
- use Psr \Log \LogLevel ;
32
23
33
24
use function sprintf ;
34
25
@@ -39,30 +30,21 @@ public function __construct(
39
30
) {
40
31
}
41
32
42
- public function authenticateHttp (RequestInterface $ request , UriInterface $ uri , string $ userAgent ): RequestInterface
43
- {
44
- $ this ->logger ?->log(LogLevel::DEBUG , 'Authentication disabled ' );
45
-
46
- return $ request ->withHeader ('User-Agent ' , $ userAgent );
47
- }
48
-
49
33
/**
50
34
* @throws Exception
51
35
*
52
36
* @return array{server: string, connection_id: string, hints: list}
53
37
*/
54
- public function authenticateBolt (V4_4 | V5 | V5_1 | V5_2 | V5_3 | V5_4 $ protocol , string $ userAgent ): array
38
+ public function authenticateBolt (BoltConnection $ connection , string $ userAgent ): array
55
39
{
56
- $ factory = $ this ->createMessageFactory ($ protocol );
40
+ $ factory = $ this ->createMessageFactory ($ connection );
57
41
58
- if (method_exists ( $ protocol , ' logon ' ) ) {
42
+ if ($ connection -> getProtocol ()-> compare (ConnectionProtocol:: BOLT_V5_1 ()) >= 0 ) {
59
43
$ helloMetadata = ['user_agent ' => $ userAgent ];
60
44
61
- $ factory ->createHelloMessage ($ helloMetadata )->send ();
62
- $ response = self ::getResponse ($ protocol );
45
+ $ factory ->createHelloMessage ($ helloMetadata )->send ()->getResponse ();
63
46
64
- $ factory ->createLogonMessage (['scheme ' => 'none ' ])->send ();
65
- self ::getResponse ($ protocol );
47
+ $ response = $ factory ->createLogonMessage (['scheme ' => 'none ' ])->send ()->getResponse ();
66
48
67
49
/** @var array{server: string, connection_id: string, hints: list} */
68
50
return $ response ->content ;
@@ -73,36 +55,19 @@ public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $
73
55
'scheme ' => 'none ' ,
74
56
];
75
57
76
- $ factory ->createHelloMessage ($ helloMetadata )->send ();
58
+ $ response = $ factory ->createHelloMessage ($ helloMetadata )->send ()-> getResponse ();
77
59
78
60
/** @var array{server: string, connection_id: string, hints: list} */
79
- return self ::getResponse ($ protocol )->content ;
80
- }
81
-
82
- public static function getResponse (V4_4 |V5 |V5_1 |V5_2 |V5_3 |V5_4 $ protocol ): Response
83
- {
84
- $ response = $ protocol ->getResponse ();
85
- if ($ response ->signature === Signature::FAILURE ) {
86
- throw Neo4jException::fromBoltResponse ($ response );
87
- }
88
-
89
- return $ response ;
90
- }
91
-
92
- public function logoff (V4_4 |V5 |V5_1 |V5_2 |V5_3 |V5_4 $ protocol ): void
93
- {
94
- $ factory = $ this ->createMessageFactory ($ protocol );
95
- $ factory ->createLogoffMessage ()->send ();
96
- $ protocol ->getResponse ();
61
+ return $ response ->content ;
97
62
}
98
63
99
64
public function toString (UriInterface $ uri ): string
100
65
{
101
66
return sprintf ('No Auth %s:%s ' , $ uri ->getHost (), $ uri ->getPort () ?? '' );
102
67
}
103
68
104
- private function createMessageFactory (V4_4 | V5 | V5_1 | V5_2 | V5_3 | V5_4 $ protocol ): BoltMessageFactory
69
+ private function createMessageFactory (BoltConnection $ connection ): BoltMessageFactory
105
70
{
106
- return new BoltMessageFactory ($ protocol , $ this ->logger );
71
+ return new BoltMessageFactory ($ connection , $ this ->logger );
107
72
}
108
73
}
0 commit comments