1<?php
2
3/**
4 * This file is part of the FreeDSx LDAP package.
5 *
6 * (c) Chad Sikorra <Chad.Sikorra@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace FreeDSx\Ldap\Protocol\ServerProtocolHandler;
13
14use FreeDSx\Ldap\Exception\OperationException;
15use FreeDSx\Ldap\Operation\ResultCode;
16use FreeDSx\Ldap\Protocol\LdapMessageRequest;
17use FreeDSx\Ldap\Protocol\Queue\ServerQueue;
18use FreeDSx\Ldap\Server\RequestContext;
19use FreeDSx\Ldap\Server\RequestHandler\RequestHandlerInterface;
20use FreeDSx\Ldap\Server\Token\TokenInterface;
21
22/**
23 * Determines whether we can page results if no paging handler is defined.
24 *
25 * @author Chad Sikorra <Chad.Sikorra@gmail.com>
26 */
27class ServerPagingUnsupportedHandler implements ServerProtocolHandlerInterface
28{
29    use ServerSearchTrait;
30
31    /**
32     * @inheritDoc
33     */
34    public function handleRequest(
35        LdapMessageRequest $message,
36        TokenInterface $token,
37        RequestHandlerInterface $dispatcher,
38        ServerQueue $queue,
39        array $options
40    ): void {
41        $context = new RequestContext(
42            $message->controls(),
43            $token
44        );
45        $request = $this->getSearchRequestFromMessage($message);
46        $pagingControl = $this->getPagingControlFromMessage($message);
47
48        /**
49         * RFC 2696, Section 3:
50         *
51         * If the server does not support this control, the server
52         * MUST return an error of unsupportedCriticalExtension if the client
53         * requested it as critical, otherwise the server SHOULD ignore the
54         * control.
55         */
56        if ($pagingControl->getCriticality()) {
57            throw new OperationException(
58                'The server does not support the paging control.',
59                ResultCode::UNAVAILABLE_CRITICAL_EXTENSION
60            );
61        }
62
63        $entries = $dispatcher->search(
64            $context,
65            $request
66        );
67
68        $this->sendEntriesToClient(
69            $entries,
70            $message,
71            $queue
72        );
73    }
74}
75