Skip to content

Commit d499ecd

Browse files
committed
bug #42354 [Ldap][Security] Make LdapAuthenticator an EntryPoint (dcp-dev, chalasr)
This PR was merged into the 5.3 branch. Discussion ---------- [Ldap][Security] Make LdapAuthenticator an EntryPoint | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #42346 | License | MIT | Doc PR | N/A I added `@chalasr`'s recommandations given in symfony/symfony#42346 (comment) Commits ------- 4daad9e784 Fix decorating non-entrypoint authenticators 0b0c15c019 [Ldap] Make LdapAuthenticator an EntryPoint
2 parents e75cbf1 + b260686 commit d499ecd

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Http\EntryPoint\Exception;
13+
14+
/**
15+
* Thrown by generic decorators when a decorated authenticator does not implement
16+
* {@see AuthenticationEntryPointInterface}.
17+
*
18+
* @author Robin Chalas <[email protected]>
19+
*/
20+
class NotAnEntryPointException extends \RuntimeException
21+
{
22+
}

Firewall/ExceptionListener.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Symfony\Component\Security\Core\Security;
3232
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
3333
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
34+
use Symfony\Component\Security\Http\EntryPoint\Exception\NotAnEntryPointException;
3435
use Symfony\Component\Security\Http\HttpUtils;
3536
use Symfony\Component\Security\Http\Util\TargetPathTrait;
3637

@@ -195,11 +196,7 @@ private function handleLogoutException(ExceptionEvent $event, LogoutException $e
195196
private function startAuthentication(Request $request, AuthenticationException $authException): Response
196197
{
197198
if (null === $this->authenticationEntryPoint) {
198-
if (null !== $this->logger) {
199-
$this->logger->notice(sprintf('No Authentication entry point configured, returning a %s HTTP response. Configure "entry_point" on the firewall "%s" if you want to modify the response.', Response::HTTP_UNAUTHORIZED, $this->firewallName));
200-
}
201-
202-
throw new HttpException(Response::HTTP_UNAUTHORIZED, $authException->getMessage(), $authException, [], $authException->getCode());
199+
$this->throwUnauthorizedException($authException);
203200
}
204201

205202
if (null !== $this->logger) {
@@ -219,7 +216,11 @@ private function startAuthentication(Request $request, AuthenticationException $
219216
}
220217
}
221218

222-
$response = $this->authenticationEntryPoint->start($request, $authException);
219+
try {
220+
$response = $this->authenticationEntryPoint->start($request, $authException);
221+
} catch (NotAnEntryPointException $e) {
222+
$this->throwUnauthorizedException($authException);
223+
}
223224

224225
if (!$response instanceof Response) {
225226
$given = get_debug_type($response);
@@ -237,4 +238,13 @@ protected function setTargetPath(Request $request)
237238
$this->saveTargetPath($request->getSession(), $this->firewallName, $request->getUri());
238239
}
239240
}
241+
242+
private function throwUnauthorizedException(AuthenticationException $authException)
243+
{
244+
if (null !== $this->logger) {
245+
$this->logger->notice(sprintf('No Authentication entry point configured, returning a %s HTTP response. Configure "entry_point" on the firewall "%s" if you want to modify the response.', Response::HTTP_UNAUTHORIZED, $this->firewallName));
246+
}
247+
248+
throw new HttpException(Response::HTTP_UNAUTHORIZED, $authException->getMessage(), $authException, [], $authException->getCode());
249+
}
240250
}

0 commit comments

Comments
 (0)