Skip to content

Commit

Permalink
setup adapter before auth
Browse files Browse the repository at this point in the history
  • Loading branch information
raffis committed Apr 12, 2019
1 parent ac81442 commit 9c08a6a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ abstract class AbstractAdapter implements AdapterInterface
*/
protected $identity_attribute = 'uid';

/**
* Setup.
*
* @return bool
*/
public function setup(): bool
{
return true;
}

/**
* Get attribute sync cache.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@

interface AdapterInterface
{
/**
* Setup.
*
* @return bool
*/
public function setup(): bool;

/**
* Get attribute sync cache.
*
Expand Down
11 changes: 10 additions & 1 deletion src/Adapter/Basic/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public function __construct(LdapServer $ldap, LoggerInterface $logger, ?Iterable
$this->setOptions($config);
}

/**
* Setup.
*/
public function setup(): bool
{
$this->ldap->connect();

return true;
}

/**
* Set options.
*
Expand Down Expand Up @@ -98,7 +108,6 @@ public function setOptions(? Iterable $config = null): AdapterInterface
*/
public function plainAuth(string $username, string $password): bool
{
$this->ldap->connect();
$resource = $this->ldap->getResource();

$esc_username = ldap_escape($username);
Expand Down
2 changes: 2 additions & 0 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ public function requireOne(): bool
$result = false;

foreach ($this->adapter as $name => $adapter) {
$adapter->setup();

try {
if ($adapter->authenticate()) {
$this->createIdentity($adapter);
Expand Down

0 comments on commit 9c08a6a

Please sign in to comment.