8000 Merge remote branch 'stof/security_login' · renegare/symfony@882a8e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 882a8e3

Browse files
committed
Merge remote branch 'stof/security_login'
* stof/security_login: Added the support of the locale in the login path and the check path
2 parents 2a5449d + f303125 commit 882a8e3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/Symfony/Component/Security/Http/EntryPoint/FormAuthenticationEntryPoint.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public function __construct(HttpKernelInterface $kernel, $loginPath, $useForward
4848
*/
4949
public function start(Request $request, AuthenticationException $authException = null)
5050
{
51+
$path = str_replace('{_locale}', $request->getSession()->getLocale(), $this->loginPath);
5152
if ($this->useForward) {
52-
return $this->httpKernel->handle(Request::create($this->loginPath), HttpKernelInterface::SUB_REQUEST);
53+
return $this->httpKernel->handle(Request::create($path), HttpKernelInterface::SUB_REQUEST);
5354
}
5455

55-
return new RedirectResponse(0 !== strpos($this->loginPath, 'http') ? $request->getUriForPath($this->loginPath) : $this->loginPath, 302);
56+
return new RedirectResponse(0 !== strpos($path, 'http') ? $request->getUriForPath($path) : $path, 302);
5657
}
5758
}

src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public final function handle(GetResponseEvent $event)
166166
*/
167167
protected function requiresAuthentication(Request $request)
168168
{
169-
return $this->options['check_path'] === $request->getPathInfo();
169+
return str_replace('{_locale}', $request->getSession()->getLocale(), $this->options['check_path']) === $request->getPathInfo();
170170
}
171171

172172
/**
@@ -196,24 +196,26 @@ private function onFailure(GetResponseEvent $event, Request $request, Authentica
196196
$this->options['failure_path'] = $this->options['login_path'];
197197
}
198198

199+
$path = str_replace('{_locale}', $request->getSession()->getLocale(), $this->options['failure_path']);
200+
199201
if ($this->options['failure_forward']) {
200202
if (null !== $this->logger) {
201-
$this->logger->debug(sprintf('Forwarding to %s', $this->options['failure_path']));
203+
$this->logger->debug(sprintf('Forwarding to %s', $path));
202204
}
203205

204-
$subRequest = Request::create($this->options['failure_path']);
206+
$subRequest = Request::create($path);
205207
$subRequest->attributes->set(SecurityContextInterface::AUTHENTICATION_ERROR, $failed);
206208

207209
return $event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
208210
}
209211

210212
if (null !== $this->logger) {
211-
$this->logger->debug(sprintf('Redirecting to %s', $this->options['failure_path']));
213+
$this->logger->debug(sprintf('Redirecting to %s', $path));
212214
}
213215

214216
$request->getSession()->set(SecurityContextInterface::AUTHENTICATION_ERROR, $failed);
215217

216-
return new RedirectResponse(0 !== strpos($this->options['failure_path'], 'http') ? $request->getUriForPath($this->options['failure_path']) : $this->options['failure_path'], 302);
218+
return new RedirectResponse(0 !== strpos($path, 'http') ? $request->getUriForPath($path) : $path, 302);
217219
}
218220

219221
private function onSuccess(GetResponseEvent $event, Request $request, TokenInterface $token)

0 commit comments

Comments
 (0)
0