Skip to content

Commit 7dc5243

Browse files
committed
temp commit
2 parents 1b35a06 + 344d28a commit 7dc5243

36 files changed

+1934
-201
lines changed

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG PHP_VERSION
1+
ARG PHP_VERSION=8.1
22

33
FROM php:${PHP_VERSION}-cli
44
RUN apt-get update \
@@ -8,9 +8,6 @@ RUN apt-get update \
88
git \
99
wget \
1010
&& docker-php-ext-install -j$(nproc) bcmath sockets \
11-
&& wget https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 \
12-
&& mv test-reporter-latest-linux-amd64 /usr/bin/cc-test-reporter \
13-
&& chmod +x /usr/bin/cc-test-reporter \
1411
&& pecl install xdebug \
1512
&& docker-php-ext-enable xdebug && \
1613
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

Dockerfile.neo4j-okta

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM neo4j:5-enterprise
2+
3+
COPY ./neo4j-with-okta.conf /var/lib/neo4j/conf/neo4j.conf

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"psr/http-factory": "^1.0",
2929
"psr/http-client": "^1.0",
3030
"php-http/message": "^1.0",
31-
"stefanak-michal/bolt": "^7.1.4",
31+
"stefanak-michal/bolt": "^7.2.4",
3232
"symfony/polyfill-php80": "^1.2",
3333
"psr/simple-cache": ">=2.0",
3434
"ext-json": "*",

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ services:
5353
- .env
5454
neo4j:
5555
<<: *common
56-
image: neo4j:5-enterprise
56+
image: neo4j:5.23-enterprise
5757
hostname: neo4j
5858
networks:
5959
- neo4j
@@ -62,7 +62,7 @@ services:
6262
- "11474:7474"
6363
environment:
6464
<<: *common-env
65-
NEO4J_ACCEPT_LICENSE_AGREEMENT: 'yes'
65+
NEO4J_ACCEPT_LICENSE_AGREEMENT: 'yes' # Also add this
6666
NEO4J_server_bolt_advertised__address: neo4j:7687
6767
NEO4J_server_http_advertised__address: neo4j:7474
6868

neo4j-with-okta.conf

Lines changed: 829 additions & 0 deletions
Large diffs are not rendered by default.

src/Authentication/BasicAuth.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313

1414
namespace Laudis\Neo4j\Authentication;
1515

16+
use Bolt\protocol\V4_4;
17+
use Bolt\protocol\V5;
18+
use Bolt\protocol\V5_1;
19+
use Bolt\protocol\V5_2;
20+
use Bolt\protocol\V5_3;
21+
use Bolt\protocol\V5_4;
1622
use Exception;
1723
use Laudis\Neo4j\Bolt\BoltConnection;
1824
use Laudis\Neo4j\Bolt\BoltMessageFactory;
1925
use Laudis\Neo4j\Common\Neo4jLogger;
2026
use Laudis\Neo4j\Contracts\AuthenticateInterface;
27+
use Laudis\Neo4j\Exception\Neo4jException;
2128
use Psr\Http\Message\UriInterface;
2229

