1313
1414namespace Laudis \Neo4j \Authentication ;
1515
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 ;
2416use Exception ;
17+ use Laudis \Neo4j \Bolt \BoltConnection ;
2518use Laudis \Neo4j \Bolt \BoltMessageFactory ;
2619use Laudis \Neo4j \Common \Neo4jLogger ;
2720use Laudis \Neo4j \Contracts \AuthenticateInterface ;
28- use Laudis \Neo4j \Exception \Neo4jException ;
29- use Psr \Http \Message \RequestInterface ;
21+ use Laudis \Neo4j \Enum \ConnectionProtocol ;
3022use Psr \Http \Message \UriInterface ;
31- use Psr \Log \LogLevel ;
3223
3324use function sprintf ;
3425
@@ -39,30 +30,21 @@ public function __construct(
3930 ) {
4031 }
4132
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-
4933 /**
5034 * @throws Exception
5135 *
5236 * @return array{server: string, connection_id: string, hints: list}
5337 */
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
5539 {
56- $ factory = $ this ->createMessageFactory ($ protocol );
40+ $ factory = $ this ->createMessageFactory ($ connection );
5741
58- if (method_exists ( $ protocol , ' logon ' ) ) {
42+ if ($ connection -> getProtocol ()-> compare (ConnectionProtocol:: BOLT_V5_1 ()) >= 0 ) {
5943 $ helloMetadata = ['user_agent ' => $ userAgent ];
6044
61- $ factory ->createHelloMessage ($ helloMetadata )->send ();
62- $ response = self ::getResponse ($ protocol );
45+ $ factory ->createHelloMessage ($ helloMetadata )->send ()->getResponse ();
6346
64- $ factory ->createLogonMessage (['scheme ' => 'none ' ])->send ();
65- self ::getResponse ($ protocol );
47+ $ response = $ factory ->createLogonMessage (['scheme ' => 'none ' ])->send ()->getResponse ();
6648
6749 /** @var array{server: string, connection_id: string, hints: list} */
6850 return $ response ->content ;
@@ -73,36 +55,19 @@ public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $
7355 'scheme ' => 'none ' ,
7456 ];
7557
76- $ factory ->createHelloMessage ($ helloMetadata )->send ();
58+ $ response = $ factory ->createHelloMessage ($ helloMetadata )->send ()-> getResponse ();
7759
7860 /** @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 ;
9762 }
9863
9964 public function toString (UriInterface $ uri ): string
10065 {
10166 return sprintf ('No Auth %s:%s ' , $ uri ->getHost (), $ uri ->getPort () ?? '' );
10267 }
10368
104- private function createMessageFactory (V4_4 | V5 | V5_1 | V5_2 | V5_3 | V5_4 $ protocol ): BoltMessageFactory
69+ private function createMessageFactory (BoltConnection $ connection ): BoltMessageFactory
10570 {
106- return new BoltMessageFactory ($ protocol , $ this ->logger );
71+ return new BoltMessageFactory ($ connection , $ this ->logger );
10772 }
10873}
0 commit comments