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\Asn1\Exception\EncoderException; 15use FreeDSx\Ldap\Exception\OperationException; 16use FreeDSx\Ldap\Exception\RuntimeException; 17use FreeDSx\Ldap\Operation\Request\AnonBindRequest; 18use FreeDSx\Ldap\Protocol\LdapMessageRequest; 19use FreeDSx\Ldap\Protocol\Queue\ServerQueue; 20use FreeDSx\Ldap\Server\RequestHandler\RequestHandlerInterface; 21use FreeDSx\Ldap\Server\Token\AnonToken; 22use FreeDSx\Ldap\Server\Token\TokenInterface; 23 24/** 25 * Handles anonymous bind requests. 26 * 27 * @author Chad Sikorra <Chad.Sikorra@gmail.com> 28 */ 29class ServerAnonBindHandler extends ServerBindHandler 30{ 31 /** 32 * @param LdapMessageRequest $message 33 * @param RequestHandlerInterface $dispatcher 34 * @param ServerQueue $queue 35 * @param array $options 36 * @return AnonToken 37 * @throws EncoderException 38 * @throws OperationException 39 * @throws RuntimeException 40 */ 41 public function handleBind(LdapMessageRequest $message, RequestHandlerInterface $dispatcher, ServerQueue $queue, array $options): TokenInterface 42 { 43 $request = $message->getRequest(); 44 if (!$request instanceof AnonBindRequest) { 45 throw new RuntimeException(sprintf( 46 'Expected an AnonBindRequest, got: %s', 47 get_class($request) 48 )); 49 } 50 51 $this->validateVersion($request); 52 $queue->sendMessage($this->responseFactory->getStandardResponse($message)); 53 54 return new AnonToken( 55 $request->getUsername(), 56 $request->getVersion() 57 ); 58 } 59} 60