2330
/**
@@ -45,6 +52,8 @@ public function authenticateBolt(BoltConnection $connection, string $userAgent):
4552
if (method_exists($protocol, 'logon')) {
4653
$helloMetadata = ['user_agent' => $userAgent];
4754

55+
$factory->createHelloMessage($helloMetadata)->send();
56+
$response = self::getResponse($protocol);
4857
$responseHello = $factory->createHelloMessage($helloMetadata)->send()->getResponse();
4958

5059
$credentials = [
@@ -53,6 +62,8 @@ public function authenticateBolt(BoltConnection $connection, string $userAgent):
5362
'credentials' => $this->password,
5463
];
5564

65+
$factory->createLogonMessage($credentials)->send();
66+
self::getResponse($protocol);
5667
$response = $factory->createLogonMessage($credentials)->send()->getResponse();
5768

5869
/** @var array{server: string, connection_id: string, hints: list} */
@@ -75,6 +86,23 @@ public function authenticateBolt(BoltConnection $connection, string $userAgent):
7586
/**
7687
* @throws Exception
7788
*/
89+
public function logoff(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): void
90+
{
91+
$factory = $this->createMessageFactory($protocol);
92+
$factory->createLogoffMessage()->send();
93+
$protocol->getResponse();
94+
}
95+
96+
public static function getResponse(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): Response
97+
{
98+
$response = $protocol->getResponse();
99+
if ($response->signature === Signature::FAILURE) {
100+
throw Neo4jException::fromBoltResponse($response);
101+
}
102+
103+
return $response;
104+
}
105+
78106
public function toString(UriInterface $uri): string
79107
{
80108
return sprintf('Basic %s:%s@%s:%s', $this->username, '######', $uri->getHost(), $uri->getPort() ?? '');

src/Authentication/KerberosAuth.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@
1313

1414
namespace 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;
1624
use Exception;
17-
use Laudis\Neo4j\Bolt\BoltConnection;
1825
use Laudis\Neo4j\Bolt\BoltMessageFactory;
1926
use Laudis\Neo4j\Common\Neo4jLogger;
2027
use Laudis\Neo4j\Contracts\AuthenticateInterface;
28+
use Laudis\Neo4j\Exception\Neo4jException;
29+
use Psr\Http\Message\RequestInterface;
2130
use Psr\Http\Message\UriInterface;
2231
use Psr\Log\LogLevel;
2332

@@ -34,33 +43,55 @@ public function __construct(
3443
) {
3544
}
3645

46+
public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
47+
{
48+
$this->logger?->log(LogLevel::DEBUG, 'Authenticating using KerberosAuth');
49+
50+
return $request->withHeader('Authorization', 'Kerberos '.$this->token)
51+
->withHeader('User-Agent', $userAgent);
52+
}
53+
3754
/**
3855
* @throws Exception
3956
*
4057
* @return array{server: string, connection_id: string, hints: list}
4158
*/
42-
public function authenticateBolt(BoltConnection $connection, string $userAgent): array
59+
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
4360
{
44-
$factory = $this->createMessageFactory($connection);
61+
$factory = $this->createMessageFactory($protocol);
4562

4663
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent]);
4764

48-
$factory->createHelloMessage(['user_agent' => $userAgent])->send()->getResponse();
65+
$factory->createHelloMessage(['user_agent' => $userAgent])->send();
66+
67+
$response = self::getResponse($protocol);
4968

5069
$this->logger?->log(LogLevel::DEBUG, 'LOGON', ['scheme' => 'kerberos', 'principal' => '']);
5170

52-
$response = $factory->createLogonMessage([
71+
$factory->createLogonMessage([
5372
'scheme' => 'kerberos',
5473
'principal' => '',
5574
'credentials' => $this->token,
56-
])->send()->getResponse();
75+
])->send();
76+
77+
self::getResponse($protocol);
5778

5879
/**
5980
* @var array{server: string, connection_id: string, hints: list}
6081
*/
6182
return $response->content;
6283
}
6384

85+
public static function getResponse(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): Response
86+
{
87+
$response = $protocol->getResponse();
88+
if ($response->signature === Signature::FAILURE) {
89+
throw Neo4jException::fromBoltResponse($response);
90+
}
91+
92+
return $response;
93+
}
94+
6495
public function toString(UriInterface $uri): string
6596
{
6697
return sprintf('Kerberos %s@%s:%s', $this->token, $uri->getHost(), $uri->getPort() ?? '');
@@ -69,8 +100,8 @@ public function toString(UriInterface $uri): string
69100
/**
70101
* Helper to create the message factory.
71102
*/
72-
private function createMessageFactory(BoltConnection $connection): BoltMessageFactory
103+
private function createMessageFactory(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): BoltMessageFactory
73104
{
74-
return new BoltMessageFactory($connection, $this->logger);
105+
return new BoltMessageFactory($protocol, $this->logger);
75106
}
76107
}

src/Authentication/NoAuth.php

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@
1313

1414
namespace 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;
1624
use Exception;
17-
use Laudis\Neo4j\Bolt\BoltConnection;
1825
use Laudis\Neo4j\Bolt\BoltMessageFactory;
1926
use Laudis\Neo4j\Common\Neo4jLogger;
2027
use Laudis\Neo4j\Contracts\AuthenticateInterface;
21-
use Laudis\Neo4j\Enum\ConnectionProtocol;
28+
use Laudis\Neo4j\Exception\Neo4jException;
29+
use Psr\Http\Message\RequestInterface;
2230
use Psr\Http\Message\UriInterface;
31+
use Psr\Log\LogLevel;
2332

