Skip to content

Commit b47dbb3

Browse files
committed
Merge branch '5.3' into 5.4
* 5.3: [SecurityBundle] Fixed LogicException message of FirewallAwareTrait [LDAP] Fix resource type checks & docblocks on PHP 8.1 Fix Redis replication on Redis <5 Fix decorating non-entrypoint authenticators [Ldap] Make LdapAuthenticator an EntryPoint
2 parents 92d3efe + df17b04 commit b47dbb3

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

Adapter/ExtLdap/Connection.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Ldap\Adapter\ExtLdap;
1313

14+
use LDAP\Connection as LDAPConnection;
1415
use Symfony\Component\Ldap\Adapter\AbstractConnection;
1516
use Symfony\Component\Ldap\Exception\AlreadyExistsException;
1617
use Symfony\Component\Ldap\Exception\ConnectionException;
@@ -32,7 +33,7 @@ class Connection extends AbstractConnection
3233
/** @var bool */
3334
private $bound = false;
3435

35-
/** @var resource */
36+
/** @var resource|LDAPConnection */
3637
private $connection;
3738

3839
/**
@@ -89,9 +90,7 @@ public function bind(string $dn = null, string $password = null)
8990
}
9091

9192
/**
92-
* Returns a link resource.
93-
*
94-
* @return resource
93+
* @return resource|LDAPConnection
9594
*
9695
* @internal
9796
*/
@@ -165,7 +164,7 @@ private function connect()
165164

166165
private function disconnect()
167166
{
168-
if ($this->connection && \is_resource($this->connection)) {
167+
if ($this->connection) {
169168
ldap_unbind($this->connection);
170169
}
171170

Adapter/ExtLdap/Query.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Ldap\Adapter\ExtLdap;
1313

14+
use LDAP\Connection as LDAPConnection;
15+
use LDAP\Result;
1416
use Symfony\Component\Ldap\Adapter\AbstractQuery;
1517
use Symfony\Component\Ldap\Exception\LdapException;
1618
use Symfony\Component\Ldap\Exception\NotBoundException;
@@ -24,7 +26,10 @@ class Query extends AbstractQuery
2426
// As of PHP 7.2, we can use LDAP_CONTROL_PAGEDRESULTS instead of this
2527
public const PAGINATION_OID = '1.2.840.113556.1.4.319';
2628

27-
/** @var resource[] */
29+
/** @var Connection */
30+
protected $connection;
31+
32+
/** @var resource[]|Result[] */
2833
private $results;
2934

3035
/** @var array */
@@ -153,7 +158,7 @@ public function execute()
153158
* Returns an LDAP search resource. If this query resulted in multiple searches, only the first
154159
* page will be returned.
155160
*
156-
* @return resource|null
161+
* @return resource|Result|null
157162
*
158163
* @internal
159164
*/
@@ -165,7 +170,7 @@ public function getResource(int $idx = 0)
165170
/**
166171
* Returns all LDAP search resources.
167172
*
168-
* @return resource[]
173+
* @return resource[]|Result[]
169174
*
170175
* @internal
171176
*/
@@ -208,7 +213,7 @@ private function resetPagination()
208213
/**
209214
* Sets LDAP pagination controls.
210215
*
211-
* @param resource $con
216+
* @param resource|LDAPConnection $con
212217
*/
213218
private function controlPagedResult($con, int $pageSize, bool $critical, string $cookie): bool
214219
{
@@ -232,8 +237,8 @@ private function controlPagedResult($con, int $pageSize, bool $critical, string
232237
/**
233238
* Retrieve LDAP pagination cookie.
234239
*
235-
* @param resource $con
236-
* @param resource $result
240+
* @param resource|LDAPConnection $con
241+
* @param resource|Result $result
237242
*/
238243
private function controlPagedResultResponse($con, $result, string $cookie = ''): string
239244
{
@@ -250,9 +255,9 @@ private function controlPagedResultResponse($con, $result, string $cookie = ''):
250255
/**
251256
* Calls actual LDAP search function with the prepared options and parameters.
252257
*
253-
* @param resource $con
258+
* @param resource|LDAPConnection $con
254259
*
255-
* @return resource|false
260+
* @return resource|Result|false
256261
*/
257262
private function callSearchFunction($con, callable $func, int $sizeLimit)
258263
{

Security/LdapAuthenticator.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1818
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
1919
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
20+
use Symfony\Component\Security\Http\Authenticator\InteractiveAuthenticatorInterface;
2021
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
22+
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
23+
use Symfony\Component\Security\Http\EntryPoint\Exception\NotAnEntryPointException;
2124

2225
/**
2326
* This class decorates internal authenticators to add the LDAP integration.
@@ -30,7 +33,7 @@
3033
*
3134
* @final
3235
*/
33-
class LdapAuthenticator implements AuthenticatorInterface
36+
class LdapAuthenticator implements AuthenticationEntryPointInterface, InteractiveAuthenticatorInterface
3437
{
3538
private $authenticator;
3639
private $ldapServiceId;
@@ -90,4 +93,22 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
9093
{
9194
return $this->authenticator->onAuthenticationFailure($request, $exception);
9295
}
96+
97+
public function start(Request $request, AuthenticationException $authException = null): Response
98+
{
99+
if (!$this->authenticator instanceof AuthenticationEntryPointInterface) {
100+
throw new NotAnEntryPointException(sprintf('Decorated authenticator "%s" does not implement interface "%s".', get_debug_type($this->authenticator), AuthenticationEntryPointInterface::class));
101+
}
102+
103+
return $this->authenticator->start($request, $authException);
104+
}
105+
106+
public function isInteractive(): bool
107+
{
108+
if ($this->authenticator instanceof InteractiveAuthenticatorInterface) {
109+
return $this->authenticator->isInteractive();
110+
}
111+
112+
return false;
113+
}
93114
}

0 commit comments

Comments
 (0)