Skip to content

Commit 85c5547

Browse files
committed
Remove the ServerOptions from the ServerProtocolHandlerInterface. This comes from the container if needed.
1 parent 4fe9628 commit 85c5547

26 files changed

+170
-118
lines changed

src/FreeDSx/Ldap/Container.php

+15-11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use FreeDSx\Ldap\Server\RequestHistory;
2626
use FreeDSx\Ldap\Server\ServerProtocolFactory;
2727
use FreeDSx\Ldap\Server\ServerRunner\PcntlServerRunner;
28+
use FreeDSx\Ldap\Server\ServerRunner\ServerRunnerInterface;
2829
use FreeDSx\Ldap\Server\SocketServerFactory;
2930
use FreeDSx\Socket\SocketPool;
3031

@@ -145,8 +146,8 @@ className: ServerProtocolFactory::class,
145146
factory: $this->makeServerProtocolFactory(...),
146147
);
147148
$this->registerFactory(
148-
className: PcntlServerRunner::class,
149-
factory: $this->makePcntlServerRunner(...),
149+
className: ServerRunnerInterface::class,
150+
factory: $this->makeServerRunner(...),
150151
);
151152
$this->registerFactory(
152153
className: ServerAuthorization::class,
@@ -197,8 +198,10 @@ private function makeRootDseLoader(): RootDseLoader
197198
private function makeServerProtocolFactory(): ServerProtocolFactory
198199
{
199200
return new ServerProtocolFactory(
200-
$this->get(HandlerFactory::class),
201-
$this->get(ServerOptions::class),
201+
handlerFactory: $this->get(HandlerFactoryInterface::class),
202+
logger: $this->get(ServerOptions::class)->getLogger(),
203+
serverProtocolHandlerFactory: $this->get(ServerProtocolHandlerFactory::class),
204+
serverAuthorization: $this->get(ServerAuthorization::class),
202205
);
203206
}
204207

@@ -207,11 +210,11 @@ private function makeHandlerFactory(): HandlerFactory
207210
return new HandlerFactory($this->get(ServerOptions::class));
208211
}
209212

210-
private function makePcntlServerRunner(): PcntlServerRunner
213+
private function makeServerRunner(): ServerRunnerInterface
211214
{
212215
return new PcntlServerRunner(
213-
$this->get(ServerProtocolFactory::class),
214-
$this->get(ServerOptions::class)->getLogger(),
216+
serverProtocolFactory: $this->get(ServerProtocolFactory::class),
217+
logger: $this->get(ServerOptions::class)->getLogger(),
215218
);
216219
}
217220

@@ -220,8 +223,8 @@ private function makeSocketServerFactory(): SocketServerFactory
220223
$serverOptions = $this->get(ServerOptions::class);
221224

222225
return new SocketServerFactory(
223-
$serverOptions,
224-
$serverOptions->getLogger(),
226+
options: $serverOptions,
227+
logger: $serverOptions->getLogger(),
225228
);
226229
}
227230

@@ -233,8 +236,9 @@ private function makeServerAuthorizer(): ServerAuthorization
233236
private function makeServerProtocolHandlerFactory(): ServerProtocolHandlerFactory
234237
{
235238
return new ServerProtocolHandlerFactory(
236-
$this->get(HandlerFactoryInterface::class),
237-
new RequestHistory()
239+
handlerFactory: $this->get(HandlerFactoryInterface::class),
240+
options: $this->get(ServerOptions::class),
241+
requestHistory: new RequestHistory(),
238242
);
239243
}
240244
}

src/FreeDSx/Ldap/LdapServer.php

-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace FreeDSx\Ldap;
1515

