Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/integration-test-cluster-neo4j-4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
run: |
echo "CONNECTION=neo4j://neo4j:testtest@neo4j" > .env
- uses: hoverkraft-tech/[email protected]
name: Start services
with:
compose-file: './docker-compose-neo4j-4.yml'
up-flags: '--build --remove-orphans'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration-test-cluster-neo4j-5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
run: |
echo "CONNECTION=neo4j://neo4j:testtest@neo4j" > .env
- uses: hoverkraft-tech/[email protected]
name: Start services
with:
compose-file: './docker-compose.yml'
up-flags: '--build --remove-orphans'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/integration-test-single-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
run: |
echo "CONNECTION=neo4j://neo4j:testtest@neo4j" > .env
- uses: hoverkraft-tech/[email protected]
name: Start services
with:
compose-file: './docker-compose-neo4j-4.yml'
up-flags: '--build --remove-orphans'
Expand All @@ -44,6 +45,7 @@ jobs:
run: |
echo "CONNECTION=neo4j://neo4j:testtest@neo4j" > .env
- uses: hoverkraft-tech/[email protected]
name: Start services
with:
compose-file: './docker-compose.yml'
up-flags: '--build'
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"suggest": {
"ext-bcmath": "Needed to implement bolt protocol",
"ext-sysvsem": "Needed for enabling connection pooling between processes",
"composer-runtime-api": "Install composer 2 for auto detection of version in user agent"
"composer-runtime-api": "Install composer 2 for auto detection of version in user agent",
"psr/log": "Needed to enable logging"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
Expand All @@ -51,12 +52,12 @@
"friendsofphp/php-cs-fixer": "3.15.0",
"psalm/plugin-phpunit": "^0.18",
"monolog/monolog": "^2.2",
"psr/log": "^1.1",
"symfony/uid": "^5.0",
"symfony/var-dumper": "^5.0",
"cache/integration-tests": "dev-master",
"kubawerlos/php-cs-fixer-custom-fixers": "3.13.*",
"rector/rector": "^1.0"
"rector/rector": "^1.0",
"psr/log": "^3.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
</testsuite>
</testsuites>
<php>
<env name="CONNECTION" value="neo4j://neo4j:testtest@localhost:11687"/>
<env name="CONNECTION" value="neo4j://neo4j:testtest@localhost:7687"/>
</php>
</phpunit>
23 changes: 12 additions & 11 deletions src/Authentication/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use function explode;

use Laudis\Neo4j\Common\Neo4jLogger;
use Laudis\Neo4j\Contracts\AuthenticateInterface;
use Psr\Http\Message\UriInterface;

Expand All @@ -32,47 +33,47 @@ final class Authenticate
*
* @pure
*/
public static function basic(string $username, string $password): BasicAuth
public static function basic(string $username, string $password, ?Neo4jLogger $logger = null): BasicAuth
{
return new BasicAuth($username, $password);
return new BasicAuth($username, $password, $logger);
}

/**
* Authenticate using a kerberos token.
*
* @pure
*/
public static function kerberos(string $token): KerberosAuth
public static function kerberos(string $token, ?Neo4jLogger $logger = null): KerberosAuth
{
return new KerberosAuth($token);
return new KerberosAuth($token, $logger);
}

/**
* Authenticate using a OpenID Connect token.
*
* @pure
*/
public static function oidc(string $token): OpenIDConnectAuth
public static function oidc(string $token, ?Neo4jLogger $logger = null): OpenIDConnectAuth
{
return new OpenIDConnectAuth($token);
return new OpenIDConnectAuth($token, $logger);
}

/**
* Don't authenticate at all.
*
* @pure
*/
public static function disabled(): NoAuth
public static function disabled(?Neo4jLogger $logger = null): NoAuth
{
return new NoAuth();
return new NoAuth($logger);
}

/**
* Authenticate from information found in the url.
*
* @pure
*/
public static function fromUrl(UriInterface $uri): AuthenticateInterface
public static function fromUrl(UriInterface $uri, ?Neo4jLogger $logger = null): AuthenticateInterface
{
/**
* @psalm-suppress ImpureMethodCall Uri is a pure object:
Expand All @@ -86,9 +87,9 @@ public static function fromUrl(UriInterface $uri): AuthenticateInterface
$explode = explode(':', $userInfo);
[$user, $pass] = $explode;

return self::basic($user, $pass);
return self::basic($user, $pass, $logger);
}

return self::disabled();
return self::disabled($logger);
}
}
12 changes: 8 additions & 4 deletions src/Authentication/BasicAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
use Bolt\protocol\V5_3;
use Bolt\protocol\V5_4;
use Exception;
use Laudis\Neo4j\Common\Neo4jLogger;
use Laudis\Neo4j\Common\ResponseHelper;
use Laudis\Neo4j\Contracts\AuthenticateInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;
use Psr\Log\LogLevel;

/**
* Authenticates connections using a basic username and password.
Expand All @@ -37,14 +39,13 @@ final class BasicAuth implements AuthenticateInterface
*/
public function __construct(
private readonly string $username,
private readonly string $password
private readonly string $password,
private readonly ?Neo4jLogger $logger,
) {}

/**
* @psalm-mutation-free
*/
public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
{
$this->logger?->log(LogLevel::DEBUG, 'Authenticating using BasicAuth');
$combo = base64_encode($this->username.':'.$this->password);

/**
Expand All @@ -64,8 +65,10 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
{
if (method_exists($protocol, 'logon')) {
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent]);
$protocol->hello(['user_agent' => $userAgent]);
$response = ResponseHelper::getResponse($protocol);
$this->logger?->log(LogLevel::DEBUG, 'LOGON', ['scheme' => 'basic', 'principal' => $this->username]);
$protocol->logon([
'scheme' => 'basic',
'principal' => $this->username,
Expand All @@ -76,6 +79,7 @@ public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $
/** @var array{server: string, connection_id: string, hints: list} */
return $response->content;
} else {
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent, 'scheme' => 'basic', 'principal' => $this->username]);
$protocol->hello([
'user_agent' => $userAgent,
'scheme' => 'basic',
Expand Down
12 changes: 8 additions & 4 deletions src/Authentication/KerberosAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
use Bolt\protocol\V5_3;
use Bolt\protocol\V5_4;
use Exception;
use Laudis\Neo4j\Common\Neo4jLogger;
use Laudis\Neo4j\Common\ResponseHelper;
use Laudis\Neo4j\Contracts\AuthenticateInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;
use Psr\Log\LogLevel;

use function sprintf;

Expand All @@ -36,14 +38,13 @@ final class KerberosAuth implements AuthenticateInterface
* @psalm-external-mutation-free
*/
public function __construct(
private readonly string $token
private readonly string $token,
private readonly ?Neo4jLogger $logger,
) {}

/**
* @psalm-mutation-free
*/
public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
{
$this->logger?->log(LogLevel::DEBUG, 'Authenticating using KerberosAuth');
/**
* @psalm-suppress ImpureMethodCall Request is a pure object:
*
Expand All @@ -61,8 +62,10 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
{
if (method_exists($protocol, 'logon')) {
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent]);
$protocol->hello(['user_agent' => $userAgent]);
$response = ResponseHelper::getResponse($protocol);
$this->logger?->log(LogLevel::DEBUG, 'LOGON', ['scheme' => 'kerberos', 'principal' => '']);
$protocol->logon([
'scheme' => 'kerberos',
'principal' => '',
Expand All @@ -73,6 +76,7 @@ public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $
/** @var array{server: string, connection_id: string, hints: list} */
return $response->content;
} else {
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent, 'scheme' => 'kerberos', 'principal' => '']);
$protocol->hello([
'user_agent' => $userAgent,
'scheme' => 'kerberos',
Expand Down
12 changes: 11 additions & 1 deletion src/Authentication/NoAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
use Bolt\protocol\V5_3;
use Bolt\protocol\V5_4;
use Exception;
use Laudis\Neo4j\Common\Neo4jLogger;
use Laudis\Neo4j\Common\ResponseHelper;
use Laudis\Neo4j\Contracts\AuthenticateInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;
use Psr\Log\LogLevel;

use function sprintf;

Expand All @@ -33,10 +35,15 @@
final class NoAuth implements AuthenticateInterface
{
/**
* @psalm-mutation-free
* @pure
*/
public function __construct(
private readonly ?Neo4jLogger $logger
) {}

public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
{
$this->logger?->log(LogLevel::DEBUG, 'Authentication disabled');
/**
* @psalm-suppress ImpureMethodCall Request is a pure object:
*
Expand All @@ -53,8 +60,10 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
{
if (method_exists($protocol, 'logon')) {
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent]);
$protocol->hello(['user_agent' => $userAgent]);
$response = ResponseHelper::getResponse($protocol);
$this->logger?->log(LogLevel::DEBUG, 'LOGON', ['scheme' => 'none']);
$protocol->logon([
'scheme' => 'none',
]);
Expand All @@ -63,6 +72,7 @@ public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $
/** @var array{server: string, connection_id: string, hints: list} */
return $response->content;
} else {
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent, 'scheme' => 'none']);
$protocol->hello([
'user_agent' => $userAgent,
'scheme' => 'none',
Expand Down
12 changes: 8 additions & 4 deletions src/Authentication/OpenIDConnectAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
use Bolt\protocol\V5_3;
use Bolt\protocol\V5_4;
use Exception;
use Laudis\Neo4j\Common\Neo4jLogger;
use Laudis\Neo4j\Common\ResponseHelper;
use Laudis\Neo4j\Contracts\AuthenticateInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;
use Psr\Log\LogLevel;

use function sprintf;

Expand All @@ -33,14 +35,13 @@ final class OpenIDConnectAuth implements AuthenticateInterface
* @psalm-external-mutation-free
*/
public function __construct(
private readonly string $token
private readonly string $token,
private readonly ?Neo4jLogger $logger
) {}

/**
* @psalm-mutation-free
*/
public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
{
$this->logger?->log(LogLevel::DEBUG, 'Authenticating using OpenIDConnectAuth');
/**
* @psalm-suppress ImpureMethodCall Request is a pure object:
*
Expand All @@ -58,8 +59,10 @@ public function authenticateHttp(RequestInterface $request, UriInterface $uri, s
public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $userAgent): array
{
if (method_exists($protocol, 'logon')) {
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent]);
$protocol->hello(['user_agent' => $userAgent]);
$response = ResponseHelper::getResponse($protocol);
$this->logger?->log(LogLevel::DEBUG, 'LOGON', ['scheme' => 'bearer']);
$protocol->logon([
'scheme' => 'bearer',
'credentials' => $this->token,
Expand All @@ -69,6 +72,7 @@ public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $
/** @var array{server: string, connection_id: string, hints: list} */
return $response->content;
} else {
$this->logger?->log(LogLevel::DEBUG, 'HELLO', ['user_agent' => $userAgent, 'scheme' => 'bearer']);
$protocol->hello([
'user_agent' => $userAgent,
'scheme' => 'bearer',
Expand Down
5 changes: 5 additions & 0 deletions src/Basic/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public static function create(string|UriInterface $uri, ?DriverConfiguration $co

return new self($driver);
}

public function closeConnections(): void
{
$this->driver->closeConnections();
}
}
Loading
Loading