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\Server\RequestHandler; 13 14use FreeDSx\Ldap\Entry\Entry; 15use FreeDSx\Ldap\Exception\OperationException; 16use FreeDSx\Ldap\LdapClient; 17use FreeDSx\Ldap\Operation\Request\SearchRequest; 18use FreeDSx\Ldap\Operation\ResultCode; 19use FreeDSx\Ldap\Server\RequestContext; 20 21/** 22 * Proxies requests to an LDAP server, including the RootDSE. 23 * 24 * @author Chad Sikorra <Chad.Sikorra@gmail.com> 25 */ 26class ProxyHandler extends ProxyRequestHandler implements RootDseHandlerInterface 27{ 28 public function __construct(LdapClient $client) 29 { 30 $this->ldap = $client; 31 } 32 33 /** 34 * @inheritDoc 35 */ 36 public function rootDse( 37 RequestContext $context, 38 SearchRequest $request, 39 Entry $rootDse 40 ): Entry { 41 $rootDse = $this->ldap() 42 ->search( 43 $request, 44 ...$context->controls()->toArray() 45 ) 46 ->first(); 47 48 // This technically could happen...but should not. 49 if (!$rootDse) { 50 throw new OperationException( 51 'Entry not found.', 52 ResultCode::NO_SUCH_OBJECT 53 ); 54 } 55 56 return $rootDse; 57 } 58} 59