summaryrefslogtreecommitdiffstats
path: root/Http/Authentication
diff options
context:
space:
mode:
Diffstat (limited to 'Http/Authentication')
-rw-r--r--Http/Authentication/AuthenticationUtils.php86
-rw-r--r--Http/Authentication/DefaultAuthenticationFailureHandler.php6
-rw-r--r--Http/Authentication/DefaultAuthenticationSuccessHandler.php2
-rw-r--r--Http/Authentication/SimpleAuthenticationHandler.php4
4 files changed, 92 insertions, 6 deletions
diff --git a/Http/Authentication/AuthenticationUtils.php b/Http/Authentication/AuthenticationUtils.php
new file mode 100644
index 0000000..03f5e44
--- /dev/null
+++ b/Http/Authentication/AuthenticationUtils.php
@@ -0,0 +1,86 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Http\Authentication;
+
+use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
+use Symfony\Component\Security\Core\SecurityContextInterface;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * Extracts Security Errors from Request
+ *
+ * @author Boris Vujicic <boris.vujicic@gmail.com>
+ */
+class AuthenticationUtils
+{
+ /**
+ * @var RequestStack
+ */
+ private $requestStack;
+
+ /**
+ * @param RequestStack $requestStack
+ */
+ public function __construct(RequestStack $requestStack)
+ {
+ $this->requestStack = $requestStack;
+ }
+
+ /**
+ * @param bool $clearSession
+ * @return null|AuthenticationException
+ */
+ public function getLastAuthenticationError($clearSession = true)
+ {
+ $request = $this->getRequest();
+ $session = $request->getSession();
+ $authenticationException = null;
+
+ if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
+ $authenticationException = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR);
+ } elseif ($session !== null && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
+ $authenticationException = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
+
+ if ($clearSession) {
+ $session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
+ }
+ }
+
+ return $authenticationException;
+ }
+
+ /**
+ * @return string
+ */
+ public function getLastUsername()
+ {
+ $session = $this->getRequest()->getSession();
+
+ return null === $session ? '' : $session->get(SecurityContextInterface::LAST_USERNAME);
+ }
+
+ /**
+ * @return Request
+ * @throws \LogicException
+ */
+ private function getRequest()
+ {
+ $request = $this->requestStack->getCurrentRequest();
+
+ if (null === $request) {
+ throw new \LogicException('Request should exist so it can be processed for error.');
+ }
+
+ return $request;
+ }
+}
diff --git a/Http/Authentication/DefaultAuthenticationFailureHandler.php b/Http/Authentication/DefaultAuthenticationFailureHandler.php
index 70dcd1e..db96e67 100644
--- a/Http/Authentication/DefaultAuthenticationFailureHandler.php
+++ b/Http/Authentication/DefaultAuthenticationFailureHandler.php
@@ -53,17 +53,17 @@ class DefaultAuthenticationFailureHandler implements AuthenticationFailureHandle
'failure_path' => null,
'failure_forward' => false,
'login_path' => '/login',
- 'failure_path_parameter' => '_failure_path'
+ 'failure_path_parameter' => '_failure_path',
), $options);
}
/**
- * {@inheritDoc}
+ * {@inheritdoc}
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
if ($failureUrl = $request->get($this->options['failure_path_parameter'], null, true)) {
- $this->options['failure_path'] = $failureUrl;
+ $this->options['failure_path'] = $failureUrl;
}
if (null === $this->options['failure_path']) {
diff --git a/Http/Authentication/DefaultAuthenticationSuccessHandler.php b/Http/Authentication/DefaultAuthenticationSuccessHandler.php
index 0c084b9..54d6fc1 100644
--- a/Http/Authentication/DefaultAuthenticationSuccessHandler.php
+++ b/Http/Authentication/DefaultAuthenticationSuccessHandler.php
@@ -48,7 +48,7 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
}
/**
- * {@inheritDoc}
+ * {@inheritdoc}
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
diff --git a/Http/Authentication/SimpleAuthenticationHandler.php b/Http/Authentication/SimpleAuthenticationHandler.php
index 2280d8f..09a55ef 100644
--- a/Http/Authentication/SimpleAuthenticationHandler.php
+++ b/Http/Authentication/SimpleAuthenticationHandler.php
@@ -51,7 +51,7 @@ class SimpleAuthenticationHandler implements AuthenticationFailureHandlerInterfa
}
/**
- * {@inheritDoc}
+ * {@inheritdoc}
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
@@ -78,7 +78,7 @@ class SimpleAuthenticationHandler implements AuthenticationFailureHandlerInterfa
}
/**
- * {@inheritDoc}
+ * {@inheritdoc}
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{