-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from ChadSikorra/v1-interface_refactor
[1.0.0] Refactor how server binds are handled / adjust interfaces.
- Loading branch information
Showing
14 changed files
with
264 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the FreeDSx LDAP package. | ||
* | ||
* (c) Chad Sikorra <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FreeDSx\Ldap\Protocol; | ||
|
||
use FreeDSx\Ldap\Exception\OperationException; | ||
use FreeDSx\Ldap\Operation\ResultCode; | ||
use FreeDSx\Ldap\Protocol\Bind\BindInterface; | ||
use FreeDSx\Ldap\Server\Token\TokenInterface; | ||
|
||
class Authenticator | ||
{ | ||
/** | ||
* @param BindInterface[] $authenticators | ||
*/ | ||
public function __construct(private readonly array $authenticators = []) | ||
{ | ||
} | ||
|
||
public function bind(LdapMessageRequest $request): TokenInterface | ||
{ | ||
foreach ($this->authenticators as $authenticator) { | ||
if ($authenticator->supports($request)) { | ||
return $authenticator->bind($request); | ||
} | ||
} | ||
|
||
throw new OperationException( | ||
'The authentication type requested is not supported.', | ||
ResultCode::AUTH_METHOD_UNSUPPORTED | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,8 @@ | |
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FreeDSx\Ldap\Protocol\ServerProtocolHandler; | ||
namespace FreeDSx\Ldap\Protocol\Bind; | ||
|
||
use FreeDSx\Asn1\Exception\EncoderException; | ||
use FreeDSx\Ldap\Exception\OperationException; | ||
use FreeDSx\Ldap\Exception\RuntimeException; | ||
use FreeDSx\Ldap\Operation\Request\AnonBindRequest; | ||
use FreeDSx\Ldap\Protocol\Factory\ResponseFactory; | ||
|
@@ -28,9 +26,9 @@ | |
* | ||
* @author Chad Sikorra <[email protected]> | ||
*/ | ||
class ServerAnonBindHandler implements BindHandlerInterface | ||
class AnonymousBind implements BindInterface | ||
{ | ||
use BindVersionValidatorTrait; | ||
use VersionValidatorTrait; | ||
|
||
public function __construct( | ||
private readonly ServerQueue $queue, | ||
|
@@ -40,11 +38,8 @@ public function __construct( | |
|
||
/** | ||
* {@inheritDoc} | ||
* @throws EncoderException | ||
* @throws OperationException | ||
* @throws RuntimeException | ||
*/ | ||
public function handleBind(LdapMessageRequest $message): TokenInterface | ||
public function bind(LdapMessageRequest $message): TokenInterface | ||
{ | ||
$request = $message->getRequest(); | ||
if (!$request instanceof AnonBindRequest) { | ||
|
@@ -62,4 +57,12 @@ public function handleBind(LdapMessageRequest $message): TokenInterface | |
$request->getVersion(), | ||
); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function supports(LdapMessageRequest $request): bool | ||
{ | ||
return $request->getRequest() instanceof AnonBindRequest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FreeDSx\Ldap\Protocol\ServerProtocolHandler; | ||
namespace FreeDSx\Ldap\Protocol\Bind; | ||
|
||
use FreeDSx\Ldap\Exception\OperationException; | ||
use FreeDSx\Ldap\Protocol\LdapMessageRequest; | ||
|
@@ -22,12 +22,17 @@ | |
* | ||
* @author Chad Sikorra <[email protected]> | ||
*/ | ||
interface BindHandlerInterface | ||
interface BindInterface | ||
{ | ||
/** | ||
* Returns a token indicating the outcome of a bind request. | ||
* | ||
* @throws OperationException | ||
*/ | ||
public function handleBind(LdapMessageRequest $message): TokenInterface; | ||
public function bind(LdapMessageRequest $message): TokenInterface; | ||
|
||
/** | ||
* Whether the specific bind request is supported. | ||
*/ | ||
public function supports(LdapMessageRequest $request): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FreeDSx\Ldap\Protocol\ServerProtocolHandler; | ||
namespace FreeDSx\Ldap\Protocol\Bind; | ||
|
||
use FreeDSx\Ldap\Exception\OperationException; | ||
use FreeDSx\Ldap\Exception\RuntimeException; | ||
|
@@ -30,9 +30,9 @@ | |
* | ||
* @author Chad Sikorra <[email protected]> | ||
*/ | ||
class ServerBindHandler implements BindHandlerInterface | ||
class SimpleBind implements BindInterface | ||
{ | ||
use BindVersionValidatorTrait; | ||
use VersionValidatorTrait; | ||
|
||
public function __construct( | ||
private readonly ServerQueue $queue, | ||
|
@@ -43,10 +43,8 @@ public function __construct( | |
|
||
/** | ||
* {@inheritDoc} | ||
* @throws RuntimeException | ||
* @throws OperationException | ||
*/ | ||
public function handleBind(LdapMessageRequest $message): TokenInterface | ||
public function bind(LdapMessageRequest $message): TokenInterface | ||
{ | ||
/** @var BindRequest $request */ | ||
$request = $message->getRequest(); | ||
|
@@ -81,4 +79,12 @@ private function simpleBind(SimpleBindRequest $request): TokenInterface | |
$request->getPassword() | ||
); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function supports(LdapMessageRequest $request): bool | ||
{ | ||
return $request->getRequest() instanceof SimpleBindRequest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
src/FreeDSx/Ldap/Protocol/Factory/ServerBindHandlerFactory.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.