Skip to content

Commit 7baeb59

Browse files
wouterjfabpot
authored andcommitted
[Security] Automatically register custom authenticator as entry_point (if supported)
1 parent c06672a commit 7baeb59

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Authenticator/FormLoginAuthenticator.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
17+
use Symfony\Component\HttpKernel\HttpKernelInterface;
1718
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1819
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
1920
use Symfony\Component\Security\Core\Exception\AuthenticationException;
@@ -49,6 +50,7 @@ class FormLoginAuthenticator extends AbstractLoginFormAuthenticator
4950
private $successHandler;
5051
private $failureHandler;
5152
private $options;
53+
private $httpKernel;
5254

5355
public function __construct(HttpUtils $httpUtils, UserProviderInterface $userProvider, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options)
5456
{
@@ -146,4 +148,24 @@ private function getCredentials(Request $request): array
146148

147149
return $credentials;
148150
}
151+
152+
public function setHttpKernel(HttpKernelInterface $httpKernel): void
153+
{
154+
$this->httpKernel = $httpKernel;
155+
}
156+
157+
public function start(Request $request, AuthenticationException $authException = null): Response
158+
{
159+
if (!$this->options['use_forward']) {
160+
return parent::start($request, $authException);
161+
}
162+
163+
$subRequest = $this->httpUtils->createRequest($request, $this->options['login_path']);
164+
$response = $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
165+
if (200 === $response->getStatusCode()) {
166+
$response->setStatusCode(401);
167+
}
168+
169+
return $response;
170+
}
149171
}

0 commit comments

Comments
 (0)