2433
use function sprintf;
2534

@@ -30,21 +39,30 @@ public function __construct(
3039
) {
3140
}
3241

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+
3349
/**
3450
* @throws Exception
3551
*
3652
* @return array{server: string, connection_id: string, hints: list}
3753
*/
38-
public function authenticateBolt(BoltConnection $connection, string $userAgent): array
54+
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
3955
{
40-
$factory = $this->createMessageFactory($connection);
56+
$factory = $this->createMessageFactory($protocol);
4157

42-
if ($connection->getProtocol()->compare(ConnectionProtocol::BOLT_V5_1()) >= 0) {
58+
if (method_exists($protocol, 'logon')) {
4359
$helloMetadata = ['user_agent' => $userAgent];
4460

45-
$factory->createHelloMessage($helloMetadata)->send()->getResponse();
61+
$factory->createHelloMessage($helloMetadata)->send();
62+
$response = self::getResponse($protocol);
4663

47-
$response = $factory->createLogonMessage(['scheme' => 'none'])->send()->getResponse();
64+
$factory->createLogonMessage(['scheme' => 'none'])->send();
65+
self::getResponse($protocol);
4866

4967
/** @var array{server: string, connection_id: string, hints: list} */
5068
return $response->content;
@@ -55,19 +73,36 @@ public function authenticateBolt(BoltConnection $connection, string $userAgent):
5573
'scheme' => 'none',
5674
];
5775

58-
$response = $factory->createHelloMessage($helloMetadata)->send()->getResponse();
76+
$factory->createHelloMessage($helloMetadata)->send();
5977

6078
/** @var array{server: string, connection_id: string, hints: list} */
61-
return $response->content;
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();
6297
}
6398

6499
public function toString(UriInterface $uri): string
65100
{
66101
return sprintf('No Auth %s:%s', $uri->getHost(), $uri->getPort() ?? '');
67102
}
68103

69-
private function createMessageFactory(BoltConnection $connection): BoltMessageFactory
104+
private function createMessageFactory(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol): BoltMessageFactory
70105
{
71-
return new BoltMessageFactory($connection, $this->logger);
106+
return new BoltMessageFactory($protocol, $this->logger);
72107
}
73108
}

src/Authentication/OpenIDConnectAuth.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
namespace Laudis\Neo4j\Authentication;
1515

16+
use Bolt\protocol\V4_4;
17+
use Bolt\protocol\V5;
18+
use Bolt\protocol\V5_1;
19+
use Bolt\protocol\V5_2;
20+
use Bolt\protocol\V5_3;
21+
use Bolt\protocol\V5_4;
1622
use Exception;
1723
use Laudis\Neo4j\Bolt\BoltConnection;
1824
use Laudis\Neo4j\Bolt\BoltMessageFactory;
@@ -45,20 +51,24 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
4551
*
4652
* @return array{server: string, connection_id: string, hints: list}
4753
*/
48-
public function authenticateBolt(BoltConnection $connection, string $userAgent): array
54+
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
4955
{
50-
$factory = $this->createMessageFactory($connection);
56+
$factory = $this->createMessageFactory($protocol);
5157

5258
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent]);
5359

54-
$factory->createHelloMessage(['user_agent' => $userAgent])->send()->getResponse();
60+
$factory->createHelloMessage(['user_agent' => $userAgent])->send();
61+
62+
$response = $protocol->getResponse();
5563

5664
$this->logger?->log(LogLevel::DEBUG, 'LOGON', ['scheme' => 'bearer']);
5765

58-
$response = $factory->createLogonMessage([
66+
$factory->createLogonMessage([
5967
'scheme' => 'bearer',
6068
'credentials' => $this->token,
61-
])->send()->getResponse();
69+
])->send();
70+
71+
$protocol->getResponse();
6272

6373
/**
6474
* @var array{server: string, connection_id: string, hints: list}

0 commit comments

Comments
 (0)