16-
use FreeDSx\Ldap\Server\LoggerTrait;
1716
use FreeDSx\Ldap\Server\RequestHandler\PagingHandlerInterface;
1817
use FreeDSx\Ldap\Server\RequestHandler\ProxyHandler;
1918
use FreeDSx\Ldap\Server\RequestHandler\ProxyPagingHandler;
@@ -31,8 +30,6 @@
3130
*/
3231
class LdapServer
3332
{
34-
use LoggerTrait;
35-
3633
private Container $container;
3734

3835
public function __construct(

src/FreeDSx/Ldap/Protocol/Factory/ServerProtocolHandlerFactory.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use FreeDSx\Ldap\Protocol\ServerProtocolHandler\ServerProtocolHandlerInterface;
2424
use FreeDSx\Ldap\Server\HandlerFactoryInterface;
2525
use FreeDSx\Ldap\Server\RequestHistory;
26+
use FreeDSx\Ldap\ServerOptions;
2627

2728
/**
2829
* Determines the correct handler for the request.
@@ -31,16 +32,11 @@
3132
*/
3233
class ServerProtocolHandlerFactory
3334
{
34-
private HandlerFactoryInterface $handlerFactory;
35-
36-
private RequestHistory $requestHistory;
37-
3835
public function __construct(
39-
HandlerFactoryInterface $handlerFactory,
40-
RequestHistory $requestHistory
36+
private readonly HandlerFactoryInterface $handlerFactory,
37+
private readonly ServerOptions $options,
38+
private readonly RequestHistory $requestHistory,
4139
) {
42-
$this->handlerFactory = $handlerFactory;
43-
$this->requestHistory = $requestHistory;
4440
}
4541

4642
public function get(
@@ -50,7 +46,7 @@ public function get(
5046
if ($request instanceof ExtendedRequest && $request->getName() === ExtendedRequest::OID_WHOAMI) {
5147
return new ServerProtocolHandler\ServerWhoAmIHandler();
5248
} elseif ($request instanceof ExtendedRequest && $request->getName() === ExtendedRequest::OID_START_TLS) {
53-
return new ServerProtocolHandler\ServerStartTlsHandler();
49+
return new ServerProtocolHandler\ServerStartTlsHandler($this->options);
5450
} elseif ($this->isRootDseSearch($request)) {
5551
return $this->getRootDseHandler();
5652
} elseif ($this->isPagingSearch($request, $controls)) {
@@ -86,7 +82,10 @@ private function getRootDseHandler(): ServerProtocolHandler\ServerRootDseHandler
8682
{
8783
$rootDseHandler = $this->handlerFactory->makeRootDseHandler();
8884

89-
return new ServerProtocolHandler\ServerRootDseHandler($rootDseHandler);
85+
return new ServerProtocolHandler\ServerRootDseHandler(
86+
$this->options,
87+
$rootDseHandler,
88+
);
9089
}
9190

9291
private function getPagingHandler(): ServerProtocolHandlerInterface

src/FreeDSx/Ldap/Protocol/ServerProtocolHandler.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ private function dispatchRequest(LdapMessageRequest $message): void
170170
$message,
171171
$this->authorizer->getToken(),
172172
$this->handlerFactory->makeRequestHandler(),
173-
$this->queue,
174-
$this->options
173+
$this->queue
175174
);
176175
# Authentication is required, but they have not authenticated...
177176
} else {

src/FreeDSx/Ldap/Protocol/ServerProtocolHandler/ServerDispatchHandler.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use FreeDSx\Ldap\Server\RequestContext;
2323
use FreeDSx\Ldap\Server\RequestHandler\RequestHandlerInterface;
2424
use FreeDSx\Ldap\Server\Token\TokenInterface;
25-
use FreeDSx\Ldap\ServerOptions;
2625

2726
/**
2827
* Handles generic requests that can be sent to the user supplied dispatcher / handler.
@@ -40,8 +39,7 @@ public function handleRequest(
4039
LdapMessageRequest $message,
4140
TokenInterface $token,
4241
RequestHandlerInterface $dispatcher,
43-
ServerQueue $queue,
44-
ServerOptions $options
42+
ServerQueue $queue
4543
): void {
4644
$context = new RequestContext($message->controls(), $token);
4745
$request = $message->getRequest();

src/FreeDSx/Ldap/Protocol/ServerProtocolHandler/ServerPagingHandler.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use FreeDSx\Ldap\Server\RequestHandler\RequestHandlerInterface;
3131
use FreeDSx\Ldap\Server\RequestHistory;
3232
use FreeDSx\Ldap\Server\Token\TokenInterface;
33-
use FreeDSx\Ldap\ServerOptions;
3433
use Throwable;
3534

3635
/**
@@ -66,8 +65,7 @@ public function handleRequest(
6665
LdapMessageRequest $message,
6766
TokenInterface $token,
6867
RequestHandlerInterface $dispatcher,
69-
ServerQueue $queue,
70-
ServerOptions $options
68+
ServerQueue $queue
7169
): void {
7270
$context = new RequestContext(
7371
$message->controls(),

src/FreeDSx/Ldap/Protocol/ServerProtocolHandler/ServerPagingUnsupportedHandler.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use FreeDSx\Ldap\Server\RequestContext;
2121
use FreeDSx\Ldap\Server\RequestHandler\RequestHandlerInterface;
2222
use FreeDSx\Ldap\Server\Token\TokenInterface;
23-
use FreeDSx\Ldap\ServerOptions;
2423

2524
/**
2625
* Determines whether we can page results if no paging handler is defined.
@@ -38,8 +37,7 @@ public function handleRequest(
3837
LdapMessageRequest $message,
3938
TokenInterface $token,
4039
RequestHandlerInterface $dispatcher,
41-
ServerQueue $queue,
42-
ServerOptions $options
40+
ServerQueue $queue
4341
): void {
4442
$context = new RequestContext(
4543
$message->controls(),

src/FreeDSx/Ldap/Protocol/ServerProtocolHandler/ServerProtocolHandlerInterface.php

-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use FreeDSx\Ldap\Protocol\Queue\ServerQueue;
1919
use FreeDSx\Ldap\Server\RequestHandler\RequestHandlerInterface;
2020
use FreeDSx\Ldap\Server\Token\TokenInterface;
21-
use FreeDSx\Ldap\ServerOptions;
2221
use FreeDSx\Socket\Exception\ConnectionException;
2322

2423
/**
@@ -32,7 +31,6 @@ interface ServerProtocolHandlerInterface
3231
/**
3332
* Handle protocol actions specific to the request received.
3433
*
35-
* @param ServerOptions $options
3634
* @throws OperationException
3735
* @throws ConnectionException
3836
*/
@@ -41,6 +39,5 @@ public function handleRequest(
4139
TokenInterface $token,
4240
RequestHandlerInterface $dispatcher,
4341
ServerQueue $queue,
44-
ServerOptions $options
4542
): void;
4643
}

src/FreeDSx/Ldap/Protocol/ServerProtocolHandler/ServerRootDseHandler.php

+13-12
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
*/
3939
class ServerRootDseHandler implements ServerProtocolHandlerInterface
4040
{
41-
public function __construct(private ?RootDseHandlerInterface $rootDseHandler = null)
42-
{
41+
public function __construct(
42+
private readonly ServerOptions $options,
43+
private readonly ?RootDseHandlerInterface $rootDseHandler = null
44+
) {
4345
}
4446

4547
/**
@@ -50,34 +52,33 @@ public function handleRequest(
5052
LdapMessageRequest $message,
5153
TokenInterface $token,
5254
RequestHandlerInterface $dispatcher,
53-
ServerQueue $queue,
54-
ServerOptions $options
55+
ServerQueue $queue
5556
): void {
5657
$entry = Entry::fromArray('', [
57-
'namingContexts' => $options->getDseNamingContexts(),
58+
'namingContexts' => $this->options->getDseNamingContexts(),
5859
'supportedExtension' => [
5960
ExtendedRequest::OID_WHOAMI,
6061
],
6162
'supportedLDAPVersion' => ['3'],
62-
'vendorName' => $options->getDseVendorName(),
63+
'vendorName' => $this->options->getDseVendorName(),
6364
]);
64-
if ($options->getSslCert()) {
65+
if ($this->options->getSslCert()) {
6566
$entry->add(
6667
'supportedExtension',
6768
ExtendedRequest::OID_START_TLS
6869
);
6970
}
70-
if ($options->getPagingHandler()) {
71+
if ($this->options->getPagingHandler()) {
7172
$entry->add(
7273
'supportedControl',
7374
Control::OID_PAGING
7475
);
7576
}
76-
if ($options->getDseVendorVersion()) {
77-
$entry->set('vendorVersion', (string) $options->getDseVendorVersion());
77+
if ($this->options->getDseVendorVersion()) {
78+
$entry->set('vendorVersion', (string) $this->options->getDseVendorVersion());
7879
}
79-
if ($options->getDseAltServer()) {
80-
$entry->set('altServer', (string) $options->getDseAltServer());
80+
if ($this->options->getDseAltServer()) {
81+
$entry->set('altServer', (string) $this->options->getDseAltServer());
8182
}
8283

8384
/** @var SearchRequest $request */

src/FreeDSx/Ldap/Protocol/ServerProtocolHandler/ServerSearchHandler.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use FreeDSx\Ldap\Server\RequestContext;
2020
use FreeDSx\Ldap\Server\RequestHandler\RequestHandlerInterface;
2121
use FreeDSx\Ldap\Server\Token\TokenInterface;
22-
use FreeDSx\Ldap\ServerOptions;
2322

2423
/**
2524
* Handles search request logic.
@@ -37,8 +36,7 @@ public function handleRequest(
3736
LdapMessageRequest $message,
3837
TokenInterface $token,
3938
RequestHandlerInterface $dispatcher,
40-
ServerQueue $queue,
41-
ServerOptions $options
39+
ServerQueue $queue
4240
): void {
4341
$context = new RequestContext(
4442
$message->controls(),

src/FreeDSx/Ldap/Protocol/ServerProtocolHandler/ServerStartTlsHandler.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ServerStartTlsHandler implements ServerProtocolHandlerInterface
3636
{
3737
private static ?bool $hasOpenssl = null;
3838

39-
public function __construct()
39+
public function __construct(private readonly ServerOptions $options)
4040
{
4141
if (self::$hasOpenssl === null) {
4242
$this::$hasOpenssl = extension_loaded('openssl');
@@ -52,11 +52,10 @@ public function handleRequest(
5252
LdapMessageRequest $message,
5353
TokenInterface $token,
5454
RequestHandlerInterface $dispatcher,
55-
ServerQueue $queue,
56-
ServerOptions $options
55+
ServerQueue $queue
5756
): void {
5857
# If we don't have a SSL cert or the OpenSSL extension is not available, then we can do nothing...
59-
if ($options->getSslCert() === null || !self::$hasOpenssl) {
58+
if ($this->options->getSslCert() === null || !self::$hasOpenssl) {
6059
$queue->sendMessage(new LdapMessageResponse($message->getMessageId(), new ExtendedResponse(
6160
new LdapResult(ResultCode::PROTOCOL_ERROR),
6261
ExtendedRequest::OID_START_TLS

src/FreeDSx/Ldap/Protocol/ServerProtocolHandler/ServerUnbindHandler.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use FreeDSx\Ldap\Protocol\Queue\ServerQueue;
1818
use FreeDSx\Ldap\Server\RequestHandler\RequestHandlerInterface;
1919
use FreeDSx\Ldap\Server\Token\TokenInterface;
20-
use FreeDSx\Ldap\ServerOptions;
2120

2221
/**
2322
* Handles an un-bind. Which just closes the connection.
@@ -33,8 +32,7 @@ public function handleRequest(
3332
LdapMessageRequest $message,
3433
TokenInterface $token,
3534
RequestHandlerInterface $dispatcher,
36-
ServerQueue $queue,
37-
ServerOptions $options
35+
ServerQueue $queue
3836
): void {
3937
$queue->close();
4038
}

src/FreeDSx/Ldap/Protocol/ServerProtocolHandler/ServerWhoAmIHandler.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use FreeDSx\Ldap\Protocol\Queue\ServerQueue;
2525
use FreeDSx\Ldap\Server\RequestHandler\RequestHandlerInterface;
2626
use FreeDSx\Ldap\Server\Token\TokenInterface;
27-
use FreeDSx\Ldap\ServerOptions;
2827

2928
/**
3029
* Handles a whoami request.
@@ -41,8 +40,7 @@ public function handleRequest(
4140
LdapMessageRequest $message,
4241
TokenInterface $token,
4342
RequestHandlerInterface $dispatcher,
44-
ServerQueue $queue,
45-
ServerOptions $options
43+
ServerQueue $queue
4644
): void {
4745
$userId = $token->getUsername();
4846

src/FreeDSx/Ldap/Server/ServerProtocolFactory.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
use FreeDSx\Ldap\Protocol\Queue\ServerQueue;
1818
use FreeDSx\Ldap\Protocol\ServerAuthorization;
1919
use FreeDSx\Ldap\Protocol\ServerProtocolHandler;
20-
use FreeDSx\Ldap\Server\RequestHandler\HandlerFactory;
2120
use FreeDSx\Socket\Socket;
2221
use Psr\Log\LoggerInterface;
2322

2423
class ServerProtocolFactory
2524
{
2625
public function __construct(
27-
private readonly HandlerFactory $handlerFactory,
28-
private readonly LoggerInterface $logger,
26+
private readonly HandlerFactoryInterface $handlerFactory,
27+
private readonly ?LoggerInterface $logger,
2928
private readonly ServerProtocolHandlerFactory $serverProtocolHandlerFactory,
3029
private readonly ServerAuthorization $serverAuthorization,
3130
) {

tests/integration/FreeDSx/Ldap/ServerTestCase.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ protected function waitForServerOutput(string $marker): string
6161
}
6262

6363
throw new Exception(sprintf(
64-
'The expected output (%s) was not received after %d seconds.',
64+
'The expected output (%s) was not received after %d seconds. Received: %s',
6565
$marker,
66-
$i
66+
$i,
67+
PHP_EOL . $this->subject->getErrorOutput()
6768
));
6869
}
6970

0 commit comments

Comments
 (0)