summaryrefslogtreecommitdiffstats
path: root/Core/User/UserChecker.php
diff options
context:
space:
mode:
Diffstat (limited to 'Core/User/UserChecker.php')
-rw-r--r--Core/User/UserChecker.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/Core/User/UserChecker.php b/Core/User/UserChecker.php
new file mode 100644
index 0000000..93897a1
--- /dev/null
+++ b/Core/User/UserChecker.php
@@ -0,0 +1,61 @@
+<?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\Core\User;
+
+use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
+use Symfony\Component\Security\Core\Exception\LockedException;
+use Symfony\Component\Security\Core\Exception\DisabledException;
+use Symfony\Component\Security\Core\Exception\AccountExpiredException;
+
+/**
+ * UserChecker checks the user account flags.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class UserChecker implements UserCheckerInterface
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function checkPreAuth(UserInterface $user)
+ {
+ if (!$user instanceof AdvancedUserInterface) {
+ return;
+ }
+
+ if (!$user->isCredentialsNonExpired()) {
+ throw new CredentialsExpiredException('User credentials have expired.', $user);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function checkPostAuth(UserInterface $user)
+ {
+ if (!$user instanceof AdvancedUserInterface) {
+ return;
+ }
+
+ if (!$user->isAccountNonLocked()) {
+ throw new LockedException('User account is locked.', $user);
+ }
+
+ if (!$user->isEnabled()) {
+ throw new DisabledException('User account is disabled.', $user);
+ }
+
+ if (!$user->isAccountNonExpired()) {
+ throw new AccountExpiredException('User account has expired.', $user);
+ }
+ }
+}